home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 276_01 / a16.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-03  |  10.6 KB  |  378 lines

  1. /*
  2.     HEADER:        CUG276;
  3.     TITLE:        PIC1650 Cross-Assembler (Portable);
  4.     FILENAME:    A16.H;
  5.     VERSION:    0.0;
  6.     DATE:        06/15/1989;
  7.  
  8.     DESCRIPTION:    "This program lets you use your computer to assemble
  9.             code for the General Instruments PIC1650 family micro-
  10.             processors.  The program is written in portable C
  11.             rather than BDS C.  All assembler features are
  12.             supported except relocation, linkage, and macros.";
  13.  
  14.     KEYWORDS:    Software Development, Assemblers, Cross-Assemblers,
  15.             General Instruments, PIC1650;
  16.  
  17.     SYSTEM:        CP/M-80, CP/M-86, HP-UX, MSDOS, PCDOS, QNIX;
  18.     COMPILERS:    Aztec C86, Aztec CII, CI-C86, Eco-C, Eco-C88, HP-UX,
  19.             Lattice C, Microsoft C,    QNIX C;
  20.  
  21.     WARNINGS:    "This program has compiled successfully on 2 UNIX
  22.             compilers, 5 MSDOS compilers, and 2 CP/M compilers.
  23.             A port to BDS C would be extremely difficult.  A port
  24.             to Toolworks C is untried."
  25.  
  26.     AUTHORS:    William C. Colley III;
  27. */
  28.  
  29. /*
  30.              PIC1650 Cross-Assembler in Portable C
  31.  
  32.           Copyright (c) 1985,1987,1989 William C. Colley, III
  33.  
  34. Revision History:
  35.  
  36. Ver    Date        Description
  37.  
  38. 0.0    JUNE 1989    Derived from version 0.2 of my portable 8085 cross-
  39.             assembler.  WCC3.
  40.  
  41. This header file contains the global constants and data type definitions for
  42. all modules of the cross-assembler.  This also seems a good place to put the
  43. compilation and linkage instructions for the animal.  This list currently
  44. includes the following compilers:
  45.  
  46.         Compiler Name        Op. Sys.    Processor
  47.  
  48.     1)  Aztec C86            CP/M-86        8086, 8088
  49.                     MSDOS/PCDOS
  50.  
  51.     2)  AZTEC C II            CP/M-80        8080, Z-80
  52.  
  53.     3)  Computer Innovations C86    MSDOS/PCDOS    8086, 8088
  54.  
  55.     4)  Eco-C            CP/M-80        Z-80
  56.  
  57.     5)  Eco-C88            MSDOS/PCDOS    8086, 8088
  58.  
  59.     6)  HP C            HP-UX        68000
  60.  
  61.     7)  Lattice C            MSDOS/PCDOS    8086, 8088
  62.  
  63.     8)  Microsoft C            MSDOS/PCDOS    8086, 8088
  64.  
  65.     9)  QNIX C            QNIX        8086, 8088
  66.  
  67. Further additions will be made to the list as users feed the information to
  68. me.  This particularly applies to UNIX and IBM-PC compilers.
  69.  
  70. Compile-assemble-link instructions for this program under various compilers
  71. and operating systems:
  72.  
  73.     1)    Aztec C86:
  74.  
  75.     A)  Uncomment out the "#define AZTEC_C 1" line and comment out all
  76.         other compiler names in A16.H.
  77.  
  78.     B)  Assuming that all files are on drive A:, run the following sequence
  79.         of command lines:
  80.  
  81.         A>cc a16
  82.         A>cc a16eval
  83.         A>cc a16util
  84.         A>ln a16.o a16eval.o a16util.o -lc
  85.         A>era a16*.o
  86.  
  87.     2)  Aztec CII (version 1.06B):
  88.  
  89.     A)  Uncomment out the "#define AZTEC_C 1" line and comment out all
  90.         other compiler names in A16.H.
  91.  
  92.     B)  Assuming the C compiler is called "CC.COM" and all files are
  93.         on drive A:, run the following sequence of command lines:
  94.  
  95.         A>cc a16
  96.         A>as -zap a16
  97.         A>cc a16eval
  98.         A>as -zap a16eval
  99.         A>cc a16util
  100.         A>as -zap a16util
  101.         A>ln a16.o a16eval.o a16util.o -lc
  102.         A>era a16*.o
  103.  
  104.     3)  Computer Innovations C86:
  105.  
  106.     A)  Uncomment out the "#define CI_C86 1" line and comment out all
  107.         other compiler names in A16.H.
  108.  
  109.     B)  Compile the files A16.C, A16EVAL.C, and A16UTIL.C.  Link
  110.         according to instructions that come with the compiler.
  111.  
  112.     4)  Eco-C (CP/M-80 version 3.10):
  113.  
  114.     A)  Uncomment out the "#define ECO_C 1" line and comment out all
  115.         other compiler names in A16.H.
  116.  
  117.     B)  Assuming all files are on drive A:, run the following sequence of
  118.         command lines:
  119.  
  120.         A>cp a16 -i -m
  121.         A>cp a16eval -i -m
  122.         A>cp a16util -i -m
  123.         A>l80 a16,a16eval,a16util,a16/n/e
  124.         A>era a16*.mac
  125.         A>era a16*.rel
  126.  
  127.     5)  Eco-C88:
  128.  
  129.     A)  Uncomment out the "#define ECO_C 1" line and comment out all
  130.         other compiler names in A16.H.
  131.  
  132.     B)  Compile the files A16.C, A16EVAL.C, and A16UTIL.C.  Link
  133.         according to instructions that come with the compiler.
  134.  
  135.     6)  HP-UX (a UNIX look-alike running on an HP-9000 Series 200/500,
  136.     68000-based machine):
  137.  
  138.     A)  Uncomment out the "#define HP_UX 1" line and comment out all
  139.         other compiler names in A16.H.
  140.  
  141.     B)  Run the following command line:
  142.  
  143.         . cc a16.c a16eval.c a16util.c
  144.  
  145.     7)  Lattice C:
  146.  
  147.     A)  Uncomment out the "#define LATTICE_C 1" line and comment out all
  148.         other compiler names in A16.H.
  149.  
  150.     B)  Compile the files A16.C, A16EVAL.C, and A16UTIL.C.  Link
  151.         according to instructions that come with the compiler.
  152.  
  153.     8)  Microsoft C (version 3.00):
  154.  
  155.     A)  Uncomment out the "#define MICROSOFT_C 1" line and comment out
  156.         all other compiler names in A16.H.
  157.  
  158.     B)  Run the following command line:
  159.  
  160.         C>cl a16.c a16eval.c a16util.c
  161.  
  162.     9)    QNIX C:
  163.  
  164.     A)  Uncomment out the "#define QNIX 1" line and comment out all other
  165.         compiler names in A16.H.
  166.  
  167.     B)  Run the following command line:
  168.  
  169.         . cc a16.c a16eval.c a16util.c
  170.  
  171. Note that, under CP/M-80, you can't re-execute a core image from a previous
  172. assembly run with the "@.COM" trick.  This technique is incompatible with the
  173. Aztec CII compiler, so I didn't bother to support it at all.
  174. */
  175.  
  176. #include <stdio.h>
  177.  
  178. /*  Comment out all but the line containing the name of your compiler:    */
  179.  
  180. /* #define    AZTEC_C                            */
  181. /* #define    CI_C86                            */
  182. /* #define    ECO_C                            */
  183. /* #define    HP_UX                            */
  184. /* #define    LATTICE_C                        */
  185. #define        MICROSOFT_C
  186. /* #define    QNIX                            */
  187.  
  188. /*  Compiler dependencies:                        */
  189.  
  190. #ifdef    AZTEC_C
  191. #define    getc(f)        agetc(f)
  192. #define    putc(c,f)    aputc(c,f)
  193. #endif
  194.  
  195. #ifndef    ECO_C
  196. #define    FALSE        0
  197. #define    TRUE        (!0)
  198. #endif
  199.  
  200. #ifdef    LATTICE_C
  201. #define    void        int
  202. #endif
  203.  
  204. #ifdef    QNIX
  205. #define    fprintf        tfprintf
  206. #define    printf        tprintf
  207. #endif
  208.  
  209. /*  On 8-bit machines, the static type is as efficient as the register    */
  210. /*  type and far more efficient than the auto type.  On larger machines    */
  211. /*  such as the 8086 family, this is not necessarily the case.  To    */
  212. /*  let you experiment to see what generates the fastest, smallest code    */
  213. /*  for your machine, I have declared internal scratch variables in    */
  214. /*  functions "SCRATCH int", "SCRATCH unsigned", etc.  A SCRATCH    */
  215. /*  varible is made static below, but you might want to try register    */
  216. /*  instead.                                */
  217.  
  218. #define    SCRATCH        static
  219.  
  220. /*  A slow, but portable way of cracking an unsigned into its various    */
  221. /*  component parts:                            */
  222.  
  223. #define    clamp(u)    ((u) &= 0xffff)
  224. #define    high(u)        (((u) >> 8) & 0xff)
  225. #define    low(u)        ((u) & 0xff)
  226. #define    word(u)        ((u) & 0xffff)
  227.  
  228. /*  The longest source line the assembler can hold without exploding:    */
  229.  
  230. #define    MAXLINE        255
  231.  
  232. /*  The maximum number of source files that can be open simultaneously:    */
  233.  
  234. #define    FILES        4
  235.  
  236. /*  The fatal error messages generated by the assembler:        */
  237.  
  238. #define    ASMOPEN        "Source File Did Not Open"
  239. #define    ASMREAD        "Error Reading Source File"
  240. #define    DSKFULL        "Disk or Directory Full"
  241. #define    FLOFLOW        "File Stack Overflow"
  242. #define    HEXOPEN        "Object File Did Not Open"
  243. #define    IFOFLOW        "If Stack Overflow"
  244. #define    LSTOPEN        "Listing File Did Not Open"
  245. #define    NOASM        "No Source File Specified"
  246. #define    SYMBOLS        "Too Many Symbols"
  247.  
  248. /*  The warning messages generated by the assembler:            */
  249.  
  250. #define    BADOPT        "Illegal Option Ignored"
  251. #define    NOHEX        "-o Option Ignored -- No File Name"
  252. #define    NOLST        "-l Option Ignored -- No File Name"
  253. #define    TWOASM        "Extra Source File Ignored"
  254. #define    TWOHEX        "Extra Object File Ignored"
  255. #define    TWOLST        "Extra Listing File Ignored"
  256.  
  257. /*  Line assembler (A16.C) constants:                    */
  258.  
  259. #define    BIGINST        2        /*  longest instruction length    */
  260. #define    IFDEPTH        16        /*  maximum IF nesting level    */
  261. #define    NOP        0x000        /*  processor's NOP opcode    */
  262. #define    ON        1        /*  assembly turned on        */
  263. #define    OFF        -1        /*  assembly turned off        */
  264.  
  265. /*  Line assembler (A16.C) opcode attribute word flag masks:        */
  266.  
  267. #define    PSEUDO        0x100    /*  is pseudo op            */
  268. #define    ISIF        0x080    /*  is IF, ELSE, or ENDI        */
  269. #define    ARG2        0x060    /*  second argument descriptor        */
  270. #define    ARG1        0x01c    /*  first argument descriptor        */
  271. #define    NONE        0x000    /*    no argument            */
  272. #define    ADDR_9        0x004    /*    9-bit address            */
  273. #define    ADDR_8        0x008    /*    8-bit address            */
  274. #define    IMMED_8        0x00c    /*    8-bit immediate value        */
  275. #define    REG_5        0x010    /*    5-bit register number        */
  276. #define    TRIS_REG    0x014    /*    register number 5, 6, or 7    */
  277. #define    BIT_3        0x020    /*    3-bit bit number        */
  278. #define    DIR        0x040    /*    1-bit direction indicator    */
  279. #define    BYTES        0x003    /*  number of bytes in instruction    */
  280.  
  281. /*  Line assembler (A16.C) pseudo-op opcode token values:        */
  282.  
  283. #define    DS        0
  284. #define    DW        1
  285. #define    ELSE        2
  286. #define    END        3
  287. #define    ENDIF        4
  288. #define    EQU        5
  289. #define    IF        6
  290. #define    INCL        7
  291. #define    ORG        8
  292. #define    PAGE        9
  293. #define    SET        10
  294. #define    TITLE        11
  295.  
  296. /*  Lexical analyzer (A16EVAL.C) token buffer and stream pointer:    */
  297.  
  298. typedef struct {
  299.     unsigned attr;
  300.     unsigned valu;
  301.     char sval[MAXLINE + 1];
  302. } TOKEN;
  303.  
  304. /*  Lexical analyzer (A16EVAL.C) token attribute values:        */
  305.  
  306. #define    EOL        0    /*  end of line                */
  307. #define    SEP        1    /*  field separator            */
  308. #define    OPR        2    /*  operator                */
  309. #define    STR        3    /*  character string            */
  310. #define    VAL        4    /*  value                */
  311.  
  312. /*  Lexical analyzer (A16EVAL.C) token attribute word flag masks:    */
  313.  
  314. #define    BINARY        0x8000    /*  Operator:    is binary operator    */
  315. #define    UNARY        0x4000    /*        is unary operator    */
  316. #define    PREC        0x0f00    /*        precedence        */
  317.  
  318. #define    FORWD        0x8000    /*  Value:    is forward referenced    */
  319. #define    SOFT        0x4000    /*        is redefinable        */
  320.  
  321. #define    TYPE        0x000f    /*  All:    token type        */
  322.  
  323. /*  Lexical analyzer (A16EVAL.C) operator token values (unlisted ones    */
  324. /*  use ASCII characters):                        */
  325.  
  326. #define    AND        0
  327. #define    GE        1
  328. #define    HIGH        2
  329. #define    LE        3
  330. #define    LOW        4
  331. #define    MOD        5
  332. #define    NE        6
  333. #define    NOT        7
  334. #define    OR        8
  335. #define    SHR        9
  336. #define    SHL        10
  337. #define    XOR        11
  338.  
  339. /*  Lexical analyzer (A16EVAL.C) operator precedence values:        */
  340.  
  341. #define    UOP1        0x0000    /*  unary +, unary -            */
  342. #define    MULT        0x0100    /*  *, /, MOD, SHL, SHR            */
  343. #define    ADDIT        0x0200    /*  binary +, binary -            */
  344. #define    RELAT        0x0300    /*  >, >=, =, <=, <, <>            */
  345. #define    UOP2        0x0400    /*  NOT                    */
  346. #define    LOG1        0x0500    /*  AND                    */
  347. #define    LOG2        0x0600    /*  OR, XOR                */
  348. #define    UOP3        0x0700    /*  HIGH, LOW                */
  349. #define    RPREN        0x0800    /*  )                    */
  350. #define    LPREN        0x0900    /*  (                    */
  351. #define    ENDEX        0x0a00    /*  end of expression            */
  352. #define    START        0x0b00    /*  beginning of expression        */
  353.  
  354. /*  Utility package (A16UTIL.C) symbol table routines:            */
  355.  
  356. struct _symbol {
  357.     unsigned attr;
  358.     unsigned valu;
  359.     struct _symbol *left, *right;
  360.     char sname[1];
  361. };
  362.  
  363. typedef struct _symbol SYMBOL;
  364.  
  365. #define    SYMCOLS        4
  366.  
  367. /*  Utility package (A16UTIL.C) opcode/operator table routines:        */
  368.  
  369. typedef struct {
  370.     unsigned attr;
  371.     unsigned valu;
  372.     char oname[7];
  373. } OPCODE;
  374.  
  375. /*  Utility package (A16UTIL.C) hex file output routines:        */
  376.  
  377. #define    HEXSIZE        32
  378.