home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff287.lzh / DAsm / doc / dasm.doc < prev    next >
Text File  |  1989-12-06  |  20KB  |  601 lines

  1.  
  2.  
  3. DOCUMENTATION FOR DASM V2.12, a high level macro cross assembler for:
  4.  
  5.     -6502
  6.     -68705
  7.     -6803
  8.     -HD6303 (extension of 6803)
  9.     -68HC11
  10.  
  11.     (C)Copyright 1987,1988 Matthew Dillon, All Rights Reserved
  12.  
  13.     Publicly distributable for non-profit only.  Must be distributed
  14.     as is, with NO CHANGES to the documentation or code.  If you want
  15.     your (general) changes to be made part of the distribution, send
  16.     them to me.
  17.  
  18.     Over the last year my work has included writing software to drive small
  19.     single-chip microcomputers for various things (remote telemetry units,
  20.     for instance).  I have had need to program quite a few different
  21.     processors over that time.
  22.  
  23.     At the beginning, I used an awful macro assembler running on an IBM-PC.
  24.     I *really* wanted to do it on my Amiga.  Thus the writing of this
  25.     program.
  26.  
  27.     Feel free to suggest other similar processors for me to add to the list!
  28.     The processor type is specified with a pseudo-op (see below).  This
  29.     assembler produces only binary output in one of three formats described
  30.     below.  In general, one has a master assembly file which INCLUDEs all
  31.     the modules.
  32.  
  33.     Also provided is FTOHEX which converts an output file in one of the
  34.     three formats to an intel-hex format suitable for many intelligent
  35.     prom programmers (I have a GTEK).
  36.  
  37.     YES it's packed with features!
  38.  
  39. FEATURES:
  40.  
  41.     -fast assembly
  42.     -supports several common 8 bit processor models (NOT 8086, thank god!)
  43.     -takes as many passes as needed
  44.     -automatic checksum generation, special symbol '...'
  45.     -several binary output formats available.  Format 2 allows reverse
  46.      indexed origins.
  47.     -multiple segments, BSS segments (no generation), relocatable origin.
  48.     -expressions, as in C but [] is used instead of () for parenthesis.
  49.      (all expressions are computed with 32 bit integers)
  50.     -no real limitation on label size, label values are 32 bits.
  51.     -complex pseudo ops, repeat loops, macros, etc....
  52.  
  53.  
  54. COMMAND LINE:
  55.  
  56.     asm srcfile [options]
  57.  
  58.     options:    -f#     select output format 1-3 (default 1, see below)
  59.             -oname  select output file name (else a.out)
  60.             -lname  select list file name   (else none generated)
  61.             -sname  select symbol dump file (else none generated)
  62.             -v#     select verboseness 0-4 (default 0, see below)
  63.             -d        debug mode
  64.             -DSYMBOL            predefine a symbol, set to 0
  65.             -DSYMBOL=EXPRESSION     predefine a symbol, set to exp
  66.  
  67.     Note: file names should be in RAM: for speed.  If a list file is
  68.     specified, it should be in the RAM: disk (assembly is slowed down
  69.     quite a bit anyway).
  70.  
  71.     Example:    asm master.asm -f2 -oram:out -lram:list -v3 -DVER=4
  72.  
  73. FORMAT OPTIONS:
  74.  
  75.     1  (DEFAULT)
  76.  
  77.     The output file contains a two byte origin in LSB,MSB order, then
  78.     data until the end of the file.
  79.  
  80.     Restrictions:    Any instructions which generate output (within an
  81.     initialized segment) must do so with an ascending PC.  Initialized
  82.     segments must occur in ascending order.
  83.  
  84.     2  RAS (Random Access Segment)
  85.  
  86.     The output file contains one or more hunks.  Each hunk consists
  87.     of a 2 byte origin (LSB,MSB), 2 byte length (LSB,MSB), and that
  88.     number of data bytes.  The hunks occur in the same order as
  89.     initialized segments in the assembly.  There are no restrictions
  90.     to segment ordering (i.e. reverse indexed ORG statements are
  91.     allowed).  The next hunk begins after the previous hunk's data,
  92.     until the end of the file.
  93.  
  94.     3  RAW (Raw)
  95.  
  96.     The output file contains data only (format #1 without the 2 byte
  97.     header).  Restrictions are the same as for format #1.
  98.  
  99.     Format 3    RAW (Raw format)
  100.         Same as format 1, but NO header origin is generated.  You get
  101.         nothing but data.
  102.  
  103. VERBOSE OPTIONS:
  104.  
  105.     0    (default)
  106.  
  107.     Only warnings and errors are generated
  108.  
  109.     1
  110.     -Segment list information generated after each pass
  111.     -Include file names are displayed
  112.     -statistics on why the assembler is going to make another pass
  113.         R1,R2 reason code: R3
  114.         where R1 is the number of times the assembler encountered
  115.         something requiring another pass to resolve.  R2 is the
  116.         number of references to unknown symbols which occured in the
  117.         pass (but only R1 determines the need for another pass).  R3
  118.         is a BITMASK of the reasons why another pass is required.
  119.         See the end of this document for bit designations.
  120.  
  121.     2
  122.     mismatches between program labels and equates are displayed
  123.     on every pass (usually none occur in the first pass unless you
  124.     have re-declared a symbol name).
  125.  
  126.     displayed information for symbols:
  127.         ???? = unknown value
  128.         str  = symbol is a string
  129.         eqm  = symbol is an eqm macro
  130.         (r)  = symbol has been referenced
  131.         (s)  = symbol created with SET or EQM pseudo-op
  132.  
  133.     3
  134.         Unresolved and unreferenced symbols are displayed every pass
  135.         (unsorted, sorry)
  136.  
  137.     4
  138.         An entire symbol list is displayed every pass to STDOUT.
  139.         (unsorted, sorry)
  140.  
  141. PROCESSOR MODEL:
  142.  
  143.     The processor model is chosen with the PROCESSOR pseudo-op and should
  144.     be the first thing you do in your assembly file.   Different processor
  145.     models use different integer formats (see below).  The word order does
  146.     not effect the headers in the output files (-f1 and -f2), which are
  147.     always LSB,MSB.  The word ordering effects all address, word, and
  148.     long generation.
  149.  
  150.     Only one PROCESSOR pseudo-op may be declared in the entire assembly,
  151.     and should be the first thing encountered.
  152.  
  153.     -6502        LSB,MSB
  154.     -68HC11     MSB,LSB
  155.     -68705        MSB,LSB
  156.     -6803        MSB,LSB
  157.     -HD6303     MSB,LSB
  158.  
  159. SEGMENTS:
  160.     The SEG pseudo-op creates/sets the current segment.  Each segment has
  161.     it's own origin and is optionally an 'uninitialized' segment.
  162.     Unitialized segments produce no output and have no restrictions.  This
  163.     is useful for determining the size of a certain assembly sequence
  164.     without generating code, and for assigning RAM to labels.
  165.  
  166.     'Initialized' segments produce output.  The following should be
  167.     considered when generating roms:
  168.  
  169.     (1) The default fill character when using ORG (and format 1 or 3) to
  170.     skip forward is 00.  This is a GLOBAL default and effects all
  171.     segments.  See ORG.
  172.  
  173.     (2) The default fill character for DS is 00 and is independant of
  174.     the default fill character for ORG (see DS).
  175.  
  176. GENERAL:
  177.     Most everything is recursive.  You cannot have a macro DEFINITION
  178.     within a macro definition, but can nest macro calls, repeat loops,
  179.     and include files.
  180.  
  181.     The other major feature in this assembler is the SUBROUTINE pseudo-op,
  182.     which logically separates local labels (starting with a dot).  This
  183.     allows you to reuse label names (for example, .1 .fail) rather than
  184.     think up crazy combinations of the current subroutine to keep it all
  185.     unique.
  186.  
  187.     Almost nothing need be resolved in pass 1.    The assembler will make
  188.     multiple passes in an attempt to resolve the assembly (including just
  189.     one pass if everything is resolved immediately).
  190.  
  191.  
  192. PSEUDOPS:
  193.  
  194.     INCLUDE     "name"
  195.  
  196.         Include another assembly file.
  197.  
  198. [label] SEG[.U]     name
  199.  
  200.         This sets the current segment, creating it if neccessary.  If
  201.         a .U extension is specified on segment creation, the segment
  202.         is an UNINITIALIZED segment.  The .U is not needed when going
  203.         back to an already created uninitialized segment, though it
  204.         makes the code more readable.
  205.  
  206. [label] DC[.BWL]    exp,exp,exp ...
  207.  
  208.         Declare data in the current segment.  No output is generated if
  209.         within a .U segment.  Note that the byte ordering for the
  210.         selected processor is used for each entry.
  211.  
  212.         The default size extension is a byte.
  213.  
  214. [label] DS[.BWL]    exp[,filler]
  215.  
  216.         declare space (default filler is 0). Data is not generated if
  217.         within an uninitialized segment.  Note that the number of bytes
  218.         generated is exp * entrysize (1,2, or 4)
  219.  
  220.         The default size extension is a byte.
  221.  
  222.         Note that the default filler is always 0 (has nothing to do
  223.         with the ORG default filler).
  224.  
  225. [label] DV[.BWL]    eqmlabel exp,exp,exp....
  226.  
  227.         This is equivalent to DC, but each exp in the list is passed
  228.         through the symbolic expression specified by the EQM label.
  229.         The expression is held in a special symbol dotdot '..' on each
  230.         call to the EQM label.
  231.  
  232.         See EQM below
  233.  
  234. [label] HEX        hh hh hh..
  235.  
  236.         This sets down raw HEX data.  Spaces are optional between bytes.
  237.         NO EXPRESSIONS are allowed.  Note that you do NOT place a $
  238.         in front of the digits.  This is a short form for creating
  239.         tables compactly.  Data is always layed down on a byte-by-byte
  240.         basis.
  241.  
  242.         Example:        HEX 1A45 45 13254F 3E12
  243.  
  244.     ERR
  245.  
  246.         Abort assembly.
  247.  
  248. [label] ORG        exp[,DefaultFillVal]
  249.  
  250.         This pseudop sets the current origin.  You can also set the
  251.         global default fill character (a byte value) with this
  252.         pseudoop.  NOTE that no filler is generated until the first
  253.         data-generating opcode/psueoop is encountered after this one.
  254.         Sequences like:
  255.  
  256.         org  0,255
  257.         org  100,0
  258.         org  200
  259.         dc   23
  260.  
  261.         will result in 200 zero's and a 23. This allows you to specify
  262.         some ORG, then change your mind and specify some other (lower
  263.         address) ORG without causing an error (assuming nothing is
  264.         generated inbetween).
  265.  
  266.         Normally, DS and ALIGN are used to generate specific filler
  267.         values.
  268.  
  269. [label] RORG        exp
  270.  
  271.         This activates the relocatable origin.  All generated
  272.         addresses, including '.', although physically placed at the
  273.         true origin, will use values from the relocatable origin.
  274.         While in effect both the physical origin and relocatable origin
  275.         are updated.
  276.  
  277.         The relocatable origin can skip around (no limitations).  The
  278.         relocatable origin is a function of the segment.  That is, you
  279.         can still SEG to another segment that does not have a
  280.         relocatable origin activated, do other (independant) stuff
  281.         there, and then switch back to the current segment and continue
  282.         where you left off.
  283.  
  284.     PROCESSOR model
  285.  
  286.         do not quote.  model is one of: 6502,6803,HD6303,68705,68HC11
  287.         Can only be executed once, and should be the first thing
  288.         encountered by the assembler.  the 68HC11 will be available
  289.         next release.
  290.  
  291.     ECHO exp,exp,exp
  292.  
  293.         The expressions (which may also be strings), are echod on the
  294.         screen and into the list file
  295.  
  296. [label] REND
  297.  
  298.         Deactivate the relocatable origin for the current segment.
  299.         Generation uses the real origin for reference.
  300.  
  301. [label] ALIGN        N[,fill]
  302.  
  303.         Align the current PC to an N byte boundry.    The default
  304.         fill character is always 0, and has nothing to do with
  305.         the default fill character specifiable in an ORG.
  306.  
  307. [label] SUBROUTINE  name
  308.  
  309.         This isn't really a subroutine, but a boundry between sets of
  310.         temporary labels (which begin with a dot).  Temporary label
  311.         names are unique within segments of code bounded by SUBROUTINE:
  312.  
  313.         CHARLIE subroutine
  314.             ldx #10
  315.         .1    dex
  316.             bne .1
  317.         BEN    subroutine
  318.             ldx #20
  319.         .qq    dex
  320.             bne .qq
  321.  
  322.         Automatic temporary label boundries occur for each macro level.
  323.         Usually temporary labels are used in macros and within actual
  324.         subroutines (so you don't have to think up a thousand different
  325.         names)
  326.  
  327.  
  328. symbol    EQU        exp
  329.  
  330.         The expression is evaluated and the result assigned to the
  331.         symbol.
  332.  
  333. symbol    EQM        exp
  334.  
  335.         The STRING representing the expression is assigned to the
  336.         symbol.  Occurances of the label in later expressions causes
  337.         the string to be evaluated for each occurance.  Also used in
  338.         conjuction with the DV psuedo-op.
  339.  
  340. symbol    SET        exp
  341.  
  342.         Same as EQU, but the symbol may be reassigned later.
  343.  
  344.     MAC        name
  345.  
  346.         Declare a macro.  lines between MAC and ENDM are the macro.
  347.         You cannot recursively declare a macro.  You CAN recursively
  348.         use a macro (reference a macro in a macro).  No label is
  349.         allowed to the left of MAC or ENDM.
  350.  
  351.         Arguments passed to macros are referenced with: {#}.  The first
  352.         argument passed to a macro would thus be {1}.  You should
  353.         always use LOCAL labels (.name) inside macros which you use
  354.         more than once. {0} represents an EXACT substitution of the
  355.         ENTIRE argument line.
  356.  
  357.     ENDM
  358.  
  359.         end of macro def.  NO LABEL ALLOWED ON THE LEFT!
  360.  
  361.     MEXIT
  362.  
  363.         Used in conjuction with conditionals.  Exits the current macro
  364.         level.
  365.  
  366. [label] IFCONST     exp
  367.  
  368.         Is TRUE if the expression result is defined,  FALSE otherwise
  369.         and NO error is generated if the expression is undefined.
  370.  
  371. [label] IFNCONST    exp
  372.  
  373.         Is TRUE if the expression result is undefined, FALSE otherwise
  374.         and NO error is generated if the expression is undefined.
  375.  
  376. [label] IF        exp
  377.  
  378.         Is TRUE if the expression result is defined AND non-zero.
  379.         Is FALSE if the expression result is defined AND zero.
  380.         Neither IF or ELSE will be executed if the expression result
  381.         is undefined.  If the expression is undefined, another assembly
  382.         pass is automatically taken.
  383.  
  384. [label] ELSE
  385.  
  386.         ELSE the current IF.
  387.  
  388. [label] ENDIF
  389. [label] EIF
  390.  
  391.         Terminate an IF. ENDIF and EIF are equivalent.
  392.  
  393. [label] REPEAT        exp
  394. [label] REPEND
  395.  
  396.         Repeat code between REPEAT/REPEND 'exp' times.  if exp == 0,
  397.         the code repeats forever.  exp is evaluated once.
  398.  
  399.         Y   SET     0
  400.             REPEAT  10
  401.         X   SET     0
  402.             REPEAT  10
  403.             DC        X,Y
  404.         X   SET     X + 1
  405.             REPEND
  406.         Y   SET     Y + 1
  407.             REPEND
  408.  
  409.         generates an output table:    0,0 1,0 2,0 ... 9,0  0,1 1,1 2,1
  410.         ... 9,1, etc...
  411.  
  412.         Labels within a REPEAT/REPEND should be temporary labels with a
  413.         SUBROUTINE pseudoop to keep them unique.
  414.  
  415.         The Label to the left of REPEND is assigned AFTER the loop
  416.         FINISHES.
  417.  
  418.  
  419. [label] XXX[.force] operand
  420.  
  421.         XXX is some mnemonic, not necessarily three characters long.
  422.         The .FORCE optional extension is used to force specific
  423.         addressing modes (see below).
  424.  
  425. GENERAL:
  426.  
  427.     The label will be set to the current ORG/RORG either before or after
  428.     a pseudo-op is executed.  Most of the time, the label to the left of a
  429.     pseudo-op is the current ORG/RORG. The following pseudo-op's labels are
  430.     created AFTER execution of the pseudo-op:
  431.  
  432.     SEG, ORG, RORG, REND, ALIGN
  433.  
  434. EXTENSIONS:
  435.  
  436.     FORCE extensions are used to force an addressing mode.  In some cases,
  437.     you can optimize the assembly to take fewer passes by telling it the
  438.     addressing mode.  Force extensions are also used with DS,DC, and DV
  439.     to determine the element size.  NOT ALL EXTENSIONS APPLY TO ALL
  440.     PROCESSORS!
  441.  
  442.     example:    lda.z   charlie
  443.  
  444.     i   -implied
  445.     ind -indirect word
  446.     0   -implied
  447.     0x  -implied indexing (0,x)
  448.     0y  -implied indexing (0,y)
  449.     b   -byte address
  450.     bx  -byte address indexed x
  451.     by  -byte address indexed y
  452.     w   -word address
  453.     wx  -word address indexed x
  454.     wy  -word address indexed y
  455.     l   -longword (4 bytes) (DS/DC/DV)
  456.     r   -relative
  457.     u   -uninitialized (SEG)
  458.  
  459.     First character equivalent substitutions:
  460.  
  461.     b z d        (byte, zeropage, direct)
  462.     w e a        (word, extended, absolute)
  463.  
  464.  
  465. ASSEMBLER PASSES:
  466.     The assembler may have to make several passes through the source
  467.     code to resolve all generation.  The number of passes is not
  468.     limited to two.  Since this may result in an unexpected, verbose
  469.     option 2, 3, and 4 have been provided to allow determination of the
  470.     cause. The assembler will give up if it thinks it can't do the
  471.     assembly in *any* number of passes.
  472.  
  473.     Error reporting could be better....
  474.  
  475.  
  476. EXPRESSIONS:
  477.     [] may be used to group expressions.  The precedense of operators
  478.     is the same as for the C language in almost all respects.  Use
  479.     brackets [] when you are unsure.  The reason () cannot be used to
  480.     group expressions is due to a conflict with the 6502 and other
  481.     assembly languages.
  482.  
  483.     Some operators, such as ||, can return a resolved value even if
  484.     one of the expressions is not resolved.   Operators are as follows:
  485.  
  486.     NOTE WELL!  Some operations will result in non-byte values when a
  487.     byte value was wanted.    For example:    ~1  is NOT $FF, but
  488.     $FFFFFFFF.  Preceding it with a < (take LSB of) will solve the
  489.     problem.  ALL ARITHMETIC IS CARRIED OUT IN 32 BITS.  The final
  490.     Result will be automatically truncated to the maximum handleable
  491.     by the particular machine language (usually a word) when applied
  492.     to standard mnemonics.
  493.  
  494.     prec        UNARY
  495.  
  496.     20  ~exp    one's complement.
  497.     20  -exp    negation
  498.     20  !exp    not expression (returns 0 if exp non-zero, 1 if exp zero)
  499.     20  <exp    take LSB byte of a 16 bit expression
  500.     20  >exp    take MSB byte of an expression
  501.  
  502.             BINARY
  503.  
  504.     19  *        multiplication
  505.     19  /        division
  506.     19  %        mod
  507.     18  +        addition
  508.     18  -        subtraction
  509.     17  >>,<<   shift right, shift left
  510.     16  >,>=    greater, greater equal
  511.     16  <,<=    smaller, smaller equal
  512.     15  ==        equal to.  Try to use this instead of =
  513.     15  =        exactly the same as == (exists compatibility)
  514.     15  !=        not equal to
  515.     14  &        logical and
  516.     13  ^        logical xor
  517.     12  |        logical or
  518.     11  &&        left expression is true AND right expression is true
  519.     10  ||        left expression is true OR right expression is true
  520.      9  ?        if left expression is true, result is right expression,
  521.             else result is 0.    [10 ? 20] returns 20
  522.      8  []        group expressions
  523.      7  ,        separate expressions in list (also used in
  524.             addressing mode resolution, BE CAREFUL!
  525.  
  526.     Constants:
  527.  
  528.     nnn    decimal
  529.     0nnn    octal
  530.     %nnn    binary
  531.     $nnn    hex
  532.     'c      character
  533.     "cc.."  string (NOT zero terminated if in DC/DS/DV)
  534.     [exp]d    the constant expressions is evaluated and it's decimal
  535.         result turned into an ascii string.
  536.  
  537.     Symbols:
  538.  
  539.     ...    -holds CHECKSUM so far (of actual-generated stuff)
  540.     ..    -holds evaluated value in DV pseudo op
  541.     .name    -represents a temporary symbol name.  Temporary symbols
  542.          may be reused inside MACROS and between SUBROUTINES, but
  543.          may not be referenced across macros or across SUBROUTINEs.
  544.     .    -current program counter (as of the beginning of the
  545.          instruction).
  546.     name    -beginning with an alpha character and containing letters,
  547.          numbers, or '_'.  Represents some global symbol name.
  548.  
  549.  
  550. WHY codes:
  551.     Each bit in the WHY word (verbose option 1) is a reason (why
  552.     the assembler needs to do another pass), as follows:
  553.  
  554.     bit 0   expression in mnemonic not resolved
  555.     1   -
  556.     2   expression in a DC not resolved
  557.     3   expression in a DV not resolved (probably in DV's EQM symbol)
  558.     4   expression in a DV not resolved (could be in DV's EQM symbol)
  559.     5   expression in a DS not resolved
  560.     6   expression in an ALIGN not resolved
  561.     7   ALIGN: Relocatable origin not known (if in RORG at the time)
  562.     8   ALIGN: Normal origin not known    (if in ORG at the time)
  563.     9   EQU:   expression not resolved
  564.     10  EQU:   value mismatch from previous pass (phase error)
  565.     11  IF:     expression not resolved
  566.     12  REPEAT: expression not resolved
  567.  
  568.     13  a program label has been defined after it has been
  569.         referenced (forward reference) and thus we need another
  570.         pass
  571.     14  a program label's value is different from that of the
  572.         previous pass (phase error)
  573.  
  574.     Certain errors will cause the assembly to abort immediately, others
  575.     will wait until the current pass is other.    The remaining allow another
  576.     pass to occur in the hopes the error will fix itself.
  577.  
  578.  
  579. VERSIONS:
  580.  
  581.     V2.12
  582.     -Fixed macro naming bug (macros wouldn't work if the name after
  583.      the 'mac' was in upper case).
  584.  
  585.     V2.11
  586.     -Fixed <exp >exp bug, <exp now means LSB, >exp MSB (it used to
  587.      be reversed).
  588.     -Fixed many bugs in macros and other things
  589.     -Added automatic checksumming ... no more doing checksums manually!
  590.     -Added several new processors, including 6502.
  591.     -Source is now 16/32 bit int compatible, and will compile on an
  592.      IBM-PC (the ultimate portability test)
  593.  
  594.     V2.01
  595.  
  596.     -can now have REPEAT/REPEND's within macros
  597.     -fill field for DS.W is a word (used to be a byte fill)
  598.     -fill field for DS.L is a long (used to be a byte fill)
  599.  
  600.  
  601.