home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / assembler / tla / Manual < prev    next >
Encoding:
Text File  |  1993-10-11  |  24.9 KB  |  890 lines

  1.  
  2.  
  3.                          The TLA for the ARM
  4.                          -------------------
  5.  
  6.                     Last updated 12th April 1991
  7.  
  8.                             version 0.1f
  9.  
  10.                          G.F.A.@ Lancaster
  11.  
  12.                 copyright 1989--1991 G.F.A. Lancaster
  13.  
  14. Permission is granted to make and distribute verbatim copies of this
  15. manual provided the copyright notice and this permission notice are
  16. preserved on all copies.
  17.  
  18.  
  19.         COPYING POLICIES
  20.         ----------------
  21. You may copy and distribute verbatim copies of the TLA for the ARM as you
  22. receive it, in any medium, provided that you conspicuously and
  23. appropriately publish on each copy a valid copyright notice `Copyright
  24. 1989 G.F.A.@ Lancaster'' (or with whatever year is appropriate).
  25.  
  26. You may not charge a distribution fee for the physical act of transferring
  27. a copy.
  28.  
  29. You may not copy, sublicense, distribute or transfer the TLA for the ARM
  30. except as expressly provided under this license agreement.  Any attempt
  31. otherwise to copy, sublicense, distribute or transfer the TLA for the ARM
  32. is void and your rights to use the programme under this license agreement
  33. shall be automatically terminated.  However, parties who have received
  34. computer software programmes from you with this license agreement will not
  35. have their licenses terminated so long as such parties remain in full
  36. compliance.
  37.  
  38.  
  39.         NO WARRANTY
  40.         -----------
  41. BECAUSE THE TLA FOR THE ARM IS LICENSED FREE OF CHARGE, I PROVIDE
  42. ABSOLUTELY NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. 
  43. EXCEPT WHEN OTHERWISE STATED IN WRITING
  44.  
  45. G.F.A. LANCASTER AND/OR OTHER PARTIES PROVIDE THE TLA "AS IS" WITHOUT
  46. WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
  47. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  48. PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF
  49. THE SOFTWARE IS WITH YOU.  SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME
  50. THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  51.  
  52. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL G.F.A.@ LANCASTER BE
  53. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  54. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
  55. OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
  56. BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A
  57. FAILURE OF THE PROGRAMME TO OPERATE WITH ANY OTHER PROGRAMMES) THE TLA,
  58. EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR
  59. ANY CLAIM BY ANY OTHER PARTY.
  60.  
  61.         Acknowledgements
  62.         ----------------
  63. Electronic thank-you's go to the following persona:
  64.  
  65. The idea of using the TLA for the Archimedes came from Edgar Fuss who is
  66. an old UCSD Pascal fanatic just like me.
  67.  
  68. The original TLA version (for the 65000) was written by Jens-Erik Riedel.
  69.  
  70. Edgar Fuss analysed the AOF format and tried to explain it to me. He also
  71. implemented TeX on the Archimedes so I could write the manual in texinfo!
  72.  
  73. H & H supplied many tools including my Archimedes (those were the days).
  74.  
  75. Tools GmbH, Bonn. ArchiTeX and ArcMF are avaiable from TooLs GmbH,
  76. Kes-senicher Strasse 108, D-5300 Bonn 1, Germany.
  77.  
  78.  
  79. Introduction
  80. ------------
  81. Most users of the Archimedes do not require any other assembler than the
  82. BBC BASIC V assembler. But if you are using a programming language like
  83. Pascal or C, the BASIC assembler is inadequate as it is unable to
  84. generated AOF files which the linker requires. This assembler is supposed
  85. to fill that hole.
  86.  
  87. The main reason I took the time to write an assembler myself was that the
  88. price for commerial AOF generating assemblers is in my opinion far too
  89. high and I needed one to implement MF for the @Archimedes.
  90.  
  91. This assembler was modeled after the The Last Assembler (TLA) developed at
  92. the University of Waterloo. The actual implementation it is based on was
  93. the 65000 assembler by Jens-Erik Riedel for the Apple II. The basic
  94. concept behind the TLA is the use of a central machine-independent core
  95. that is common to all versions of the assembler. The central core is
  96. augmented with machine-specific code to handle the pecularities of each
  97. individual machine.
  98.  
  99. One advantage over most other macro assemblers is that the TLA is a one
  100. pass assembler. There are some restrictions due to this but assembly is
  101. faster than with a multi-pass assembler.
  102.  
  103. This manual is intended for readers familiar with the BASIC assembler or
  104. any other assembler for the Archimedes. It does not explain the ARM
  105. assembly language.
  106.  
  107. Assembler Input File Structure
  108. ------------------------------
  109. The overall structure of input files is procedure orientated. This concept
  110. is somewhat different from the structure of Unix or similar assemblers.
  111. Actual code can only be declared in a procedure block. Each procedure
  112. block shares global definitions that are given at the beginning of the
  113. input file with all other procedures. Global definitions are non-code
  114. generating operations. They define global constants, register identifiers,
  115. macros etc. Any identifier declared inside a procedure is local to that
  116. procedure except when exported.
  117.  
  118. example
  119.                 .TITLE  "TLA example file" ; define a title
  120.  
  121. sp              .EQU    R12     ; sp is R12
  122. link            .EQU    R14     ; link is R14
  123.  
  124.  
  125.                 .PROC   ernie
  126.  
  127.                 STMFD   SP!,{R0-R3,link}
  128.                 SWI     OS_WriteS
  129.                 .STRING "Hello there!"
  130.                 LDR     R0,MyString
  131.                 SWI     OS_Write0
  132.                 LDMFD   SP!,{R0-R3,PC}
  133.  
  134. MyString        .STRING "Data string"
  135.  
  136.  
  137.                 .PROC   bert
  138.  
  139.                 TEQ     R0,#0
  140.                 MOVEQS  PC,link
  141.                 LDR     R0,DataWord
  142.  
  143. DataWord        .WORD   0FFFF
  144.  
  145.  
  146.                 .END
  147.  
  148. In the above example the identifiers sp and link are global and can be
  149. used in every procedure. The identifier MyString is local to the procedure
  150. ernie} as DataWord} is to bert}. As shown in the example, all assembler
  151. directives begin with a period. This distinguishes them from other
  152. identifiers.
  153.  
  154. The main purpose of this structure is to make assembler files more similar
  155. in structure to high level languages, so that it is easier to write
  156. external procedures for these languages in assembly language.
  157.  
  158.         Syntax of Assembly Statements
  159.         -----------------------------
  160.  
  161.         Identifiers
  162.         -----------
  163. Identifiers are character strings starting with a letter. The following
  164. characters must be alphanumeric or the underline '_' or the dollar sign
  165. '$'. The maximum identifier length is 255. On encountering an undefined
  166. identifier in an expression the assembler assumes that the identifier will
  167. eventually be defined as a label, which is the most probable case. Any
  168. identifier which is not a label must be defined before it is used.
  169.  
  170.         Labels
  171.         ------
  172. Labels are identifiers that represent a position in the code that is being
  173. assembled. The numeric value is an address in the code. Only labels and
  174. comments may begin in the first column, with no preceding spaces. Labels
  175. may optionally be followed by a colon which is not part of the label
  176. identifier.
  177.  
  178.         Local Labels
  179.         ------------
  180. Local labels must have a backslash '\' as the first non-space character.
  181. This is part of the label identifier and must be used in each reference.
  182. Their purpose is to conserve symbol table space and permit the use of an
  183. identifier name twice in a procedure. They are mainly used to jump around
  184. within a small segment of code. The local labels are held in a special
  185. stack separate from other identifiers so that they can even have the same
  186. name as a normal label (with a leading backslash '\'). This stack can hold
  187. up to 50 local labels. It is flushed each time a regular label is
  188. encounter at the beginning of a line.
  189.  
  190.  
  191. CopySomething   LDR     R0,Source
  192.                 LDR     R1,Destination
  193. \CopyIt         LDR     R2,[R0],#1
  194.                 TEQ     R2,#0
  195.                 STRNE   R2,[R1],#1
  196.                 BNE     \CopyIt
  197. CopyAnother     LDR     R0,NextSource
  198.                 LDR     R1,NextDest
  199. \CopyIt         LDRB    R2,[R0],#1
  200.                 TEQ     R2,#0
  201.                 STRNEB  R2,[R1],#1
  202.                 BNE     \CopyIt
  203.  
  204. In the first loop of the example a word aligned structure is copied. The
  205. label at the beginning of the loop is a local label called CopyIt}. In the
  206. second loop a byte aligned structure is copied. The loop label has the
  207. same name as before but as a regular label occured before the local label
  208. stack was cleared and all local labels can be newly defined.
  209.  
  210.         Operators
  211.         --------
  212. The following operators can be used in expressions processed by this assembler:
  213.  
  214.   +     As a unary and binary operator.
  215.  
  216.   -     As a unary and binary operator.
  217.  
  218.   ~     As a unary operator, denotes ones complement of the following
  219.         expression.
  220.  
  221.   ^     Binary operator for exclusive or.
  222.  
  223.   *     Multiplication operator.
  224.  
  225.   /     Division (DIV).
  226.  
  227.   %     Remainder division (MOD).
  228.  
  229.   |     Bit-wise OR.
  230.  
  231.   &     Bit-wise AND.
  232.  
  233.   =     Equal comparison.
  234.  
  235.   <>    Not equal comparison.
  236.  
  237.   <<    Logical shift left.
  238.  
  239.   >>    Logical shift right.
  240.  
  241. All operators have the same precedence.
  242.  
  243.         Constants
  244.         ---------
  245. Constants are either given as a numeric constant or as a character
  246. constant. The value used in an expression is always the numeric value of
  247. the constant.
  248.  
  249.         Numeric constants
  250.         -----------------
  251. Numeric constants begin with a digit (0@dots9), the following characters
  252. can be either further digits or the letters 'A'..'F' for hexadecimal
  253. constants. The default radix is hexadecimal, but you can specify the base
  254. by placing one of the following characters at the end of the constant:
  255.  
  256.   H     For hexadecimal constants (default, e.g. 0F0H)
  257.  
  258.   .     For decimal constants (e.g. 10.)
  259.  
  260.   O     For octal constants (e.g. 756O)
  261.  
  262.   T     For binary constants (e.g. 11001T)
  263.  
  264.  
  265.         Character constants
  266.         -------------------
  267. Character constants are enclosed in single quotation marks. E.g. 'A', ';'
  268. and '['. Their numeric value is the ASCII value of the character.
  269.  
  270.         Expressions
  271.         -----------
  272. The handling of expressions is simple as opposed to high level language
  273. compilers. This may be changed in future releases. The assembler evaluates
  274. expressions from left to right, and all operators have the same
  275. precedence. Parentheses can be used to override straightforward evaluation
  276.  
  277.         3+2*5          result = 25
  278.  
  279.         3*2+5          result = 11
  280.  
  281.         3+(2*5)        result = 13
  282.  
  283.  
  284.         Expression Types
  285.         ----------------
  286. The assembler uses the following expression types: Boolean, Register,
  287. Absolute, Label.
  288.  
  289.         Boolean
  290.  
  291. Boolean expressions have either the value TRUE or FALSE. They are mainly
  292. used for conditional assembly.
  293.  
  294.         Register
  295.  
  296. Register expression specifiy an ARM register. No arithmetic is allowed in
  297. register expressions, they are used in assigments (.EQU) to define
  298. alternative names for the registers. Possible values are: R0 -- R15,
  299. PC}.
  300.  
  301.         Absolute
  302.  
  303. Absolute expressions are the most common expressions. They specify
  304. absolute numeric values. You can use absolute expressions to define
  305. immediate constants or constants in the code (.WORD). They can also be
  306. mixed with label expressions.
  307.  
  308.         Label
  309.  
  310. Label expressions are used to specify labels. Adding or subtracting
  311. absolute values from labels gives a label as result, but multiplying or
  312. other operations give an absolute value.
  313.  
  314.  
  315.                 Assembler Directives
  316.                 --------------------
  317.  
  318.         Global And Routine Directives
  319.         -----------------------------
  320. Every assembly must include at least one .PROC and one .END, even in the
  321. case of stand-alone absolute code which will not be linked.
  322.  
  323. PROC
  324. ----
  325. Identifies a procedure or that should return no value. A .PROC is
  326. terminated by the occurence of a new .PROC or .END.
  327.  
  328. FUNC
  329. ----
  330. Is equivalent to a .PROC on the @Archimedes@ as the AOF file does not
  331. distinguish functions that return values from procedures that do not.
  332.  
  333. END
  334. ---
  335. This directive is used to denote the physical end of an assembly.
  336.  
  337. ABSOLUTE
  338. --------
  339. If .ABSOLUTE is specified in an assembly file, the assembler will
  340. generated an executable absolute image, not a linkable AOF file. The
  341. directive must appear before any procedure is defined.
  342.  
  343. ENTRY
  344. -----
  345. Identifies a label which will be used as the entry point into a linked
  346. programme.
  347.  
  348.         .ENTRY Startup
  349.  
  350.         .PROC main
  351.         .EXPORT Startup
  352.  
  353. Startup .
  354.         .
  355.         .
  356.  
  357.  
  358. CODEAREA
  359. --------
  360. Begin code area (read-only part) of AOF image.
  361.  
  362. DATAAREA
  363. --------
  364. Begin data area (read-write part) of AOF image.
  365. Label Definitions And Space-Allocation Directives
  366.  
  367. EQU
  368. ---
  369. Assigns a value to an identifier. Used to assign register names, boolean
  370. flags and values to labels.
  371.  
  372. Register identifiers can only be equated to other register identifiers.
  373.  
  374. sp      .EQU R13
  375.  
  376. Boolean identifiers can only be equated to boolean values, logical
  377. expressions are currently not allowed.
  378.  
  379. Debug   .EQU TRUE
  380.  
  381. Labels may be equated to an expression containing labels and/or absolutes.
  382. One must define a label before it is used unless it will be simply equated
  383. to another label. A local label may not appear on the left-hand side of an
  384. .EQU.
  385.  
  386. label .EQU value
  387.  
  388. ORG
  389. ---
  390. Takes the operand of .ORG as the offset, relative to the start of the
  391. assembly file, where the next word or byte of code is to go. Words or
  392. bytes of zeros are produced to get the current location counter (LC) to
  393. the correct value.
  394.  
  395.         .ORG 9000
  396.  
  397. ALIGN
  398. -----
  399. .ALIGN is used to align the code location counter to a certain byte
  400. boundary. If no absolute expression follows the directive a 4 byte word
  401. boundary is used.
  402.  
  403. WORD
  404. ----
  405. Allocates a word of space in the code stream for each value in the
  406. valuelist. Associates the (optional) declaration label with the word space
  407. allocation.
  408.  
  409. Table   .WORD 0, 2, 4
  410.  
  411. BYTE
  412. ----
  413. Allocates a byte of space into the code stream for each value listed. Each
  414. value actually stored must have a value between 0 and 255. If the value is
  415. outside of this range an error will be flagged. If a label is associated
  416. with .BYTE, the address at which the byte is stored will be assigned to it
  417.  
  418. BLOCK
  419. -----
  420. Allocates a block of space into the code stream for the value listed with
  421. the given length.
  422.  
  423. Data    .BLOCK 4,6
  424.  
  425. This will allocate four bytes each with value 6. Data is a label to the
  426. start of the block. 
  427.  
  428. ASCII
  429. -----
  430. With .ASCII you can specify ASCII data which is inserted into the code. A
  431. string must follow the directive.
  432.  
  433.         .ASCII "String data"
  434.  
  435. STRING
  436. ------
  437. Does the same as .ASCII, but adds a zero byte at the end of the ASCII data
  438.  
  439. HASCII 
  440. ------
  441. Same as .ASCII but each byte allocated has the highest bit set.
  442.  
  443. HSTRING
  444. -------
  445. Same as .STRING but each byte has highest bit set.
  446.  
  447. HBYTE
  448. -----
  449. Allocates a byte of space with the high byte of the given value.
  450.  
  451.         .HYBTE 3000
  452.  
  453. This will insert the hex byte 30 in the code stream.
  454.  
  455. LBYTE
  456. ----
  457. Allocates a byte of space with the low byte of the given value.
  458.  
  459.         .LBYTE 1234
  460.  
  461. This will insert the hex byte 34 in the code stream.
  462.  
  463.  
  464.         Macro Facility Directives
  465.         -------------------------
  466. A macro is a named section of text that can be defined once and repeated
  467. in other places simply by using its name. The entire macro definition may
  468. precede the first .PROC in the assembly file.
  469.  
  470. The text of the macro may be parameterized, so that each invocation
  471. results in a different version of the macro contents. At the invocation
  472. point, the macro name can be followed by a list of parameters, each
  473. terminated by a comma (except for the last one, which is terminated by end
  474. of line or the comment character (;).
  475.  
  476. The text of the macro definition, modified by substituting the invocation
  477. parameters, is inserted by the assembler at the invocation point. Wherever
  478. %n (where n is a single decimal digit greater than zero) occurs in the
  479. macro definition, the text of the n-th invocation parameter is
  480. substituted. Leading and trailing blanks are stripped from the parameter
  481. before the substitution.
  482.  
  483. If the macro definition includes a reference to a parameter not provided
  484. in a particular invocation (too few parameters or no parameter before a
  485. terminating comma), a null string is substituted.
  486.  
  487. A macro definition may not contain another macro definition. A definition
  488. can certainly, however, include macro invocations. This ``nesting'' of
  489. macro invocations is limited to five levels deep.
  490.  
  491.         .MACRO MOVEBYTE
  492.         LDRB   %1,[%2]
  493.         STRB   %1,[%3]
  494.         .ENDM
  495.  
  496. MACRO
  497. -----
  498. Indicates the start of a macro definition and gives the macro an
  499. identifier.
  500.  
  501.         .MACRO identifier
  502.  
  503. ENDM
  504. ----
  505. Indicates the end point of a macro definition.
  506.  
  507.         Conditional Assembly Directives
  508.         -------------------------------
  509. Conditionals are used to selectively exclude or include sections of code
  510. at assembly time. When the assembler encounters a .IF directive, it
  511. evaluates the associated Boolean expression. In the simplest case, if the
  512. expression is FALSE, the assembler simply discards the text until a .ENDC
  513. is reached. If there is a .ELSE directive between the .IF and .ENDC
  514. directive, the text before the .ELSE is selected if the expression is
  515. TRUE, and the text after the .ELSE if the condition os FALSE. The
  516. unassembled part of the conditional will not be included in any listing.
  517. Conditionals may be nested.
  518.  
  519. IF
  520. --
  521. Identifies the beginning of an conditional.
  522.  
  523. ELSE
  524. ----
  525. Identifies the alternate to a .IF. If the conditional expression is FALSE
  526. then the else portion is used.
  527.  
  528. ENDC
  529. ----
  530. Identifies the end of a conditional.
  531.  
  532.  
  533.         External Communication Directives
  534.         ---------------------------------
  535. Separate routines may share data structures and subroutines by linkage
  536. from one assembly routine to another assembly routine. This is made
  537. possible through the use of .DEF and .REF. These directives cause the
  538. assembler to generate link information that allows separately assembled
  539. routines to be linked together. By using .DEF and .REF, one assembly
  540. routines may call subroutines found in another assembly routine.
  541.  
  542. The use of .REF and .DEF is not limited to subroutines and data defined in
  543. other assembly files. You can reference any symbol defined in a AOF file,
  544. e.g. a C or Pascal routine or data.
  545.  
  546. DEF
  547. ---
  548. Identifies a label that is defined in the current routine as being
  549. available for use in other AOF files.
  550.  
  551. REF
  552. ---
  553. Identifies a label used in the curremt routine which refers to a symbol
  554. declared in an other AOF file.
  555.  
  556. EXPORT
  557. ------
  558. Is equivalent to .DEF.
  559.  
  560. IMPORT
  561. ------
  562. Is equivalent to .REF.
  563.  
  564.  
  565.         Listing Control Directives
  566.         --------------------------
  567. LIST
  568. ----
  569. Enable or disable listing. Listing can be toggled anywhere in an assembly.
  570.  
  571. PAGE 
  572. ----
  573. Output a form feed onto the list file.
  574.  
  575. TITLE
  576. -----
  577. Set a title for the normal pages of a listing.
  578.  
  579.         .TITLE "P-Code Interpreter 1.1a"
  580.  
  581. GTITLE
  582. ------
  583. Set a global title for the pages of a listing. This title will always
  584. appear.
  585.  
  586.         .TITLE "This file is (C) Arthur Dent 1990."
  587.  
  588. CONDLIST
  589. --------
  590. Enable or disable conditional listing.
  591.  
  592.         .CONDLIST OFF
  593.  
  594. MACROLIST
  595. ---------
  596. Enable or disable macro expansion listing.
  597.  
  598. PATCHLIST
  599. ---------
  600. Enable or disable backpatch listing.
  601.  
  602. NOLIST
  603. ------
  604. Disable listing.
  605.  
  606. NOMACROLIST
  607. -----------
  608. Disable macro expansion listing.
  609.  
  610. NOPATCHLIST
  611. -----------
  612. Disable backpatch listing.
  613.  
  614.  
  615.         File Directives
  616.         ---------------
  617.  
  618. INCLUDE
  619. -------
  620. Include the specified file into assembly. Nesting is allowed.
  621.  
  622.         .INCLUDE "s.RegDefs"
  623.  
  624. This will include the file @file{s.RegDefs.
  625.  
  626.  
  627.         Configuration Directives
  628.         ------------------------
  629. PAGING
  630. ------
  631. Turn paging on list file ON or OFF. With no parameter .PAGING defaults to ON
  632.  
  633.         .PAGING OFF
  634.  
  635. PAGESIZE
  636. --------
  637. Specify size of page as number of lines on a page.
  638.  
  639.         .PAGESIZE 50.
  640.  
  641. CASESENSE
  642. ---------
  643. Enable case-sensitive or case-insensitive mode.
  644.  
  645. SYMBOLTABLEDUMP
  646. ---------------
  647. Enable or disable symbol table dump at end of assembly. Default is ON.
  648.  
  649. SIGNEDARITHMETIC
  650. ----------------
  651. Enable or disable signed arithmetic.
  652.  
  653.  
  654.         Obscure Directives
  655.         ------------------
  656. These are special hacks and can only be used by TLA wizards.
  657.  
  658. ASECT
  659. PSECT
  660. PORG
  661. ERROR
  662.  
  663.  
  664.         Command Line Arguments
  665.         ----------------------
  666. The TLA is executed from the command line, it can take the following form:
  667.  
  668.         tla [-bchvVw] [-l list] input [output]
  669.  
  670. The input file is searched for with the directory prefix @file{s.. If no
  671. output file is specified the default @file{o.input is used. Otherwise the
  672. file name as specified.
  673.  
  674. Command Line Options
  675.   -b    Enable batchmode. Execution will not stop when an error is flagged.
  676.  
  677.   -c    Parsing will be case-insensitive.
  678.  
  679.   -h    Display command line usage.
  680.  
  681.   -l list    Generate a listing in file list.
  682.  
  683.   -v    Display version number at beginning of assembly.
  684.  
  685.   -V    Enable verbose mode. Output on VDU is like original TLA.
  686.  
  687.  
  688.         Syntax Error File
  689.         -----------------
  690. The syntax error messages used by the TLA are kept in the file TLA_Errors.
  691. This file is searched for with the path variable TLA$Path and with the
  692. default system variable File$Path.
  693.  
  694.         Assembly Examples
  695.         -----------------
  696.  
  697. A filetype set routine:
  698.  
  699. SP      .EQU    R13
  700.  
  701.         .PROC   SetFileType
  702.  
  703.         STMFD   SP!,{R0,R1,R2,R14}
  704.         MOV     R2,R1
  705.         MOV     R1,R0
  706.         MOV     R0,#18.
  707.         SWI     XOS_File
  708.         LDMFD   SP!,{R0,R1,R2,PC}^
  709.  
  710.         .END
  711.  
  712. The code fetch macro of my Infocom Adventure Z-Code interpreter
  713. (a parameterless macro).
  714.  
  715.         .MACRO  ZIPFETCH
  716.         LDRB    OpCode,[IPC],#1
  717.         .IF     Statistics
  718.         BL      CountStatistics
  719.         .ENDC
  720.         .IF     Debug
  721.         BL      DebugCode
  722.         .ENDC
  723.         LDR     PC,[PtrJmpTable,OpCode,LSL #2]
  724.         .ENDM
  725.  
  726. Macros for VIDC programming:
  727.  
  728.         .MACRO  VIDC
  729.         .WORD   (%1 << 24.) | (%2 << 14.)
  730.         .ENDM
  731.  
  732.         .MACRO  VIDC1
  733.         VIDC    %1,(%2-1)
  734.         .ENDM
  735.  
  736.         .MACRO  VIDC2
  737.         VIDC    %1,((%2-%3)/2)
  738.         .ENDM
  739.  
  740.         .MACRO  ModeVIDC
  741. ; %1 = XRes,           %2 = YRes
  742. ; %3 = HorBorderStart, %4 = HorBorderWidth
  743. ; %5 = VerBorderStart, %6 = VerBorderWidth
  744. ; %7 = HorSyncWidth,   %8 = VerSyncWidth
  745. ; %9 = Adjust
  746.         VIDC2   HorCycle,%1+%3+(2*%4)+1,2
  747.         VIDC2   HorSyncWidth,%7,2
  748.         VIDC2   HorBorderStart,%3,1
  749.         VIDC2   HorDisplayStart,%3+%4,%9
  750.         VIDC2   HorDisplayEnd,%1+%3+%4,%9
  751.         VIDC2   HorBorderEnd,%1+%3+(2*%4),1
  752.         VIDC1   VerCycle,%2+%5+(2*%6)
  753.         VIDC1   VerSyncWidth,%8
  754.         VIDC1   VerBorderStart,%5
  755.         VIDC1   VerDisplayStart,%5+%6
  756.         VIDC1   VerDisplayEnd,%2+%5+%6
  757.         VIDC1   VerBorderEnd,%2+%5+(2*%6)
  758.         .WORD   -1
  759.         .ENDM
  760.  
  761. Mode20VIDC
  762.         .WORD   0
  763.         .WORD   20.
  764.          ModeVIDC 640., 512., 131., 4, 18., 2, 36., 1, 7
  765.  
  766.         .END
  767.  
  768.  
  769.         Referencing external variables in assembler
  770.         -------------------------------------------
  771.  
  772. C-Programme:
  773.  
  774. int LittleInt;
  775. char BeautifulChars[20];
  776.  
  777. int main(void) {
  778.   AssProc();
  779.   ...
  780. }
  781.  
  782. Assembler Prcoedure:
  783.  
  784.         .PROC AssProc
  785.  
  786.         .IMPORT LittleInt
  787.         .IMPORT BeautifulChars
  788.  
  789.         LDR     R1, IntAdrs
  790.         MOV     R0, #0
  791.         STR     R0, [R1]       ; set LittleInt to 0
  792.         LDR     R2, ChsAdrs
  793.         STRB    R0, [R2]       ; set BeautifulChars to ""
  794.         MOVS    PC, R14
  795.  
  796. IntAdrs .WORD   LittleInt
  797. ChsAdrs .WORD   BeautifulChars
  798.  
  799.         .END
  800.  
  801.  
  802.                 Assembler Directive Summary
  803.                 ---------------------------
  804.  
  805.         Global And Routine Directives
  806.         -----------------------------
  807.  
  808.         .PROC procedure-name
  809.         .FUNC function-name
  810.         .END
  811.         .ABSOLUTE
  812.         .ENTRY label
  813.         .CODEAREA area-name
  814.         .DATAAREA data-name
  815.  
  816.         Label Definitions And Space-Allocation Directives
  817.         -------------------------------------------------
  818.  
  819. label   .EQU     value
  820.         .ALIGN   [alignment]
  821. [label]  .WORD    [valuelist]
  822. [label]  .BYTE    [valuelist]
  823. [label]  .BLOCK   count[,value]
  824. [label]  .ASCII   string
  825. [label]  .STRING  string
  826. [label]  .HASCII  string
  827. [label]  .HSTRING string
  828. [label]  .HBYTE   value
  829. [label]  .LBYTE   value
  830. @end example
  831.  
  832.         Macro Facility Directives
  833.         -------------------------
  834.  
  835.         .MACRO   macro-name
  836.         .ENDM
  837.  
  838.         Conditional Assembly Directives
  839.         -------------------------------
  840.  
  841.         .IF      logical-expression
  842.         .ELSE
  843.         .ENDC
  844.  
  845.         External Communciation Directives
  846.         ---------------------------------
  847.  
  848.         .DEF     label
  849.         .REF     label
  850.         .EXPORT  label
  851.         .IMPORT  label
  852.  
  853.         Listing Control Directives
  854.         --------------------------
  855.  
  856.         .LIST    boolean
  857.         .PAGE
  858.         .TITLE   string
  859.         .GTITLE  string
  860.         .CONDLIST [boolean[,boolean]]
  861.         .MACROLIST [boolean]
  862.         .PATCHLIST [boolean]
  863.         .NOLIST
  864.         .NOMACROLIST
  865.         .NOPATCHLIST
  866.  
  867.         Listing Control Directives
  868.         --------------------------
  869.  
  870.         .INCLUDE string
  871.  
  872.  
  873.         Configuration Directives
  874.         ------------------------
  875.  
  876.         .PAGING  [boolean]
  877.         .PAGESIZE value
  878.         .CASESENSE [boolean]
  879.         .SYMBOLTABLE [boolean]
  880.         .SIGNEDARITHMETIC [boolean]
  881.  
  882.         Obscure Directives
  883.         ------------------
  884.  
  885.         .ASECT
  886.         .PSECT
  887.         .PORG    value
  888.         .ERROR
  889.  
  890.