home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 042.lha / assembler / A68k.doc < prev    next >
Text File  |  1987-06-25  |  15KB  |  340 lines

  1.     A68k - a freely    distributable assembler    for the    Amiga
  2.  
  3.             by Charlie Gibbs
  4.  
  5.              with special thanks to
  6.         Brian R. Anderson and Jeff Lydiatt
  7.  
  8.           (Version 1.00    - June 18, 1987)
  9.  
  10. Note: This program is NOT Public Domain.  Permission is    given to freely
  11. distribute this    program    provided no fee    is charged, and    this
  12. documentation file is included with the    program.
  13.  
  14.      This assembler is based on    Brian R. Anderson's 68000 cross-assembler
  15. published in Dr. Dobb's Journal, April through June 1986.  I have converted
  16. it to produce AmigaDOS-format object modules, and have made many enhancements,
  17. such as    macros and include files.
  18.  
  19.      My    first step was to convert the original Modula-2    code into C.
  20. I did this for two reasons.  First, I had access to a C    compiler, but
  21. not a Modula-2 compiler.  Second, I like C better anyway.
  22.  
  23.      The executable code generator code    (GetObjectCode and MergeModes) is
  24. essentially the    same as    in the original    article, aside from its    translation
  25. into C.     I have    almost completely rewritten the    remainder of the code,
  26. however, in order to remove restrictions, add enhancements, and    adapt it to
  27. the AmigaDOS environment.  Since the only reference book available to me
  28. was the    AmigaDOS Developer's Manual (Bantam, February 1986), the assembler
  29. and the    remainder of this document work    in terms of that book.
  30.  
  31.  
  32. RESTRICTIONS
  33.  
  34.      Let's get these out of the way first.  There are a few things that I
  35. have not yet implemented, and some outright bugs that would take too long
  36. to correct for this version.
  37.  
  38.       o    The verification file (-v) option is not supported.  Diagnostic
  39.     messages always    appear on the console.    They also appear in the
  40.     listing    file, however (see extensions below).
  41.  
  42.       o    The header file    (-h) option is not supported.
  43.  
  44.       o    The equate file    (-e) option is not supported.  If someone manages
  45.     to explain to me just what it does, and    convinces me that it's
  46.     sufficiently useful, I might implement it.
  47.  
  48.       o    The file names in the include directory    list (-i) must be separated
  49.     by commas.  The    list may not be    enclosed in quotes.
  50.  
  51.       o    Labels assigned    by EQUR    and REG    directives are case-sensitive.
  52.  
  53.       o    The following directives are not supported, and    will be    flagged    as
  54.     invalid    op-codes:
  55.  
  56.         RORG
  57.         OFFSET
  58.         NOPAGE
  59.         LLEN
  60.         PLEN
  61.         NOOBJ
  62.         FAIL
  63.         FORMAT
  64.         NOFORMAT
  65.         MASK2
  66.  
  67.     I feel that NOPAGE, LLEN, and PLEN should not be defined within    a
  68.     source module.    It doesn't make sense to me to have to change your
  69.     program    just because you want to print your listings on    different
  70.     paper.    The command-line option    "-p" (see below) can be used as a
  71.     replacement for    PLEN.
  72.  
  73.  
  74. EXTENSIONS
  75.  
  76.      Now for the good stuff:
  77.  
  78.       o    Labels can be any length that will fit onto one    source line
  79.     (currently 128 bytes maximum).    Since labels are stored    on the
  80.     heap, the number of labels that    can be processed is limited only
  81.     by available memory, which can be increased by using the "-w"
  82.     option (see below).
  83.  
  84.       o    Since section data and user macro definitions are stored on the
  85.     same heap as the symbol    table (see above), they    too are    limited
  86.     only by    available memory.  (Actually, there is a hard-coded limit
  87.     of 32767 sections, but I doubt anyone will run into that one.)
  88.  
  89.       o    The only values    a label    cannot take are    the register names - the
  90.     assembler can distinguish between the same name    used as    a label,
  91.     instruction name, macro    name, directive, or section name.
  92.  
  93.       o    Section    and user macro names appear in the symbol table    dump, and
  94.     will also be cross-referenced.    Their names can    be the same as any
  95.     label (see above); the assembler can sort them out.
  96.  
  97.       o    Includes and macro calls can be    nested indefinitely, limited only
  98.     by available memory.  The message "Secondary heap overflow -
  99.     assembly terminated" will be displayed if memory is exhausted.
  100.     You can    increase the size of this heap using the -w parameter
  101.     (see below).  Recursive    macros are supported; recursive    includes
  102.     will, of course, result    in a loop that will be broken only when
  103.     the heap overflows.
  104.  
  105.       o    The EVEN directive forces alignment on a word (2-byte) boundary.
  106.     It does    the same thing as CNOP 0,2.
  107.     (This one is left over from the    original code.)
  108.  
  109.       o    Branch (Bcc) instructions to a previously-defined label    will be
  110.     automatically converted    to short form if possible.  This feature is
  111.     not available for forward branches, since in pass 1 the    assembler
  112.     doesn't yet know how far the branch must go.
  113.  
  114.       o    If a MOVEM instruction only specifies one register, it is converted
  115.     to the corresponding MOVE instruction.    Instructions of    the form
  116.     MOVEM D0-D0,label will not be converted, however.
  117.  
  118.       o    ADD, SUB, and MOVE instructions    will be    converted to ADDQ, SUBQ,
  119.     and MOVEQ respectively if possible.  Instructions coded    explicitly
  120.     as (for    example) ADDA or ADDI will not be converted.
  121.  
  122.       o    ADD, CMP, SUB, and MOVE    to an address register are converted to
  123.     ADDA, CMPA, SUBA, and MOVEA respectively, except if an ADD, SUB,
  124.     or MOVE    instruction has    already    been convreted to quick    form.
  125.  
  126.       o    ADD, AND, CMP, EOR, OR,    and SUB    of an immediate    value are converted
  127.     to ADDI, ANDI, CMPI, EORI, ORI,    and SUBI respectively (unless the
  128.     address    register or quick conversion above has already been done).
  129.  
  130.       o    If both    operands of a CMP instruction are postincrement    mode, the
  131.     instruction is converted to CMPM.
  132.  
  133.       o    The SECTION directive allows a third parameter.     This can be
  134.     specified as either CHIP or FAST (upper- or lower-case).  If this
  135.     parameter is present, the hunk will be written with the    MEMF_CHIP
  136.     or MEMF_FAST bit set.  This allows you to produce "pre-ATOMized"
  137.     object modules.
  138.  
  139.       o    The synonyms DATA and BSS are accepted for SECTION directives
  140.     starting data or BSS hunks.  A section name is mandatory for
  141.     all non-CODE hunks.
  142.  
  143.       o    The ability to produce Motorola    S-records is retained from the
  144.     original code.    The -s option causes the assembler to produce
  145.     S-format instead of AmigaDOS format.  Relocatable code cannot be
  146.     produced in this format.
  147.  
  148.       o    Error messages include the name    of the source, macro, or include
  149.     module that contains the statement in error, plus the line number
  150.     within the module of the offending line.  If a statement has
  151.     multiple errors, this information appears only on the first
  152.     error message for the statement.
  153.  
  154.  
  155. HOW TO USE IT
  156.  
  157.      The command-line syntax to    run the    assembler is as    follows:
  158.  
  159.     a68k <source file>
  160.         [-o<object file>]
  161.         [-l<listing file>]
  162.         [-i<include dirlist>]
  163.         [-p<page depth>]
  164.         [-d]
  165.         [-s]
  166.         [-w[<primary-heap-size>][,secondary-heap-size]]
  167.         [-x]
  168.  
  169. These options can be given in any order, so if you like    to specify your
  170. switches first,    you can.  Option values, if any, must immediately follow
  171. the keyword with no intervening    spaces.
  172.  
  173.      If    the -o keyword is omitted, the object file will    be given a default
  174. name.  It is created by    replacing all characters after the last    period in
  175. the source file    name by    "o".  For example, if the source file name is
  176. "myprog.asm", the object file name defaults to "myprog.o".  A source name
  177. of "my.new.prog.asm" produces a default object file name of "my.new.prog.o".
  178. If the source file name    does not contain a period, ".o" is appended to it
  179. to produce the default object file name.
  180.  
  181.      The default value for the listing file name is arrived at in the same
  182. way as the object file name, except that ".lst" is appended instead of ".o".
  183. If you don't specify this parameter, no listing file will be produced.
  184. If you specify -x (see below), -l (with    the default name) is assumed,
  185. although you can still use this    parameter if you wish.
  186.  
  187.      The include directory list    is a list of directory names separated by
  188. commas.     No embedded blanks are    allowed.  For example, the specification
  189.     -imylib,df1:another.lib
  190. will cause include files to be searched    for first in the current directory,
  191. then in    "mylib", then in "df1:another.lib".
  192.  
  193.      The -d keyword causes symbol table    entries    (hunk_symbol) to be written
  194. to the object module for the use of symbolic debuggers.
  195.  
  196.      The -p keyword causes the page depth to be    set to the specified value.
  197. If omitted, a default of 60 lines (-p60) is assumed.
  198.  
  199.      The -s keyword, if    specified, causes the object file to be    written    in
  200. Motorola S-record format.  If omitted, AmigaDOS    format will be produced.
  201. The default name for an    S-record file has ".s" appended to the source name,
  202. rather than ".o"; this can still be overridden with the -o keyword, though.
  203.  
  204.      The -w keyword specifies the size of the heaps used.  The primary heap
  205. stores the symbol table, user macro text, relocation information, and
  206. cross-reference    information.  The secondary heap stores    information for
  207. nested macro calls and include files.  The primary heap    size defaults to
  208. 32768 bytes, which should be enough for    all but    the largest assemblies.
  209. The secondary heap size    defaults to 1024 bytes,    which should be    enough
  210. unless you use very deeply nested macros and/or    include    files with long
  211. path names.  You can specify either or both parameters.     For example:
  212.     -w40000        secondary heap size remains at 1024 bytes
  213.     -w,2000        primary    heap size remains at 32768 bytes
  214.     -w40000,2000    increases the size of both heaps
  215. If you're really tight for memory, and are assembling small modules, you
  216. can use    this keyword to    shrink the heaps below their default sizes.
  217. At the end of an assembly, a message will be displayed giving the
  218. amount of heap space actually used, in the form    of the -w command
  219. you would have to enter    to allocate the    mininum    heap space.
  220. See below for a    layout of the heaps.
  221.  
  222.      The -x keyword will cause the symbol table    dump to    include
  223. cross-reference    information.  If you haven't also specified -l (with
  224. or without a file name), -l with the default file name will be assumed.
  225.  
  226.  
  227.      If    you wish to override the default object    and (optionally) listing
  228. file names, you    can omit the -o    and -l keywords.  The assembler    interprets
  229. the first three    parameters without leading hyphens as the source, object,
  230. and listing file names respectively.  Anything over three file names is    an
  231. error, as is attempting    to respecify a file name with the -o or    -l keywords.
  232.  
  233.  
  234.      The primary heap is built from both ends.    Symbol table entries
  235. (including labels) and macro text are stored during pass 1.  Cross-reference
  236. data is    stored during pass 2.  Relocation information is also stored during
  237. pass 2,    but is cleared at the end of each SECTION.  Since it is    no longer
  238. needed once dumped, the    space is freed for re-use by the next section's
  239. relocation information.     The expression    parser also uses the primary heap
  240. to store its working stacks - this space is freed as soon as an    expression
  241. has been evaluated.
  242.      The fixed portion of each symbol table entry occupies 16 bytes.  The
  243. labels and macro text occupy just enough space to hold their strings
  244. (including the end-of-string delimiter)    - they are all pointed to by fixed
  245. symbol table entries.  Relocation entries occupy 10 bytes each.
  246. Cross-reference    entries    are 12 bytes long - each holds four references to
  247. one symbol.  The expression parser creaates temporary entries for terms
  248. (10 bytes each)    and operators (4 bytes each).  Since terms are combined
  249. as soon    as possible, the parser    almost never needs to store the    entire
  250. expression on the heap.
  251.      The diagram below illustrates the layout of the primary heap.  High
  252. memory addresses are at    the top    of the diagram,    while low addresses are
  253. at the bottom.    The names on the left of the diagram are the names of the
  254. pointers to the    various    tables within the heap.
  255.  
  256.     Heap + maxheap ------------->  ___________________________
  257.                       |                  |
  258.                       |      Symbol table          |
  259.     struct SymTab *SymStart     ---> |___________________________|
  260.                       |                  |
  261.                       |      Symbol references      |
  262.     struct Ref *RefStart -------> |___________________________|
  263.                       |                  |
  264.                       |      (unused space)      |
  265.     char *HeapLim --------------> |___________________________|
  266.                       |                  |
  267.                       |      Relocation data      |
  268.     struct RelTab *RelStart    ----> |___________________________|
  269.                       |                  |
  270.                       |      Labels and macro text      |
  271.     char *Heap -----------------> |___________________________|
  272.  
  273.      Note that the pointers are    to various types.  This    makes for
  274. lots of    interesting casts.  (Ain't C fun?)  Since the relocation
  275. data is    cleared    at the end of each section, HeapLim will move up and
  276. down.  The "high-water mark" is stored in char *HighHeap, which is
  277. used solely to produce the memory usage    message    at the end of the
  278. assembly.  Note    that a program may consist of a    section    containing
  279. many relocatable references, followed by a section with    fewer
  280. relocatable references but lots    of symbol references.  In this case,
  281. RefStart might end up below HighHeap, and the final message would
  282. indicate that more heap    space was used than was    available.  This is
  283. not an error - only if RefStart    hits HeapLim will an error be reported.
  284.  
  285.  
  286.      The secondary heap    is also    built from both    ends, but it grows and
  287. shrinks    according to how many macros and include files are currently open.
  288. At all times there will    be at lease one    entry on the heap, for the original
  289. source code file.
  290.      The bottom    of the heap holds the names of the source code file and
  291. any macro or include files that    are currently open .  The full path is
  292. given.    A null string is stored    for user macros.  Macro    arguments are
  293. stored by additional strings, one for each argument in the macro call line.
  294. All strings are    stored in minimum space, similar to the    labels and user
  295. macro text on the primary heap.     File names are    pointed    to by the fixed
  296. table entries (see below) - macro arguments are    accessed by stepping past
  297. the macro name to the desired argument,    unless NARG would be exceeded.
  298.      The fixed portion of the heap is built down from the top.    Each entry
  299. occupies 16 bytes.  Enough information is stored to return to the proper
  300. position in the    outer file once    the current macro or include file has been
  301. completely processed.
  302.      The diagram below illustrates the layout of the secondary heap.
  303.  
  304.     Heap2 +    maxheap2 ----------->  ___________________________
  305.                       |                  |
  306.                       |      Input    file table      |
  307.     struct InFCtl *InF ---------> |___________________________|
  308.                       |                  |
  309.                       |      Parser operator stack      |
  310.     struct OpStack *Ops --------> |___________________________|
  311.                       |                  |
  312.                       |      (unused space)      |
  313.     struct TermStack *Term -----> |___________________________|
  314.                       |                  |
  315.                       |      Parser term stack      |
  316.     char *NextFNS --------------> |___________________________|
  317.                       |                  |
  318.                       |      Input    file name stack      |
  319.     char *Heap2 ----------------> |___________________________|
  320.  
  321.      The "high-water mark" for NextFNS is stored in char *High2,
  322. and the    "low-water mark" (to stretch a metaphor) for InF is stored
  323. in struct InFCtl *LowInF.  Again, these    figures    are used only to
  324. determine the maximum heap usage.
  325.  
  326.  
  327.      Please send me any    bug reports, flames, etc.  I can be reached on
  328. Dorean BBS (604/432-8579), Mind    Link (604/533-2312), at    any Panorama
  329. (PAcific NORthwest AMiga Association) meeting, or via Jeff Lydiatt
  330. or Larry Phillips.  (I don't have the time or money to live on
  331. Usenet or CompuServe, etc.)
  332.  
  333.                 Charlie    Gibbs
  334.                 #21 - 21555 Dewdney Trunk Road
  335.                 Maple Ridge, B.C.  CANADA
  336.                 V2X 3G6
  337.  
  338.  
  339. P.S.  COMING SOON TO AN    AMIGA NEAR YOU:     68010/68020 support!
  340.