home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / forthmacs / htmldocs / !Forthmacs / docs / html / armassem < prev    next >
Encoding:
Text File  |  1996-02-23  |  23.7 KB  |  618 lines

  1. <!-- Forthmacs Formatter generated HTML output -->
  2. <html>
  3. <head>
  4. <title>ARM Assembler</title>
  5. </head>
  6. <body>
  7. <h1>ARM Assembler</h1>
  8. <hr>
  9. <p>
  10. <p>
  11. <h2>Using the assembler</h2>
  12. <p>
  13. Coding in ARM assembler is very straightforward.  If you have used an ARM 
  14. Assembler before, you will already know the instructions.  Otherwise I recommend 
  15. <p>
  16. <em>Acorn Risc Machine Family Data Manual, Prentice Hall, ISBN 0-13-781618-9</em> 
  17. <p>
  18. for further information.  It tells you everything about the ARM cpu you should 
  19. know and covers the whole instruction set plus lots of hardware details.  In 
  20. fact it was my only source of information at hand when starting this 
  21. Risc-OS Forthmacs port.  
  22. <p>
  23. This documentation is by far not complete, but it covers most aspects.  If you 
  24. are writing code, just have a look at some kernel sources and see how it works.  
  25. Whenever you are not sure about the produced code, have a look at it by 
  26. <br><code>    code demo ...... c;</code><br>
  27. <br><code>    see demo</code><br>
  28. and you have the code just in front of you.  
  29. <p>
  30. Also there is a chapter "Assembler Tutorial".  
  31. <p>
  32. As most Forth assemblers are, this assembler is really just a vocabulary which 
  33. contains the words for assembling ARM code.  It is "activated" by adding the 
  34. assembler vocabulary to the search order.  There are also some common ways to 
  35. control assembly which do more than just put the assembler vocabulary in the 
  36. search order.  It also uses a <em>data first - operand last</em> syntax as Forth 
  37. generally does.  
  38. <p>
  39. Lets now have a look at some kernel source and see what the syntax looks like in 
  40. the forth assembler syntax and in the original Acorn Syntax ( displayed by the 
  41. disassembler utility).  
  42. <p>
  43. <p><pre>
  44. code count      (s adr -- adr1 cnt ) 
  45.         r0      top     mov
  46.         top     r0 byte )+ ldr
  47.         r0      sp      push c;
  48. see count
  49. code count 
  50.  (   a148 )  mov     r0,r10
  51.  (   a14c )  ldrb    r10,[r0],#1
  52.  (   a150 )  str     r0,[r13,#-4]!
  53.  (   a154 )  ldr     pc,[r8],#4
  54. </pre><p>
  55. <p>
  56. <p>
  57. <h2>General syntax</h2>
  58. <p>
  59. All instructions follow the general syntax: 
  60. <p>
  61. <p><pre>
  62.         ARM:        opcode  r-dest r-n operand
  63.         Forth:      r-dest r-nsrc operand modifiers  condition op-code
  64. </pre><p>
  65. <p>
  66. <p>
  67. The brackets and commas in the original assembler source are replaced by spaces, <em>addressing mode indicators</em> 
  68. and macros.  The 
  69. <p>
  70. ia [r0],#4 will be )+ , indicating a postincrement by 1 or 4 according to 
  71. byte/word access.  
  72. <p>
  73. push is a macro meaning 
  74. <br><code>    -( str.</code><br>
  75. <p>
  76. c; at the end assembles a next instruction 
  77. <br><code>    ldr     pc,[r8],#4</code><br>
  78. <br><code>    pc  ip )+  ldr</code><br>
  79. and quits assembling.  
  80. <p>
  81. The operands ( registers or numbers ) must appear in the correct order followed 
  82. by modifiers.  
  83. <p>
  84. <p>
  85. <h2>Conditions</h2>
  86. <p>
  87. All instructions can be conditionally executed on ARM cpus.  All condition codes 
  88. are implemented, they should be preferably written just before the opcode 
  89. itself.  You don't have to write down the <strong>al</strong> condition, it is 
  90. the default.  
  91. <p>
  92. Note: According to ARM standards, <strong>nv</strong> is  <code><A href="_smal_AM#27c"> not </A></code> 
  93. implemented and should never be used because of future instruction set 
  94. extensions.  
  95. <p>
  96. Condition codes available : <strong>eq ne cs cc mi pl vs vc hi ls ge lt gt le al</strong> 
  97. <p>
  98. <p>
  99. <h2>Shifts</h2>
  100. <p>
  101. There a numerous shifts for operators available, 
  102. <p>
  103. <strong>asl #asl lsl #lsl lsr #lsr asr #asr ror #ror rrx</strong> , 
  104. <p>
  105. all shift operator leaded by a # mean count of shift specified by a number, 
  106. otherwise by a register.  
  107. <p>
  108. This assembler is clever enough to find out shifted immediates itself, so you 
  109. don't have to worry about lines like 
  110. <br><code>    top th f0 #  td 24 #lsl mov</code><br>
  111. just write 
  112. <br><code>    top th f0000000 # mov</code><br>
  113. instead.  
  114. <p>
  115. <p>
  116. <h2>Register usage</h2>
  117. <p>
  118. Registers <strong>r0 - r6</strong> are available for use within code 
  119. definitions.  Don't try to use them for permanent storage, because they are used 
  120. by many code words with no attempt to preserve the previous contents.  
  121. <p>
  122. <br><code>    r7      floating stack pointer  fsp</code><br>
  123. <br><code>    r8      instruction pointer     ip</code><br>
  124. <br><code>    r9      user area pointer       up</code><br>
  125. <br><code>    r10     top-of-stack register   top</code><br>
  126. <br><code>    r11     return stack pointer    rp</code><br>
  127. <br><code>    r12     RiscOS frame pointer    fp never touch this</code><br>
  128. <br><code>    r13     stack pointer           sp</code><br>
  129. <br><code>    r14     link register           lk</code><br>
  130. <br><code>    r15     pc + status + flags     pc</code><br>
  131. Note: In future CPU Versions, the internal structure of the  <code><A href="_smal_BA#18"> pc </A></code> 
  132. register will be different, it seems to be better, to imagine  <code><A href="_smal_BA#18"> pc </A></code> 
  133. and status register as two registers.  The hardware-errors and the  <code><A href="_smal_AX#47"> .registers </A></code> 
  134. instruction know about this already.  
  135. <p>
  136. <p>
  137. <h2>Structured programming</h2>
  138. <p>
  139. This assembler supports structured programming not by using labels but common 
  140. forth-like structures instead.  The structures do not have to fit on one line, 
  141. and they may be nested to any level.  The range of the branches assembled by 
  142. these structures is not restricted.  
  143. <p>
  144. Implemented structures are: 
  145. <br><code>    set the flags                   \ produce the condition</code><br>
  146. <br><code>    condition if ...                \ if condition is met do this</code><br>
  147. <br><code>              else ...              \ otherwise this</code><br>
  148. <br><code>              then</code><br>
  149. <br><code>    </code><br>
  150. <br><code>    </code><br>
  151. <br><code>    </code><br>
  152. <br><code>    begin ....</code><br>
  153. <br><code>          set the flags             \ produce the condition</code><br>
  154. <br><code>    condition     while ...         \ do this when condition met</code><br>
  155. <br><code>          ( you may set the flags )</code><br>
  156. <br><code>    ( condition ) repeat            \ the repeat is normally always done</code><br>
  157. <br><code>                                    \ but you may also test for another</code><br>
  158. <br><code>                                    \ condition.</code><br>
  159. <br><code>    </code><br>
  160. <br><code>    </code><br>
  161. <br><code>    begin ...</code><br>
  162. <br><code>          set the flags             \ produce the condition</code><br>
  163. <br><code>    condition until                 \ leave the loop when condition is met</code><br>
  164. <br><code>    </code><br>
  165. <br><code>    </code><br>
  166. <br><code>    </code><br>
  167. <br><code>    begin ... again                 \ loop until whatever may happen</code><br>
  168. <p>
  169. <p>
  170. <h2>Porting</h2>
  171. <p>
  172. The ARM assembler can be used also by other Forth systems, all hardware specific 
  173. parts are written portable and can be changed in case of problems very easily.  
  174. So a 68k-Forthmacs can metacompile ARM code by this assembler without any 
  175. change.  In fact, the very first metacompilation of this Risc-OS Forthmacs took 
  176. place on an ATARI-ST having 1MB Ram and a 720k disk.  
  177. <p>
  178. <p>
  179. <h2>Byte-sex</h2>
  180. <p>
  181. Both byte-sexes can be produced by this assembler, this allows portable 
  182. assembler code for all ARM CPUs.  <strong>little-endian</strong> and <strong>big-endian</strong> 
  183. do the switch.  
  184. <p>
  185. <p>
  186. <h2>ARM2/3/6</h2>
  187. <p>
  188. The assembler takes care of some cpu dependent restrictions, <strong>arm2</strong> 
  189. disallows the more advanced instructions, <strong>arm3</strong> allows them.  
  190. <p>
  191. <p>
  192. <h2>Forth Virtual Machine Considerations</h2>
  193. <p>
  194. The Forth parameter stack is implemented with r13, but the name  <code><A href="_smal_BB#19"> sp </A></code> 
  195. should be used instead of r13, in case the virtual machine implementation should 
  196. change.  
  197. <p>
  198. The return stack is implemented with r11, and the name  <code><A href="_smal_BF#1d"> rp </A></code> 
  199. should be used to refer to it.  
  200. <p>
  201. The base address of the user area ( the user pointer) is r9 but should be 
  202. referred to as  <code><A href="_smal_BD#31b"> up </A>.</code> User variable 
  203. number 124 (for instance) may be accessed with the 
  204. <br><code>    up td 124 d)</code><br>
  205. addressing mode.  There is a macro  <code><A href="_smal_BH#1f"> 'user </A></code> 
  206. which will assemble this addressing mode for you.  
  207. <p>
  208. The interpreter pointer  <code><A href="_smal_BE#1c"> ip </A></code> is r8.  The 
  209. interpreter is post-incrementing, so when a code definition is being executed,  <code><A href="_smal_BE#1c"> ip </A></code> 
  210. points to the token after the one being executed.  A "token" is the number that 
  211. is compiled into the dictionary for each Forth word in a definitions.  For 
  212. Risc-OS Forthmacs, a token is a 32-bit absolute address.  
  213. <p>
  214. <p>
  215. <h2>Assembler Glossary </h2>
  216. <p>
  217.  
  218. <hr><h3><A name="18">pc</A> ( -- n )</h3>
  219. <br>
  220. portable name for the  <code><A href="_smal_BA#18"> pc </A></code> register 
  221.  
  222. <hr><h3><A name="19">sp</A> ( -- n )</h3>
  223. <br>
  224. portable name for the stack pointer 
  225.  
  226. <hr><h3><A name="1a">fsp</A> ( -- n )</h3>
  227. <br>
  228. portable name for the floating stack pointer 
  229.  
  230. <hr><h3><A name="1b">up</A> ( -- n )</h3>
  231. <br>
  232. portable name for the user pointer 
  233.  
  234. <hr><h3><A name="1c">ip</A> ( -- n )</h3>
  235. <br>
  236. portable name for the instruction pointer 
  237.  
  238. <hr><h3><A name="1d">rp</A> ( -- n )</h3>
  239. <br>
  240. portable name for the return stack pointer 
  241.  
  242. <hr><h3><A name="1e">top</A> ( -- n )</h3>
  243. <br>
  244. portable name for the top of stack register 
  245.  
  246. <hr><h3><A name="1f">'user</A> ( --  )</h3> <kbd>name</kbd> 
  247. <br>
  248. Executed in the form: 
  249. <br><code>         top   'user <name>   ldr</code><br>
  250. <name> is the name of a User variable.  Assembles the appropriate 
  251. addressing mode for accessing that User variable.  
  252. <p>
  253. In Risc-OS Forthmacs, the addressing mode for User variables is 
  254. <br><code>                 up #n d)</code><br>
  255. where #n is the offset of that variable within the User area.  
  256.  
  257. <hr><h3><A name="20">;code</A> ( --  )</h3>
  258.  Extra: C,I
  259. <br>
  260.  ( --  )<br>
  261. <br>
  262. Used in the form: 
  263. <br><code>                 : <name>  ... create ... ;code ... c; (or end-code)</code><br>
  264. Stops compilation, terminates the defining word <name>, executes  <code><A href="_smal_AD#153"> assembler </A>,</code> 
  265. and does  <code><A href="_smal_AW#1c6"> do-entercode </A>.</code> 
  266. <p>
  267. When <name> is later executed in the form: 
  268. <br><code>                 <name> <new-name></code><br>
  269. to define the word <new-name>, the later execution of <new-name> 
  270. will cause the machine code sequence following the  <code><A href="_smal_BN#115"> ;code </A></code> 
  271. to be executed.  
  272. This is analogous to  <code><A href="_smal_BF#1cd"> does> </A>,</code> except 
  273. that the behavior of the defined words <word-name> is specified in 
  274. assembly language instead of high-level Forth.  
  275. <p>
  276.  <code><A href="_smal_BN#115"> ;code </A></code> calls  <code><A href="_smal_AW#1c6"> do-entercode </A>,</code> 
  277. this is implementation specific and assembles the code needed to start the 
  278. assembler code with the body of the defined word in  <code><A href="_smal_BG#1e"> top </A></code> 
  279. <br><code>         top     sp      push</code><br>
  280. <br><code>         top     lk      th fc000003 # bic</code><br>
  281. <p>
  282. Note for specialists: You may do 
  283. <br><code>    ;code</code><br>
  284. <br><code>      -8 ass-allot</code><br>
  285. <br><code>      ...</code><br>
  286. and handle the link register and stack on your own which can be somewhat faster.  
  287.  
  288. See:  <code><A href="_smal_AH#187"> code </A></code>  <code><A href="_smal_BF#1cd"> does> </A></code> 
  289. <p>
  290.  
  291. <hr><h3><A name="21">adr</A> ( rx addr --  )</h3>
  292. <br>
  293. Assembler macro with the following effect: 
  294. <p>
  295. addr is moved to register rx.  Within short distances this is achieved by a  <code><A href="_smal_AM#3c"> pcr </A></code> 
  296. instruction, otherwise it's more complicated.  
  297. <p>
  298. Note: The address will be relocated correctly! 
  299.  
  300. <hr><h3><A name="22">aligning?</A> ( -- addr  )</h3>
  301. <br>
  302. variable holding flag, true means assembler does aligning on its own.  
  303. Implemented for CPU independent metacompiling.  
  304.  
  305. <hr><h3><A name="23">alu-instructions</A> ( r-dest r-op1 op2{r-op2|imm} --  )</h3>
  306. <br>
  307. Available instructions with this syntax: 
  308. <p>
  309. <strong>and eor sub rsb add adc sbc rsc tst teq cmp cmn orr bic </strong> 
  310. <p>
  311. These instructions all have two data-inputs to the alu, the register r-op1 and 
  312. the operand op2.  This can be another register or an 8-bit immediate.  
  313. <p>
  314. The register r-op2 can be "shifted" in any way specified by a shift specifier, 
  315. either a 5-bit integer or another register plus the shifted register.  The 
  316. immediate operand can be rotated right by 2*(4-bit-integer).  
  317. <p>
  318. If you give "large" literals as arguments, the assembler will generate the 
  319. correct shifts itself.  
  320. <p>
  321. The <strong>#</strong> modifier declares an immediate operand as in: \ top r0 3 
  322. # add 
  323. <p>
  324. The <strong>s</strong> modifier will set the flags according to the result, the 
  325. instruction will be <strong>adds</strong> instead of <strong>add</strong> .  
  326. <strong>mov</strong> and <strong>mvn</strong> are somewhat different, the 
  327. operand r-op1 isn't needed.  Also, both can handle "big" immediates themselves, 
  328. <br><code>         top th 12345678 # mov</code><br>
  329. won't be a problem, <strong>mov</strong> assembles all instructions needed.  
  330. <p>
  331. <strong>cmp</strong> and (Fcmn) can both handle negative immediate operandes, 
  332. they try to find out which operand is possible.  
  333. <p>
  334.  
  335. <hr><h3><A name="24">ass-allot</A> ( n --  )</h3>
  336.  Extra: deferred
  337. <br>
  338. Allocates n bytes in the dictionary.  The address of the next available 
  339. dictionary location is adjusted accordingly.  
  340. <p>
  341. default  <code><A href="_smal_BT#14b"> allot </A>,</code> implemented for ( cpu 
  342. independent ) metacompiling.  
  343.  
  344. <hr><h3><A name="25">assembler</A> ( --  )</h3>
  345. <br>
  346. Execution replaces the first vocabulary in the search order with the  <code><A href="_smal_AD#153"> assembler </A></code> 
  347. vocabulary, making all the assembler words accessible.  
  348.  
  349. <hr><h3><A name="26">big-endian</A> ( -- )</h3>
  350. <br>
  351. Switches assembler to big-endian target code 
  352.  
  353. <hr><h3><A name="27">branch</A> ( addr --  )</h3>
  354. <br>
  355. Assembles a branch instruction to here.  Can be modified by  <code><A href="_smal_BX#2f"> dolink </A></code> 
  356. and all condition codes.  
  357.  
  358. <hr><h3><A name="28">byte</A> ( -- )</h3>
  359. <br>
  360. modifier for the assembler, memory accesses mean byte wide access 
  361.  
  362. <hr><h3><A name="29">code</A> ( --  )</h3> <kbd>name</kbd> 
  363.  Extra: M
  364. <br>
  365. A defining word executed in the form: 
  366. <br><code>                 code <name> ... end-code or c;</code><br>
  367. Creates a dictionary entry for <name> to be defined by a following 
  368. sequence of assembly language words.  Words thus defined are called code 
  369. definitions or primitives.  Executes  <code><A href="_smal_AD#153"> assembler </A></code> 
  370. and sets the opcode defaults .  
  371. <p>
  372. This is the most common way to begin assembly.  
  373. <p>
  374.  
  375. See:  <code><A href="_smal_BV#1dd"> end-code </A></code>  <code><A href="_smal_BJ#171"> c; </A></code> 
  376.  
  377. <hr><h3><A name="2a">code!</A> ( n addr --  )</h3>
  378.  Extra: Deferred
  379. <br>
  380. Stores a 32-bit word into the code at addr.  
  381. <p>
  382. This word is deferred so that the metacompiler may change it to assemble code 
  383. into the target dictionary rather than the resident dictionary.  It also handles 
  384. little/big endian target code.  
  385.  
  386. <hr><h3><A name="2b">code,</A> ( n --  )</h3>
  387.  Extra: Deferred
  388. <br>
  389. Places n in the dictionary at ( assemblers )  <code><A href="_smal_AM#21c"> here </A></code> 
  390. and  <code><A href="_smal_BM#24"> ass-allot </A>s</code> enough space for a 
  391. word.  
  392. <p>
  393. This word is deferred so that the metacompiler may change it to assemble code 
  394. into the target dictionary rather than the resident dictionary.  It also handles 
  395. little/big endian target code.  
  396.  
  397. <hr><h3><A name="2c">c;</A> ( --  )</h3>
  398. <br>
  399. Terminates the current code definition and allows its name to be found in the 
  400. dictionary.  
  401. <p>
  402. Sets the  <code><A href="_smal_AU#194"> context </A></code> vocabulary to be 
  403. same as the  <code><A href="_smal_BL#1a3"> current </A></code> vocabulary (which 
  404. removes the  <code><A href="_smal_AD#153"> assembler </A></code> vocabulary from 
  405. the search order, unless you have explicitly done something funny to the search 
  406. order while assembling the code).  
  407. <p>
  408. Executes  <code><A href="_smal_AK#3a"> next </A></code> to assemble the "next" 
  409. routine at then end of the code word word being defined.  The "next" routine 
  410. causes the Forth interpreter to continue execution with the next word.  
  411. <p>
  412. <p>
  413. This is the most common way to end assembly, calls  <code><A href="_smal_BV#1dd"> end-code </A>.</code> 
  414.  
  415. <hr><h3><A name="2d">conditions</A> ( --  )</h3>
  416. <br>
  417. All instruction are executed only if the correct condition is met, the 
  418. assemblers default is <strong>al</strong> (always), but these are also 
  419. available: 
  420. <p>
  421. <strong>eq ne cs cc mi pl vs vc hi ls ge lt gt le al</strong> 
  422.  
  423. <hr><h3><A name="2e">decr</A> ( reg n# --  )</h3>
  424. <br>
  425. Macro, n# will be subtracted from reg.  
  426.  
  427. <hr><h3><A name="2f">dolink</A> ( --  )</h3>
  428. <br>
  429. modifier for  <code><A href="_smal_BB#169"> branch </A></code> instruction, the 
  430. current pc will be saved to the link register.  
  431.  
  432. <hr><h3><A name="30">end-code</A> ( --  )</h3>
  433. <br>
  434. Terminates a code definition and allows the <name> of the corresponding 
  435. code definition to be found in the dictionary.  
  436. <p>
  437. The  <code><A href="_smal_AU#194"> context </A></code> vocabulary is set to the 
  438. same as the  <code><A href="_smal_BL#1a3"> current </A></code> vocabulary (which 
  439. removes the  <code><A href="_smal_AD#153"> assembler </A></code> vocabulary from 
  440. the search order, unless you have explicitly done something funny to the search 
  441. order while assembling the code).  
  442. <p>
  443. The  <code><A href="_smal_AK#3a"> next </A></code> routine is not automatically 
  444. added to the end of the code definition.  Usually you want  <code><A href="_smal_AK#3a"> next </A></code> 
  445. to be at the end of the definition, but sometimes the last thing in the 
  446. definition is a branch to somewhere else, so the  <code><A href="_smal_AK#3a"> next </A></code> 
  447. at the end is not needed.  
  448. <p>
  449.  
  450. See:  <code><A href="_smal_BJ#171"> c; </A></code> 
  451.  
  452. <hr><h3><A name="31">entercode</A> ( --  )</h3>
  453. <br>
  454. Starts assembling after stack checking, setting the assembler defaults and 
  455. switching to  <code><A href="_smal_AD#153"> assembler </A>.</code> 
  456.  
  457. <hr><h3><A name="32">get-link</A> ( -- reg --  )</h3>
  458. <br>
  459. Assembler macro, equivalent for: 
  460. <br><code>    lk fc000003 # bic</code><br>
  461. this is useful to get the address after a branch instruction.  
  462. <br><code>    xxxxx dolink branch  ---+</code><br>
  463. <br><code>      A) data ...           |</code><br>
  464. <br><code>                            |</code><br>
  465. <br><code>                            |</code><br>
  466. <br><code>      B) top get-link  <----+</code><br>
  467. So after branching to B),  <code><A href="_smal_BG#1e"> top </A></code> will be 
  468. set to A) 
  469.  
  470. <hr><h3><A name="33">incr</A> ( reg n# --  )</h3>
  471. <br>
  472. Macro, n# will be added to reg.  
  473.  
  474. <hr><h3><A name="34">label</A> ( --  )</h3> <kbd>name</kbd> 
  475.  Extra: F83
  476. <br>
  477. A defining word used in the form: 
  478. <br><code>    label <name> ... end-code</code><br>
  479. <br><code>    label <name> ... c;</code><br>
  480. Creates a dictionary entry for <name> consisting of a following sequence 
  481. of assembly language words.  When <name> is later executed, the address of 
  482. the first word of the assembly language sequence is left on the stack.  
  483. <p>
  484.  
  485. See:  <code><A href="_smal_BV#1dd"> end-code </A></code> 
  486.  
  487. <hr><h3><A name="35">ldm</A> ( rx1 rx2 .. rxn  n#  r-adr --  )</h3>
  488. <br>
  489. Load multiple registers from the address pointed to by r-adr, an addressing 
  490. modes must be defined.  
  491. <p>
  492. The register list is given by all register names (don't name a register twice) 
  493. and the number of registers.  
  494. <br><code>     r0 r1 r2 r3 4   sp ia! ldm</code><br>
  495. This loads registers r0-r3 from the stack and sets the stack pointer to the next 
  496. stack entry.  
  497. <p>
  498.  
  499. See:  <code><A href="_smal_AG#36"> ldr </A></code>  <code><A href="_smal_AP#3f"> stm </A></code> 
  500.  
  501. <hr><h3><A name="36">ldr</A> ( r-data r-adr operand2 --  )</h3>
  502. <br>
  503. r-data is read from memory, the default is word (32-bit) wide, but the modifier  <code><A href="_smal_BQ#28"> byte </A></code> 
  504. sets this byte-wide access.  
  505. <p>
  506. The address is calculated using r-adr and the operand2.  It can be another 
  507. register (the shift specified as usual by a 5-bit literal and a shift type) or a 
  508. 12-bit immediate offset.  
  509. <p>
  510. operand2 can be added to or subtracted from r-adr according to the addressing 
  511. mode defined by two letters.  The first tells whether (i)ncreasing or 
  512. (d)decreasing should be used, the second whether the in/decreasing takes place 
  513. (b)efore or (a)fter the memory access.  A "!" at the end tells "write-back" will 
  514. take place.  So these modes are possible 
  515. <br><code>         da  ia  db  ib    \ decrease/increase after/before</code><br>
  516. <br><code>         da  ia! db! ib!   \ as above plus write-back</code><br>
  517. <p>
  518. Some macros make live a bit more easy, they are somewhat 68k alike, and must 
  519. follow a  <code><A href="_smal_BQ#28"> byte </A></code> modifier because an 
  520. offset will be calculated by the assembler itself.  
  521. <p>
  522. <br><code>    : )      0 #   ib ;</code><br>
  523. <br><code>    : )+     @increment  ia ;</code><br>
  524. <br><code>    : )-     @increment  da ;</code><br>
  525. <br><code>    : -(     @increment  db! ;</code><br>
  526. <br><code>    : +(     @increment  ib! ;</code><br>
  527. <br><code>    </code><br>
  528. <br><code>    : d)     dup abs # offset?  swap 0<  if db  else ib  then ;</code><br>
  529. <br><code>    : d)!    dup abs # offset?  swap 0<  if db! else ib! then ;</code><br>
  530. <br><code>    : push   -( str ;</code><br>
  531. <br><code>    : pop    )+ ldr ;</code><br>
  532. Examples: 
  533. <br><code>      top  r6 byte )+ ldr</code><br>
  534. <br><code>      top  up 8 d)    ldr</code><br>
  535. <p>
  536.  
  537. See:  <code><A href="_smal_AQ#40"> str </A></code> 
  538. <p>
  539.  
  540. <hr><h3><A name="37">little-endian</A> ( -- )</h3>
  541. <br>
  542. Switches assembler to little-endian target code 
  543.  
  544. <hr><h3><A name="38">mla</A> ( r-dest r-op1 r-op2 )</h3>
  545. <br>
  546. Assembles a multiply-and-accumulate instruction.  
  547.  
  548. <hr><h3><A name="39">mul</A> ( r-dest r-op1 r-op2 )</h3>
  549. <br>
  550. Assembles a multiply instruction.  
  551.  
  552. <hr><h3><A name="3a">next</A> ( --  )</h3>
  553. <br>
  554. Assembler macro which assembles the  <code><A href="_smal_AK#3a"> next </A></code> 
  555. routine, which is the Forth address interpreter.  
  556. <p>
  557. In Risc-OS Forthmacs this is one single instruction.  
  558. <br><code>         pc  ip  )+  ldr</code><br>
  559.  
  560. <hr><h3><A name="3b">nop</A> ( --  )</h3>
  561. <br>
  562. Assembler macro, equivalent to 
  563. <br><code>    r0 r0 mov</code><br>
  564.  
  565. <hr><h3><A name="3c">pcr</A> ( addr -- pc offset  )</h3>
  566. <br>
  567. Assembler macro, expects an address on the stack and calculates its address 
  568. offset from  <code><A href="_smal_BA#18"> pc </A>.</code> The addressing mode is 
  569. also set.  
  570.  
  571. <hr><h3><A name="3d">return</A> ( --  )</h3>
  572. <br>
  573. macro for 
  574. <br><code>    pc  lk  mov</code><br>
  575.  
  576. <hr><h3><A name="3e">s</A> ( --  )</h3>
  577. <br>
  578. modifier, the instruction will set the flags according to the result.  default 
  579. for tst, teq tstp teqp cmp cmn cmpp cmnp.  
  580.  
  581. <hr><h3><A name="3f">stm</A> ( rx1 rx2 .. rxn  n#  r-adr --  )</h3>
  582. <br>
  583. Store multiple registers to the address pointed to by r-adr, an addressing modes 
  584. must be defined.  
  585. <p>
  586.  
  587. See:  <code><A href="_smal_AF#35"> ldm </A></code> for more details.  
  588.  
  589. <hr><h3><A name="40">str</A> ( r-data r-adr operand2 --  )</h3>
  590. <br>
  591. r-data is stored to memory, the default is word (32-bit) wide, but the modifier  <code><A href="_smal_BQ#28"> byte </A></code> 
  592. sets this byte-wide access.  
  593. <p>
  594.  
  595. See:  <code><A href="_smal_AG#36"> ldr </A></code> 
  596.  
  597. <hr><h3><A name="41">swi</A> ( swi# --  )</h3>
  598. <br>
  599. assembles a swi instruction, the number is swi#.  
  600.  
  601. <hr><h3><A name="42">swix</A> ( swi# --  )</h3>
  602. <br>
  603. assembles a swix instruction, the number is swi#.  
  604.  
  605. <hr><h3><A name="43">swp</A> ( r-dest r-base r-source --  )</h3>
  606. <br>
  607. assembles a swp instruction if Arm3-code is allowed by <strong>arm3</strong> 
  608.  
  609. <hr><h3><A name="44">t</A> ( --  )</h3>
  610. <br>
  611. modifier, force -T pin.  
  612.  
  613. <hr><h3><A name="45">^</A> ( --  )</h3>
  614. <br>
  615. modifier, force access to user-mode registers.  
  616. </body>
  617. </html>
  618.