home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 303.lha / AssemTools / Asm65 / Asm65.doc < prev    next >
Text File  |  1980-12-03  |  18KB  |  581 lines

  1.  
  2.  
  3.               65c02 Cross Assembler for Amiga
  4.              =================================
  5.  
  6.              Supervisor Software 1989
  7.                    Jukka  Marin
  8.  
  9.                    Version 2.352
  10.  
  11.  
  12.  
  13.     Freely distributable as long as all the files are kept
  14.        together and the copyright notice is not changed.
  15.  
  16.  
  17.  
  18.  
  19. Asm65 is a macro assembler running under AmigaDOS.  It was completely
  20. written in assembly language to make the executable small (and because
  21. I *love* machine language!).
  22.  
  23. I suggest that you would read through this manual.  I know that all the
  24. topics are not explained exactly where they should be.  I'll improve this
  25. document sometimes...
  26.  
  27.  
  28.  
  29.              Command line parameters
  30.             =========================
  31.  
  32.  
  33. Command line syntax is as follows:
  34.  
  35. Asm65 <sourcefile> [-opt]
  36.  
  37. where <sourcefile> is a standard AmigaDOS filename WITHOUT the .asm
  38. extension.  Asm65 will automatically add the extensions needed to
  39. generate the source and list file names.
  40.  
  41. [-opt] may contain one or more of the following options:
  42.  
  43. -l    produce a list file (uses name <filename>.lst)
  44. -h    destination file in hex dump
  45. -s    dump symbol values after assembling
  46. -c    enable 65c02 extended addressing modes and instructions
  47.  
  48. Example:
  49.  
  50. Asm65 test -s-l
  51.  
  52. will assemble a file called 'test.asm' in current directory and produce
  53. an binary file 'test' as well as a list file 'test.lst' with a symbol
  54. table.
  55.  
  56.  
  57.  
  58.              Source line syntax
  59.             ====================
  60.  
  61.  
  62. The source lines should follow the following format:
  63.  
  64. [label]        [mnemonic  [operands]]        [;comment]
  65.  
  66.  
  67. The label, if present, must start at the column 1.  The first character
  68. of a symbol must be i) an alphabetic character (a...z, A...Z) OR ii)
  69. an underscore (_) OR iii) a period (.).  The rest of the characters
  70. can be any of these characters or also numeric (0...9).
  71. The symbol names are case-sensitive, so 'test' is different from 'TEST'
  72. and 'Test'.
  73.  
  74. The line may or may not contain a mnemonic and its operands.  Comments
  75. are also optional.  The comments must begin with a ';'.
  76.  
  77. Mnemonics may *never* start at column 1.  They must always be preceded
  78. by at least one blank (a space character or a tabulator).
  79.  
  80.  
  81. An example listing follows:
  82.  
  83.  
  84. zpl        equ    251        ; free ZP storage on a C-64
  85. zph        equ    252
  86. chrout        equ    $ffd2        ; used to output a char on a C-64
  87.  
  88. text        macro
  89.         jmp    text\@z        ; causes a jump over the text
  90.         db \1
  91.         db 13,0
  92. text\@z
  93.         endm
  94.  
  95.  
  96. sjmp        macro            ; short jump
  97.         ifne    @MODE&1
  98.         bra    \1        ; on a 65c02 bra will be used
  99.         endc
  100.         ifeq    @MODE&1
  101.         jmp    \1        ; on a 6502 jmp will be used
  102.         endc
  103.         endm
  104.  
  105.  
  106.  
  107. *        equ    $c000        ; sets the destination address
  108.  
  109.         ldx    #<string    ; set the string address
  110.         ldy    #>string
  111.         stx    zpl
  112.         sty    zph
  113.         ldy    #0        ; reset index
  114. loop        lda    (zpl),y        ; get a char
  115.         beq    exit        ; NULL -> exit
  116.         jsr    chrout        ; print it
  117.         iny
  118.         bne    loop
  119.         inc    zph        ; incr. high byte of addr
  120.         sjmp    loop        ; get next char
  121.  
  122. exit        rts
  123.  
  124. string        text    'This is a test!'
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.              Symbols
  133.             =========
  134.  
  135.  
  136. The symbols can be defined in three ways:
  137. i)   using a symbol as a label
  138. ii)  by the SET directive
  139. iii) by the EQU directive
  140.  
  141. If a symbol is defined using the SET directive it may be re-defined using
  142. another SET.  Labels and EQUated symbols may not be re-defined.
  143.  
  144. * is a special symbol:  It must be EQUated to the start address of the
  145. compiled code before any code producing lines.  That is to tell the
  146. assembler where the compiled code will be located in the 6502 address
  147. space.
  148. Later, the 'asterisk' symbol contains the start address of each line
  149. (ie. jmp *  will produce an endless loop because it causes a jump to
  150. the start of line which in this case is the JMP instruction).
  151.  
  152. All symbols that will be used to address the page zero must be defined
  153. *before* they are used.  Otherwise the assembler will take the symbols
  154. as absolute ones during the first pass until it reads the definition
  155. statement.  During the second pass the assembler knows that the symbol
  156. is a page zero value and a phasing difference will occur.
  157. It is recommended to define *all* page zero symbols at the beginning of
  158. the source code to avoid any problems.
  159.  
  160. If you use the -s option during assembly the symbol table will be listed
  161. after the assembly is completed.  The symbol table contains the following
  162. fields:
  163.  
  164. symbol_name    value type usage
  165.  
  166. Symbol name fields contain the symbol names in alphabetical order.  Value
  167. is the symbol value in hexadecimal.  Type indicates the way in which the
  168. symbol was defined: S means it was SET, E that it was EQUated, and Z means
  169. that the value is a page zero address.
  170.  
  171. The assembler creates page zero references always when it is possible to
  172. use page zero addressing instead of absolute addressing.  If the page zero
  173. addressing mode is not available the absolute addressing will be used
  174. instead.
  175.  
  176.  
  177.  
  178.              Numbers
  179.             =========
  180.  
  181.  
  182. The assembler accepts numbers in decimal (default), hexadecimal (preceded
  183. by '$'), octal (preceded by '&'), in quinary (preceded by '^') and in
  184. binary (preceded by '%').  An ASCII character can also be used but it
  185. must be enclosed in single quotes (eg. 'A' = 65 = $41 = %1000001 = &101).
  186.  
  187.  
  188.  
  189.              Expression evaluation
  190.             =======================
  191.  
  192.  
  193. All expressions are evaluated from left to right BUT the *, /, and \
  194. operators have higher priority than the others and will be handled
  195. before addition and subtraction, for example.  The expressions
  196. enclosed in [] will be evaluated first.  The assembler knows the
  197. following operators:
  198.  
  199. oper.    operation            example
  200.  
  201. +    addition            symbol+5
  202. -    subtraction            78-43
  203. *    multiplication            10*length
  204. /    division            buffer/8
  205. \    modulo operation        length\4
  206. &    logical AND            address&7
  207. !    logical OR            bit!1
  208. ^    logical Exclusive OR        bit^1
  209. <    logical shift left        bit<5
  210. >    logical shift right        number>2
  211. -    negation (2's compelment)    -332
  212. ~    logical NOT (1's complement)    ~10
  213. <    get low byte only        <address
  214. >    get high byte only        >address
  215. @MODE    gets the current MODE value    @MODE
  216. $    a hex number            $ffd2
  217. &    an octal number            &777
  218. ^    a quinary number        ^0123
  219. %    a binary number            %10111010101
  220. ''    ASCII code conversion        'J'
  221.  
  222.  
  223. With < and > you can separate the high and low bytes of an absolute
  224. address.  For example:
  225.  
  226. pointerlow    equ    251
  227. pointerhigh    equ    252
  228.  
  229.         ...
  230.  
  231.         ldx    #<TABLE
  232.         ldy    #>TABLE
  233.         stx    pointerlow
  234.         sty    pointerhigh
  235.  
  236.         ldy    #0
  237. loop        lda    (pointerlow),y
  238.         adc    temp
  239.  
  240.         ...
  241.  
  242. TABLE        db    0,5,2,7,3,8,4,9,-1
  243.  
  244.  
  245. The system variable @MODE contains some information about the options
  246. used when starting the assembler.  Currently only the lowest five
  247. bits of the variable are used:
  248.  
  249. bit#    meaning
  250.  
  251. 0    if '1' the assembler operates in 65c02 mode (otherwise in 6502 mode)
  252. 1    if '1' the assembler is producing a hex object file (not binary)
  253. 2    if '1' the assembler will produce a symbol table after assembly
  254. 3    if '1' the assembler is producing a list file
  255. 4    if '1' the assembler is compiling an include file
  256.  
  257. This way you can make 'intelligent' macros that will utilize the extra
  258. addressing modes and instructions of the 65c02 when the compiler is
  259. operating in 65c02 mode.  Otherwise you could write your own code to
  260. achieve the same function using only 6502 instructions.
  261. You can check the @MODE variable with the conditional assembly direc-
  262. tives:
  263.  
  264. sjmp        macro            ;short jump
  265.         ifne    @MODE&1
  266.         bra    \1        ; on a 65c02 bra will be used
  267.         endc
  268.         ifeq    @MODE&1
  269.         jmp    \1        ; on a 6502 jmp will be used
  270.         endc
  271.         endm
  272.  
  273.  
  274.  
  275.  
  276.              Conditional assembly
  277.             ======================
  278.             (and other directives)
  279.  
  280. The Asm65 cross assembler supports conditional assembly.  The conditional
  281. blocks may be nested; maximum nesting level is currently set to 16.
  282. The conditional assembly directives are listed below:
  283.  
  284. dir.    operation            example
  285.  
  286. IFEQ    assemble if expression = 0    IFEQ version-5
  287. IFNE    assemble if expression <> 0    IFNE debug
  288. IFGT    assemble if expression > 0    IFGT version-4
  289. IFLT    assemble if expression < 0    IFLT test
  290. IFGE    assemble if expression >= 0
  291. IFLE    assemble if expression =< 0
  292. IFD    assemble if symbol defined    IFD debug
  293. IFND    assemble if symbol not defined    IFND debug
  294. IFC    assemble if strings identical    IFC '\1','test'
  295. IFNC    assemble if strings not ident.    IFNC '\1',''
  296. IFI    assemble if the second string contains the first string
  297. IFNI    assemble if the second string does not contain the first string
  298. ENDC    end of conditional assembly block
  299. FAIL    cause assembly to fail
  300. PAGE    inserts a page break into the list file
  301.  
  302. With IFI and IFNI you can test if a macro parameter contains a specific
  303. character, for example.
  304.  
  305.  
  306.  
  307.              Macros
  308.             ========
  309.  
  310. Any macros must be defined before they are used in the program code.
  311. The macro definitions may not be nested but it is allowed to call
  312. another macro from within a macro.  The maximum macro nesting level
  313. is currently set to 8.
  314. The first four parameters are passed to the macro while the rest are
  315. discarded.  You can handle the parameters within a macro by using a
  316. backslash followed with the parameter number (eg. \3 is the third
  317. parameter of the macro).  If no parameter is given to the macro the
  318. parameters will be NULL (ie. '').
  319. You can use the conditional assembly directives to analyse the macro
  320. parameters (you can check if the parameter is empty with IFC '\1',''
  321. or see whether it contains a known string with IFI 'reg','\2').
  322.  
  323. The macro definition is done as follows:
  324.  
  325. text        macro        ; create a macro called 'text'
  326.         db    \1    ; stores the first param. into memory
  327.         db    13,0    ; adds CR and NULL to the end of string
  328.         endm        ; ends the macro definition
  329.  
  330. NOTE: No label is allowed on the ENDM line.
  331.  
  332. The macro can be called later using the macro name as a directive:
  333.  
  334.         ...
  335.         text    'Test string for a macro!'
  336.         text    'Another line of text.'
  337.         ...
  338.  
  339. If a macro parameter like 10,13,34 is needed it must be enclosed in
  340. < and > characters.  Otherwise each individual number will be taken
  341. as a separate macro parameter.
  342.  
  343.         ...
  344.         text    <'This',32,'is only',32,'a single parameter!'>
  345.         ...
  346.  
  347.  
  348. Within macros you may use special labels whose names start with '\@'
  349. to generate unique label names.  The '\@' will be converted into a
  350. four character hexadecimal number (0001...ffff).  This number is
  351. incremented each time a symbol with '\@' is defined.
  352. Example:
  353.  
  354. test        macro
  355.         jmp    test\@
  356.         db    \1
  357. test\@                    ; Note: the ENDM line may NOT
  358.         endm            ; contain a label.
  359.  
  360.  
  361.  
  362.  
  363.              Storage allocation:
  364.             =====================
  365.  
  366. To allocate storage for variables you can use the define directive:
  367.  
  368. counter        db    4    ; allocates one byte and sets it to 4.
  369.  
  370. jumpaddr    dw    routine    ; allocates two bytes and store the
  371.                 ; value of 'routine' into memory (low
  372.                 ; byte first).
  373.  
  374. hugevalue    dl    $654312    ; allocates four bytes and writes the
  375.                 ; number into them (the least significant
  376.                 ; byte is stored at the lowest address)
  377.  
  378. Other examples:
  379.  
  380. text        db    'This is a string!',13,'Another line.',13,0
  381. adrtable    dw    load,save,help,quit
  382.  
  383.  
  384.  
  385.  
  386.              Including other files
  387.             =======================
  388.  
  389. You can include additional header files using the INCLUDE directive.
  390. The syntax is
  391.  
  392.         INCLUDE    'filename'
  393.  
  394. where filename is a standard AmigaDOS filename with an optional path.
  395. The maximum nesting level of nested include files is currently set
  396. to 8.
  397.  
  398.  
  399.  
  400.              The MODE directive
  401.             ====================
  402.  
  403. You can set or change several assembler parameters using the MODE
  404. directive.
  405. The syntax is MODE <let>[<let>[<let>...]]
  406. A lower case character turns an option OFF and an upper case character
  407. turns the option ON.  The options currently supported are listed below:
  408.  
  409. C    65c02 mode
  410. L    start/stop writing to list file
  411. S    produce the symbol table
  412. H    produce a hex object file (NOTE: No .hex extension is added to
  413.     the filename when using the MODE H directive instead of the -h
  414.     option on the command line)
  415.  
  416. You may, for example, prevent the included files to be written into the
  417. list file using the command 'MODE l' at the first line of the include
  418. file and the command 'MODE L' on the last line.  If the list file was
  419. not enabled using the -l option on the command line the 'MODE L' command
  420. will have no effect.
  421.  
  422.  
  423.  
  424.              The output file formats
  425.             =========================
  426.  
  427. The binary object file
  428.  
  429. When no -h option or MODE H command is used the assembler will produce
  430. a pure binary object file which can be executed by the 65(c)02 as it
  431. is.  No extra bytes are added to the compiled data.
  432.  
  433.  
  434. The hex object file
  435.  
  436. If the option -h is used the compiler will replace all bytes of the object
  437. code with two ASCII hex characters (ie. 00...FF).  There will be no spaces
  438. or line feeds between the hex numbers (the file will only contain one
  439. string).  At the end of the file a CTRL+Z character is added.
  440.  
  441.  
  442. The list file
  443.  
  444. When the option -l is used on the command line the compiler will write
  445. a list file on the disk.  The list file is divided into pages by FF (12)
  446. characters.  A title and a page number will be written at the top of each
  447. page.
  448.  
  449. The rows of the list file contain several fields:
  450.  
  451. line#  addr bytes     symbol          mnem    operands        comments
  452. =====  ==== =====     ======          ====    ========        ========
  453.  
  454.  65c02 Cross Assembler v2.34  (c) J. & T. Marin 1988                  --  Page #    1  --
  455.  
  456. 00001                 
  457. 00002  =00fb          zpl             equ     251             ; free ZP storage on a C-64
  458. 00003  =00fc          zph             equ     252
  459. 00004  =ffd2          chrout          equ     $ffd2           ; used to output a char on a C-64
  460. 00005                 
  461. 00006                 text            macro
  462. 00007                                 jmp     text\@z         ; causes a jump over the text
  463. 00008                                 db \1
  464. 00009                                 db 13,0
  465. 00010                 text\@z
  466. 00011                                 endm
  467. 00012                 
  468. 00013                 
  469. 00014                 sjmp            macro                   ; short jump
  470. 00015                                 ifne    @MODE&1
  471. 00016                                 bra     \1              ; on a 65c02 bra will be used
  472. 00017                                 endc
  473. 00018                                 ifeq    @MODE&1
  474. 00019                                 jmp     \1              ; on a 6502 jmp will be used
  475. 00020                                 endc
  476. 00021                                 endm
  477. 00022                 
  478. 00023                 
  479. 00024                 
  480. 00025  =c000          *               equ     $c000           ; sets the destination address
  481. 00026                 
  482. 00027  c000 a2 19                     ldx     #<string        ; set the string address
  483. 00028  c002 a0 c0                     ldy     #>string
  484. 00029  c004 86 fb                     stx     zpl
  485. 00030  c006 84 fc                     sty     zph
  486. 00031  c008 a0 00                     ldy     #0              ; reset index
  487. 00032  c00a b1 fb     loop            lda     (zpl),y         ; get a char
  488. 00033  c00c f0 0a                     beq     exit            ; NULL -> exit
  489. 00034  c00e 20 d2 ff                  jsr     chrout          ; print it
  490. 00035  c011 c8                        iny
  491. 00036  c012 d0 f6                     bne     loop
  492. 00037  c014 e6 fc                     inc     zph             ; incr. high byte of addr
  493. 00038M                                sjmp    loop            ; get next char
  494. 00038M TRUE                           ifne    @MODE&1
  495. 00038M c016 80 f2                     bra     loop            ; on a 65c02 bra will be used
  496. 00038M                                endc
  497. 00038M FALSE                          ifeq    @MODE&1
  498. 00038M                                jmp     loop            ; on a 6502 jmp will be used
  499. 00038M                                endc
  500. 00039                 
  501. 00040  c018 60        exit            rts
  502. 00041                 
  503. 00042M                string          text    'This is a test!'
  504. 00042M c019 4c 2d c0                  jmp     text0002z               ; causes a jump over the text
  505. 00042M c01c 54 68 69                  db 'This is a test!'
  506. 00042M c02b 0d 00                     db 13,0
  507. 00042M                text0002z
  508. 00043                 
  509. 00044                 
  510.  
  511.  
  512.  65c02 Cross Assembler v2.34  (c) J. & T. Marin 1988                  --  Page #    2  --
  513.  
  514.  
  515. symbol_name      value type usage           symbol_name      value type usage
  516. chrout            ffd2   e      1           exit              c018          1
  517. loop              c00a          2           string            c019          2
  518. text0002z         c02d          1           zph               00fc  ze      2
  519. zpl               00fb  ze      2           
  520.  
  521.  
  522.  
  523. The leftmost field shows the source line number.  If the line is generated
  524. by macro expansion an 'M' will be added to the line number.  Lines derived
  525. from included files are marked with 'I'.
  526.  
  527. The next field contains the destination address in hexadecimal, or the
  528. value SET or EQUated to a symbol.  If SET was used the value is preceded
  529. with a '>' and if EQU was used by a '='.
  530. If the line contained a conditional assembly directive the address field
  531. will be replaced with 'TRUE' or 'FALSE' depending on the result on the
  532. condition test.
  533.  
  534. The third field contains the first three object bytes generated from this
  535. line.
  536.  
  537. The fourth field contains the symbol name, fifth the mnemonic and sixth
  538. the operands.  The last field contains the comments.
  539.  
  540. The columns of the fields depend on the number of tabulators being used in
  541. the source file.
  542.  
  543.  
  544.  
  545. -------------------------------------------------------------------------
  546.  
  547. Known bugs:
  548.  
  549. - lda #-1-8 causes an error message although it shouldn't.
  550.  
  551. - Strange line numbers in some error messages (in errors with macros
  552.   and include files).
  553.  
  554.  
  555. -------------------------------------------------------------------------
  556.  
  557.  
  558.  
  559.  
  560. Send all flames/thanks/bug_reports/whatever to:
  561.  
  562. MAIL:    Jukka Marin
  563.     Ruskeisentie 24
  564.     70900 Toivala
  565.     FINLAND
  566.  
  567. E-MAIL:    jmarin@finkuo.bitnet
  568.  
  569.  
  570. If you like this program I would appreciate a small donation from you.
  571. You know, it takes some time to write a macro assembler...  The source
  572. code is now included with the executables.  To compile the source you
  573. need special macro libraries, however.
  574. I know the source is *terrible* and not suitable to be used as an example
  575. of assembly language programming.
  576.  
  577. Thanks!
  578.  
  579.     -jm
  580.  
  581.