home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 242_01 / a611.h < prev    next >
Text File  |  1989-01-13  |  11KB  |  383 lines

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