home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 1 / AU_CD1.iso / internet / webster / ARMinstrs
Text File  |  1995-02-28  |  46KB  |  1,283 lines

  1. <HTML>
  2. <HEAD>
  3. <TITLE>ARM Instruction Formats and Timings</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <H1>ARM Instruction Formats and Timings</H1>
  7. <P>
  8. <H3>
  9. Last revised: 31st January 1995
  10. </H3>
  11. <P>
  12. The information included here is provided in good faith, but no
  13. responsibility can be accepted for any damage or loss caused from the
  14. use of information contained within this document even if the author
  15. has been advised of the possibility of such loss.
  16. <P>
  17. This is not an official document from ARM Ltd; in fact other than a
  18. couple of nice people from ARM limited pointing out some of the
  19. corrections, they have no connection with this document at all. They
  20. do not guarantee to have found all the mistakes in this, so don't
  21. blame them when you find some more.
  22. <P>
  23. Corrections/amendments for this document would be most welcome.
  24. <P>
  25. Throughout this document, a `word' refers to 32 bits (thats 4 bytes)
  26. of memory. If you don't like this, tough.
  27. <P>
  28. This document is available in several forms.
  29. <A HREF="http://www.comlab.ox.ac.uk/oucl/users/robin.watts/ARMinstrs/">The index describes them fully.</A>
  30. <P>
  31. <HR><A NAME="Contents"><H2>
  32. Contents
  33. </H2></A>
  34. <P>
  35. <UL>
  36. <LI> <A HREF="#Modes">Processor Modes</A>
  37. <LI> <A HREF="#Registers">Registers</A>
  38. <LI> <A HREF="#Pipeline">Pipeline</A>
  39. <LI> <A HREF="#Timings">Timings</A>
  40. <LI> <A HREF="#Instructions">Instructions</A>
  41. <UL>
  42. <LI> <A HREF="#Condition">Condition Code</A>
  43. <LI> <A HREF="#Data">Data Processing Instructions</A>
  44. <LI> <A HREF="#Branch">Branch Instructions</A>
  45. <LI> <A HREF="#Multiplication">Multiplication</A>
  46. <LI> <A HREF="#Long">Long Multiplication (ARM7DM)</A>
  47. <LI> <A HREF="#Transfer">Single Data Transfer</A>
  48. <LI> <A HREF="#Block">Block Data Transfer</A>
  49. <LI> <A HREF="#Software">Software interrupt</A>
  50. <LI> <A HREF="#CoproOp">Co-processor data operations</A>
  51. <LI> <A HREF="#CoproTrans">Co-processor data transfer and register transfers</A>
  52. <LI> <A HREF="#Swap">Single Data Swap (ARM 3 and later including ARM 2aS)</A>
  53. <LI> <A HREF="#Status">Status Register transfer (ARM 6 and later)</A>
  54. <LI> <A HREF="#Undefined">Undefined instructions</A>
  55. </UL>
  56. <LI> <A HREF="#Credits">Credits</A>
  57. </UL>
  58. <P>
  59. <HR><A NAME="Modes"><H2>
  60. Processor Modes
  61. </H2></A>
  62. <P>
  63. ARM processors have a user mode and a number of privileged supervisor modes.
  64. These are used as follows:
  65. <DL>
  66. <DT> IRQ
  67. <DD>Entered when an Interrupt Request (IRQ) is triggered.
  68. <DT> FIQ
  69. <DD>Entered when a Fast Interrupt Request (FIQ) is triggered.
  70. <DT> SVC
  71. <DD>Entered when a Software Interrupt (SWI) is executed.
  72. <DT> Undef
  73. <DD>Entered when an Undefined instruction is executed (Not ARM 2 and
  74. 3, where SVC mode is entered).
  75. <DT> Abt
  76. <DD>Entered when a memory access attempt is aborted by the memory manager
  77. (e.g. MEMC or MMU), usually because an attempt is made to access
  78. non-existent memory or to access memory from an insufficiently privileged
  79. mode (Not ARM 2 and 3, where SVC mode is entered).
  80. </DL>
  81. <P>
  82. In each case the appropriate hardware vector is also called.
  83. <P>
  84. <HR><A NAME="Registers"><H2>
  85. Registers
  86. </H2></A>
  87. <P>
  88. The ARM 2 and 3 have 27 32 bit processor registers, 16 of which are visible
  89. at any given time (which sixteen varies according to the processor mode).
  90. These are referred to as R0-R15.
  91. <P>
  92. The ARM 6 and later have 31 32 bit processor registers, again 16 of which
  93. are visible at any given time.
  94. <P>
  95. R15 has special significance. On the ARM 2 and 3, 24 bits are used as the
  96. program counter, and the remaining 8 bits are used to hold processor mode,
  97. status flags and interrupt modes. R15 is therefore often referred to as PC.
  98. <PRE>
  99.         R15 = PC = NZCVIFpp pppppppp pppppppp ppppMM
  100. </PRE>
  101. Bits 0-1 and 26-31 are known as the PSR (processor status
  102. register). Bits 2-25 give the address (in words) of the instruction
  103. currently being fetched into the execution pipeline (see below). Thus
  104. instructions are only ever executed from word aligned addresses.
  105. <! center BOXED ;
  106. l VLINE l. ><PRE>
  107. M    Current processor mode
  108.  
  109. 0    User Mode
  110. 1    Fast interrupt processing mode (FIQ mode)
  111. 2    Interrupt processing mode (IRQ mode)
  112. 3    Supervisor mode (SVC mode)
  113. </PRE>
  114. <! center BOXED ;
  115. l l. ><PRE>
  116. Name    Meaning
  117.  
  118. N    Negative flag
  119. Z    Zero flag
  120. C    Carry flag
  121. V    oVerflow flag
  122. I    Interrupt request disable
  123. F    Fast interrupt request disable
  124. </PRE>
  125. <P>
  126. R14, R14_FIQ, R14_IRQ, and R14_SVC are sometimes known as `link'
  127. registers due to their behaviour during the branch with link
  128. instructions.
  129. <P>
  130. The ARM 6 and later processor cores support a 32 bit address space. Such
  131. processors can operate in both 26 bit and 32 bit PC modes. In 26 bit PC
  132. mode, R15 acts as on previous processors, and hence code can only be run in
  133. the lowest 64MBytes of the address space. In 32 bit PC mode, all 32 bits of
  134. R15 are used as the program counter. Separate status registers are used to
  135. store the processor mode and status flags. These are defined as follows:
  136. <PRE>
  137.         NZCVxxxx xxxxxxxx xxxxxxxx IFxMMMMM
  138. </PRE>
  139. Note that the bottom two bits of R15 are always zero in 32-bit modes -
  140. i.e. you can still only get word-aligned instructions. Any attempts to
  141. write non-zeros to these bits will be ignored.
  142. <P>
  143. The following modes are currently defined:
  144. <! center BOXED ;
  145. l VLINE c VLINE l. ><PRE>
  146.   M    Name    Meaning
  147.  
  148. 00000    usr_26    26 bit PC User Mode
  149. 00001    fiq_26    26 bit PC FIQ Mode
  150. 00010    irq_26    26 bit PC IRQ Mode
  151. 00011    svc_26    26 bit PC SVC Mode
  152.  
  153. 10000    usr_32    32 bit PC User Mode
  154. 10001    fiq_32    32 bit PC FIQ Mode
  155. 10010    irq_32    32 bit PC IRQ Mode
  156. 10011    svc_32    32 bit PC SVC Mode
  157. 10111    abt_32    32 bit PC Abt Mode
  158. 11011    und_32    32 bit PC Und Mode
  159. </PRE>
  160. <P>
  161. Extrapolating from the above table, it might be expected that the
  162. following two modes are also defined:
  163. <! center BOXED ;
  164. l VLINE c VLINE l. ><PRE>
  165.   M    Name    Meaning
  166.  
  167. 00111    abt_26    26 bit PC Abt Mode
  168. 01011    und_26    26 bit PC Und Mode
  169. </PRE>
  170. These are in fact undefined (and if you <B>do</B> write 00111 or 01011 to
  171. the mode bits, the resulting chip state won't be what you might expect
  172. - i.e. it won't be a 26-bit privileged mode with the appropriate R13
  173. and R14 swapped in).
  174. <P>
  175. The following table shows which registers are available in which
  176. processor modes:
  177. <PRE>
  178.         +------+---------------------------------------+
  179.         | Mode |  Registers available                  |
  180.         +------+---------------------------------------+
  181.         | USR  | R0             -             R14  R15 |
  182.         +------+---------+-----------------------------+
  183.         | FIQ  | R0 - R7 | R8_FIQ    -    R14_FIQ  R15 |
  184.         +------+---------+----+------------------------+
  185.         | IRQ  | R0   -   R12 | R13_IRQ - R14_IRQ  R15 |
  186.         +------+--------------+------------------------+
  187.         | SVC  | R0   -   R12 | R13_SVC - R14_SVC  R15 |
  188.         +------+--------------+------------------------+
  189.         | ABT  | R0   -   R12 | R13_ABT - R14_ABT  R15 | (ARM 6 and later only)
  190.         +------+--------------+------------------------+
  191.         | UND  | R0   -   R12 | R13_UND - R14_UND  R15 | (ARM 6 and later only)
  192.         +------+---------------------------------------+
  193. </PRE>
  194. <P>
  195. There are six status registers on the ARM6 and later processors. One is
  196. the current processor status register (CPSR) and holds information about
  197. the current state of the processor. The other five are the saved processor
  198. status registers (SPSRs): there is one of these for each privileged mode,
  199. to hold information about the state the processor must be returned to when
  200. exception handling in that mode is complete.
  201. <P>
  202. These registers are set and read using the MSR and MRS instructions
  203. respectively.
  204. <P>
  205. <HR><A NAME="Pipeline"><H2>
  206. Pipeline
  207. </H2></A>
  208. <P>
  209. Rather than being a microcoded processor, the ARM is (in keeping with
  210. its RISCness) entirely hardwired.
  211. <P>
  212. To speed execution the ARM 2 and 3 have 3 stage pipelines. The first
  213. stage holds the instruction being fetched from memory. The second
  214. starts the decoding, and the third is where it is actually
  215. executed. Due to this, the program counter is always 2 instructions
  216. beyond the currently executing instruction. (This must be taken
  217. account of when calculating offsets for branch instructions).
  218. <P>
  219. Because of this pipeline, 2 instruction cycles are lost on a branch
  220. (as the pipeline must refill). It is therefore often preferable to
  221. make use of conditional instructions to avoid wasting cycles. For
  222. example:
  223. <PRE>
  224.  
  225.     ...
  226.     CMP R0,#0
  227.     BEQ over
  228.     MOV R1,#1
  229.     MOV R2,#2
  230. over
  231.     ...
  232.  
  233. </PRE>
  234. can be more efficiently written as:
  235. <PRE>
  236.  
  237.     ...
  238.     CMP R0,#0
  239.     MOVNE R1,#1
  240.     MOVNE R2,#2
  241.     ...
  242. </PRE>
  243. <P>
  244. <HR><A NAME="Timings"><H2>
  245. Timings
  246. </H2></A>
  247. <P>
  248. ARM instructions are timed in a mixture of S, N, I and C cycles.
  249. <P>
  250. An S-cycle is a cycle in which the ARM accesses a sequential memory
  251. location.
  252. <P>
  253. An N-cycle is a cycle in which the ARM accesses a non-sequential memory
  254. location.
  255. <P>
  256. An I-cycle is a cycle in which the ARM doesn't try to access a memory
  257. location or to transfer a word to or from a coprocessor.
  258. <P>
  259. A C-cycle is a cycle in which a word is transferred between the ARM and a
  260. coprocessor on either the data bus (for uncached ARMs) or the coprocessor
  261. bus (for cached ARMs).
  262. <P>
  263. The different types of cycle must all be at least as long as the ARM's
  264. clock rating. The memory system can stretch them: with a typical DRAM
  265. system, this results in:
  266. <UL>
  267. <LI>
  268. N-cycles being twice the minimum length (essentially because
  269. DRAMs require a longer access protocol when the memory access
  270. is non-sequential).
  271. <LI>
  272. S-cycles usually being the minimum length, but occasionally
  273. being stretched to N-cycle length (when you've just moved
  274. sequentially from the last word of one memory "row" to the
  275. first of the next one<A HREF="#Footnote1">[1]</A>).
  276. <LI>
  277. I- and C-cycles always being the minimum length.
  278. </UL>
  279. <P>
  280. With a typical SRAM system, all four types of cycle are typically the
  281. minimum length.
  282. <P>
  283. On the 8MHz ARM2 used in the Acorn Archimedes A440/1, an S
  284. (sequential) cycle is 125ns and an N (non-sequential) cycle is
  285. 250ns. It should be noted that these timings are <B>not</B> attributes of
  286. the ARM, but of the memory system. E.g. an 8MHz ARM2 can be connected
  287. to a static RAM system which gives a 125ns N cycle. The fact that the
  288. processor is rated at 8MHz simply means that it isn't guaranteed to
  289. work if you make any of the types of cycle shorter than 125ns in
  290. length.
  291. <P>
  292. Cached processors: All the information given is in terms of the clock
  293. cycles seen by the ARM. These do not occur at a constant rate: the
  294. cache control logic changes the source of the clock cycles presented
  295. to the ARM when cache misses occur.
  296. <P>
  297. Generally, a cached ARM has two clock inputs: the "fast clock" FCLK
  298. and the "memory clock" MCLK. When operating normally from cache, the
  299. ARM is clocked at FCLK speed and all types of cycle are the minimum
  300. length: cache is effectively a type of SRAM from this point of
  301. view. When a cache miss occurs, the ARM's clock is synchronised to
  302. MCLK, then the cache line fill takes place at MCLK speed (taking
  303. either N+3S or N+7S depending on the length of cache lines in the
  304. processor involved), then the ARM's clock is resynchronised back to
  305. FCLK.
  306. <P>
  307. While the memory access is taking place, the ARM is being clocked:
  308. however, an input called NWAIT is used to cause the ARM cycles
  309. involved not to do anything until the correct word arrives from
  310. memory, and usually not to do anything while the remaining words
  311. arrive (to avoid getting further memory requests while the cache is
  312. still busy with the cache line refill). The situation is also
  313. complicated by the fact that the cached ARM can be configured either
  314. for FCLK and MCLK to be synchronous to each other (so FCLK is an exact
  315. multiple of MCLK, and every MCLK clock cycle starts at just about the
  316. same time as an FCLK cycle) or asynchronous (in which case FCLK and
  317. MCLK cycles can have any relationship to each other).
  318. <P>
  319. All in all, the situation is therefore quite complicated. An approximation
  320. to the behaviour is that when a cache line miss occurs, the cycle involved
  321. takes the cache line refill time (i.e. N+3S or N+7S) in MCLK cycles, with
  322. N-cycles and S-cycles probably being stretched as described above for DRAM,
  323. plus a few more cycles to allow for the resynchronisation periods. For any
  324. more details, you really need to get a datasheet for the processor involved.
  325. <P>
  326. <A NAME="Footnote1">Footnote 1:</A> Memory controllers tend to use this simple strategy: if an N-cycle is requested, treat the access as not being in the same row; if an S-cycle is requested, treat the access as being in the same row unless it is effectively the last word in the row (which can be detected quickly). The net result is that <B>some</B> S-cycles will last the same time as an N-cycle; if I remember correctly, on an Archimedes these are S-cycle accesses to an address which is divisible by 16. The practical consequences of this for Archimedes code are: (a) that about 1 in 4 S-cycles becomes an N-cycle, since for this purpose, all addresses are word addresses and so divisible by 4; (b) that it is occasionally worth taking care to align code carefully to avoid this effect and get some extra performance.)
  327. <P>
  328. <HR><A NAME="Instructions"><H2>
  329. Instructions
  330. </H2></A>
  331. <P>
  332. Each ARM instruction is 32 bits wide, and are explained in more detail
  333. below. For each instruction class we give the instruction bitmap, and
  334. an example of the syntax used by a typical assembler.
  335. <P>
  336. It should of course be noted that the mnemonic syntax is not fixed; it
  337. is a property of the assembler, not the ARM machine code.
  338. <P>
  339. <A NAME="Condition"><H3>
  340. Condition Code
  341. </H3></A>
  342. <P>
  343. The top nibble of every instruction is a condition code, so every
  344. single ARM instruction can be run conditionally.
  345. <P>
  346. <PRE>
  347.                                     Cond
  348. Instruction Bitmap                  No   Cond Code            Executes if:
  349.  
  350. 0000xxxx xxxxxxxx xxxxxxxx xxxxxxxx 0    EQ(Equal)          Z
  351. 0001xxxx xxxxxxxx xxxxxxxx xxxxxxxx 1    NE(Not Equal)          ~Z
  352. 0010xxxx xxxxxxxx xxxxxxxx xxxxxxxx 2    CS(Carry Set)          C
  353. 0011xxxx xxxxxxxx xxxxxxxx xxxxxxxx 3    CC(Carry Clear)      ~C
  354.  
  355. 0100xxxx xxxxxxxx xxxxxxxx xxxxxxxx 4    MI(MInus)            N
  356. 0101xxxx xxxxxxxx xxxxxxxx xxxxxxxx 5    PL(PLus)             ~N
  357. 0110xxxx xxxxxxxx xxxxxxxx xxxxxxxx 6    VS(oVerflow Set)     V
  358. 0111xxxx xxxxxxxx xxxxxxxx xxxxxxxx 7    VC(oVerflow Clear)   ~V
  359.  
  360. 1000xxxx xxxxxxxx xxxxxxxx xxxxxxxx 8    HI(HIgher)           C and ~Z
  361. 1001xxxx xxxxxxxx xxxxxxxx xxxxxxxx 9    LS(Lower or Same)    ~C and  Z
  362. 1010xxxx xxxxxxxx xxxxxxxx xxxxxxxx A    GE(Greater or equal) N =  V
  363. 1011xxxx xxxxxxxx xxxxxxxx xxxxxxxx B    LT(Less Than)          N = ~V
  364.  
  365. 1100xxxx xxxxxxxx xxxxxxxx xxxxxxxx C    GT(Greater Than)     (N =  V) and ~Z
  366. 1101xxxx xxxxxxxx xxxxxxxx xxxxxxxx D    LE(Less or equal)    (N = ~V) or   Z
  367. 1110xxxx xxxxxxxx xxxxxxxx xxxxxxxx E    AL(Always)          True
  368. 1111xxxx xxxxxxxx xxxxxxxx xxxxxxxx F    NV(Never)          False
  369. </PRE>
  370. <P>
  371. In most assemblers, the condition code is inserted immediately after
  372. the mnemonic stub; omitting a condition code defaults to AL being
  373. used.
  374. <P>
  375. HS (Higher or Same) and LO (LOwer) can be used as synonyms for CS and
  376. CC (respectively) in some assemblers.
  377. <P>
  378. The conditions GT, GE, LT, LE refer to signed comparisons whereas HS,
  379. HI, LS, LO refer to unsigned.
  380. <P>
  381. EORing a condition code with 1 gives the opposite condition code.
  382. <P>
  383. NB: ARM have deprecated the use of the NV condition code - you are now
  384. supposed to use MOV R0,R0 as a noop rather than MOVNV R0,R0 as was
  385. previously recommended. Future processors may have the NV condition
  386. code reused to do other things.
  387. <P>
  388. Instructions with false conditions execute in 1S cycle, and no time
  389. penalty is incurred by making an instruction conditional.
  390. <P>
  391. <A NAME="Data"><H3>
  392. Data Processing Instructions
  393. </H3></A>
  394. <P>
  395. <PRE>
  396. xxxx000a aaaSnnnn ddddcccc ctttmmmm  Register form
  397. xxxx001a aaaSnnnn ddddrrrr bbbbbbbb  Immediate form
  398. </PRE>
  399. <P>
  400. Typical Assembler Syntax:
  401. <PRE>
  402.  
  403.         MOV    Rd, #0
  404.         ADDEQS Rd, Rn, Rm, ASL Rc
  405.         ANDEQ  Rd, Rn, Rm
  406.         TEQP   Pn, #&80000000
  407.         CMP    Rn, Rm
  408. </PRE>
  409. <P>
  410. Combine contents of Rn with Op2, under operation a, placing the
  411. results in Rd.
  412. <P>
  413. If the register form is used, then Op2 is set to be the contents of Rm
  414. shifted according to t as below.  If the immediate form is used, then
  415. Op2 = #b, ROR #2r.
  416. <! center BOXED ;
  417. c l s l
  418. c l l l. ><PRE>
  419.  t    Assembler           Interpretation
  420.  
  421. 000    LSL #c                Logical Shift Left
  422. 001    LSL Rc                 Logical Shift Left
  423. 010    LSR #c    for c != 0    Logical Shift Right
  424.     LSR #32    for c  = 0
  425. 011    LSR Rc                 Logical Shift Right
  426. 100    ASR #c    for c != 0     Arithmetic Shift Right
  427.     ASR #32    for c  = 0
  428. 101    ASR Rc                 Arithmetic Shift Right
  429. 110    ROR #c    for c != 0     Rotate Right.
  430.     RRX    for c  = 0     Rotate Right one bit with extend.
  431. 111    ROR Rc                 Rotate Right
  432. </PRE>
  433. <P>
  434. In the register form, Rc is signified by bits 8-11; bit 7 must be
  435. clear if Rc is used. (If you code a 1 instead, you'll get a multiply,
  436. a SWP or something unallocated instead of a data processing
  437. instruction.)
  438. <P>
  439. Also, only the bottom byte of Rc is used - If Rc = 256, then the
  440. shifts will be by zero.
  441. <P>
  442. "MOV[S] Ra,Rb,RLX" can be done by ADC[S] Ra,Rb,Rb, with RLX meaning
  443. Rotate Left one bit with extend.
  444. <P>
  445. Most assemblers allow ASL to be used as a synonym for LSL. Since
  446. opinions differ on what an arithmetic left shift is, LSL is the
  447. preferred term.
  448. <P>
  449. By setting the S bit in a MOV, MVN or logical instruction, (in either
  450. the register or immediate form) the carry flag is set to be the last
  451. bit shifted out.
  452. <P>
  453. If no shift is done, the carry flag will be unaffected.
  454. <P>
  455. If there is a choice of forms for an immediate (e.g. #1 could be
  456. represented as 1 ROR #0, 4 ROR #2, 16 ROR #4 or 64 ROR #6), the
  457. assembler is expected to use the one involving a zero rotation, if
  458. available. So MOVS Rn,#const will leave the carry flag unaffected if
  459. 0 <= const <= 255, but will change it otherwise.
  460. <P>
  461. <! center BOXED ;
  462. c l l l. ><PRE>
  463. aaaa    Assembler    Meaning             P-Code
  464.  
  465. 0000    AND         Boolean And         Rd = Rn AND Op2
  466. 0001    EOR         Boolean Eor         Rd = Rn EOR Op2
  467. 0010    SUB         Subtract            Rd = Rn  -  Op2
  468. 0011    RSB         Reverse Subtract    Rd = Op2 -  Rn
  469. 0100    ADD         Addition            Rd = Rn  +  Op2
  470. 0101    ADC         Add with Carry       Rd = Rn  +  Op2 + C
  471. 0110    SBC         Subtract with carry     Rd = Rn  -  Op2 - (1-C)
  472. 0111    RSC         Reverse sub w/carry     Rd = Op2 -  Rn  - (1-C)
  473. 1000    TST         Test bit            Rn AND Op2
  474. 1001    TEQ         Test equality       Rn EOR Op2
  475. 1010    CMP         Compare             Rn  -  Op2
  476. 1011    CMN         Compare Negative    Rn  + Op2
  477. 1100    ORR         Boolean Or          Rd = Rn OR  Op2
  478. 1101    MOV         Move value          Rd =        Op2
  479. 1110    BIC         Bit clear           Rd = Rn AND NOT Op2
  480. 1111    MVN         Move Not            Rd =    NOT Op2
  481. </PRE>
  482. Note that MVN and CMN are not as related as they first appear; MVN
  483. uses straight bitwise negation, setting Rn to the 1's complement of
  484. Op2. CMN compares Rn with the 2's complement of Op2.
  485. <P>
  486. These instructions fall broadly into 4 subsets:
  487. <DL>
  488. <DT> MOV,  MVN
  489. <DD>Rn is ignored, and should be 0000. If the S bit is set, N and Z
  490. are set on the result, and if the shifter is used, C is set to be the
  491. last bit shifted out. V is unaffected.
  492. <DT> CMN,  CMP,  TEQ,  TST
  493. <DD>Rd is not set by the instruction, and should be 0000. The S bit
  494. must be set (most assemblers do this automatically; if it weren't
  495. set, the instruction would be MRS, MSR, or an unallocated one.)
  496. <P>
  497. The arithmetic operations (CMN, CMP) set N, Z on result, and C and
  498. V from the ALU.
  499. <P>
  500. The logical operations (TEQ, TST) set N and Z on the result, C
  501. from the shifter if it is used (in which case it becomes the last
  502. bit shifted out), and V is unaffected.
  503. <P>
  504. As a special case (for ARMs >= 6, this only applies to 26 bit
  505. code), the dddd field being 1111 causes flags (in user mode), or
  506. the entire 26 bit PSR (in privileged modes) to be set from the
  507. corresponding bits of the result. This is indicated by a P suffix
  508. to the instruction - CMNP, CMPP, TEQP, TSTP. This is most commonly
  509. used to change mode via TEQP PC,#(new mode number). In 32 bit
  510. modes, MSR should be used instead (as TEQP etc will not work).
  511. <DT> ADC,  ADD,  RSB,  RSC,  SBC,  SUB
  512. <DD>If the S bit is set, then N and Z are set on result, and C and V are
  513. set from the ALU.
  514. <DT> AND,  BIC,  EOR,  ORR
  515. <DD>If the S bit is set, then N and Z are set on result, C is set from
  516. the shifter if used (in which case it becomes the last bit shifted
  517. out) and V is unaffected.
  518. </DL>
  519. <P>
  520. ADD and SUB can be used to make registers point to data in a position
  521. independent way, eg. ADD R0,PC,#24. This is so useful that some
  522. assemblers have a special directive called ADR which generates the
  523. appropriate ADD or SUB automatically. (ADR R0, fred typically puts the
  524. address of fred into R0, assuming fred is within range).
  525. <P>
  526. In 26-bit modes, special cases occur when R15 is one of the registers
  527. being used:
  528. <UL>
  529. <LI>
  530. If Rn = R15 then the value used is R15 with all the PSR bits masked out.
  531. <LI>
  532. If Op2 involves R15, then all 32 bits are used.
  533. </UL>
  534. <P>
  535. In 32-bit modes, all the bits of R15 are used.
  536. <P>
  537. In 26-bit modes, if Rd = R15 then:
  538. <UL>
  539. <LI>
  540. If the S bit is not set, only the 24 bits of the PC are set.
  541. <LI>
  542. If the S bit is set, both the PC and PSR are overwritten (though the Mode,
  543. I and F bits will not be altered unless we are in a non-user mode.)
  544. </UL>
  545. <P>
  546. For 32-bit modes, if Rd=15, all the bits of the PC will be
  547. overwritten, except the two least significant bits, which are always
  548. zero.  If the S bit is not set, that is all that happens; if the S bit
  549. is set, the SPSR for the current mode is copied to the CPSR. You
  550. should not execute a data processing instruction with the PC as
  551. destination and the S bit set in 32-bit user mode, since user mode
  552. does not have an SPSR. (By the way, you won't break the processor by
  553. doing so - it's just that the results of doing so aren't defined, and
  554. may differ between processors.)
  555. <P>
  556. These instructions take the following number of cycles to execute:
  557. 1S + (1S if register controlled shift used) + (1S + 1N if PC changed)
  558. <P>
  559. <A NAME="Branch"><H3>
  560. Branch Instructions
  561. </H3></A>
  562. <P>
  563. <PRE>
  564. xxxx101L oooooooo oooooooo oooooooo
  565. </PRE>
  566. <P>
  567. Typical Assembler Syntax:
  568. <PRE>
  569.  
  570.         BEQ  address
  571.         BLNE subroutine
  572. </PRE>
  573. <P>
  574. These instructions are used to force a jump to a new address, given as
  575. an offset in words from the value of the PC as this instruction is
  576. executed.
  577. <P>
  578. Due to the pipeline, the PC is always 2 instructions (8 bytes) ahead
  579. of the address at which this instruction was stored, so a branch with
  580. offset = (sign extended version of bits 0-23):
  581. <PRE>
  582.     destination address = current address + 8 + (4 * offset)
  583. </PRE>
  584. In 26-bit modes, the top 6 bits of the destination address are cleared.
  585. <P>
  586. If the L flag is set, then the current contents of PC are copied into
  587. R14 before the branch is taken. Thus R14 holds the address of the
  588. instruction after the branch, and the called routine can return with
  589. MOV PC,R14.
  590. <P>
  591. In 26-bit modes, using MOVS PC,R14, to return from a branch with link,
  592. the PSR flags can be restored automatically on return. The behaviour
  593. of MOVS PC,R14 is different in 32-bit modes, and only suitable for
  594. return from an exception.
  595. <P>
  596. Both branch and branch with links, take 2S+1N cycles to execute.
  597. <P>
  598. <A NAME="Multiplication"><H3>
  599. Multiplication
  600. </H3></A>
  601. <P>
  602. <PRE>
  603. xxxx0000 00ASdddd nnnnssss 1001mmmm
  604. </PRE>
  605. <P>
  606. Typical Assembler Syntax:
  607. <PRE>
  608.  
  609.         MULEQS Rd, Rm, Rs
  610.         MLA    Rd, Rm, Rs, Rn
  611. </PRE>
  612. <P>
  613. These instructions multiply the values of 2 registers, and optionally
  614. add a third, placing the result in another register.
  615. <P>
  616. If the S bit is set, the N and Z flags are set on the result, C is
  617. undefined, and V is unaffected.
  618. <P>
  619. If the A bit is set, then the effect of the operation is Rd = Rm.Rs + Rn
  620. otherwise, Rd = Rm.Rs.
  621. <P>
  622. The destination register shall not be the same as the operand register
  623. Rm.  R15 shall not be used as an operand or as the destination
  624. register.
  625. <P>
  626. These instructions take 1S + 16I cycles to execute in the worst case,
  627. and may be less depending on arguement values. The exact time depends
  628. on the value of Rs, according to the following table:
  629. <! center BOXED ;
  630. c s l
  631. r1 l l. ><PRE>
  632.          Range of Rs             Number of cycles
  633.  
  634.            &0 -    &1          1S + 1I
  635.            &2 -    &7          1S + 2I
  636.            &8 -    &1F         1S + 3I
  637.           &20 -    &7F         1S + 4I
  638.           &80 -    &1FF        1S + 5I
  639.          &200 -    &7FF        1S + 6I
  640.          &800 -    &1FFF       1S + 7I
  641.         &2000 -    &7FFF       1S + 8I
  642.         &8000 -    &1FFFF      1S + 9I
  643.        &20000 -    &7FFFF      1S + 10I
  644.        &80000 -    &1FFFFF     1S + 11I
  645.       &200000 -    &7FFFFF     1S + 12I
  646.       &800000 -    &1FFFFFF    1S + 13I
  647.      &2000000 -    &7FFFFFF    1S + 14I
  648.      &8000000 -    &1FFFFFFF    1S + 15I
  649.     &20000000 -    &FFFFFFFF    1S + 16I
  650. </PRE>
  651. <P>
  652. These multiplication timings don't apply to ARM7DM. ARM7DM timings are
  653. given by the following table.
  654. <! center BOXED ;
  655. c s l l l l l
  656. c s l l l l l
  657. r1 l l l l l l. ><PRE>
  658.                                 MLA/
  659.          Range of Rs        MUL    SMULL    SMLAL    UMULL    UMLAL
  660.  
  661.            &0 -    &FF         1S+1I    1S+2I    1S+3I    1S+2I    1S+3I
  662.          &100 -    &FFFF        1S+2I    1S+3I    1S+4I    1S+3I    1S+4I
  663.        &10000 -    &FFFFFF      1S+3I    1S+4I    1S+5I    1S+4I    1S+5I
  664.      &1000000 -    &FEFFFFFF    1S+4I    1S+5I    1S+6I    1S+5I    1S+6I
  665.     &FF000000 -    &FFFEFFFF    1S+3I    1S+4I    1S+5I    1S+5I    1S+6I
  666.     &FFFF0000 -    &FFFFFEFF    1S+2I    1S+3I    1S+4I    1S+5I    1S+6I
  667.     &FFFFFF00 -    &FFFFFFFF    1S+1I    1S+2I    1S+3I    1S+5I    1S+6I
  668. </PRE>
  669. <P>
  670. <A NAME="Long"><H3>
  671. Long Multiplication (ARM7DM)
  672. </H3></A>
  673. <P>
  674. <PRE>
  675. xxxx0000 1UAShhhh llllssss 1001mmmm
  676. </PRE>
  677. <P>
  678. Typical Assembler Syntax:
  679. <PRE>
  680.  
  681.         UMULL  Rl,Rh,Rm,Rs
  682.         UMLAL  Rl,Rh,Rm,Rs
  683.         SMULL  Rl,Rh,Rm,Rs
  684.         SMLAL  Rl,Rh,Rm,Rs
  685. </PRE>
  686. <P>
  687. These instructions multiply the values of registers Rm and Rs to
  688. obtain a 64-bit product.
  689. <P>
  690. When the U bit is clear the multiply is unsigned (UMULL or UMLAL),
  691. otherwise signed (SMULL, SMLAL).  When the A bit is clear the result
  692. is stored with its least significant half in Rl and its most
  693. significant half in Rh.  When A is set, the result is instead added to
  694. the contents of Rh,Rl.
  695. <P>
  696. The program counter, R15 should not be used.  Rh, Rl and Rm should be
  697. different.
  698. <P>
  699. If the S bit is set, the N and Z flags are set on the 64-bit result, C and V
  700. are undefined.
  701. <P>
  702. Timings for these can be found above in the multiplication section.
  703. </PRE>
  704. <P>
  705. <A NAME="Transfer"><H3>
  706. Single Data Transfer
  707. </H3></A>
  708. <P>
  709. <PRE>
  710. xxxx010P UBWLnnnn ddddoooo oooooooo  Immediate form
  711. xxxx011P UBWLnnnn ddddcccc ctt0mmmm  Register form
  712. </PRE>
  713. <P>
  714. Typical Assembler Syntax:
  715. <PRE>
  716.  
  717.         LDR  Rd, [Rn, Rm, ASL#1]!
  718.         STR  Rd, [Rn],#2
  719.         LDRT Rd, [Rn]
  720.         LDRB Rd, [Rn]
  721. </PRE>
  722. <P>
  723. These instructions load/store a word of memory from/to a register. The
  724. first register used in specifying the address is termed the base
  725. register.
  726. <P>
  727. If the L bit is set, then a load is performed. If not, a store.
  728. <P>
  729. If the P bit is set, then Pre-indexed addressing is used, otherwise
  730. post-indexed addressing is used.
  731. <P>
  732. If the U bit is set, then the offset given is added to the base
  733. register - otherwise it is subtracted.
  734. <P>
  735. If the B bit is set, then a byte of memory is transferred, otherwise a
  736. word is transferred. This is signified to assemblers by postfixing the
  737. mnemonic stub with a `B'.
  738. <P>
  739. The interpretation of the W bit depends on the addressing mode
  740. used:
  741. <UL>
  742. <LI>
  743. For pre-indexed addressing, W being set forces the writing
  744. back of the final address used for the address translation
  745. into the base register. (i.e.  A side effect of the transfer
  746. is Rn := Rn +/- offset. This is signified to assemblers by
  747. postfixing the instruction with !.)
  748. <LI>
  749. For post-indexed addressing, the address is always written
  750. back, and the bit being set indicates that an address
  751. translation should be forced before the transfer takes
  752. place. This is signified to assmeblers by postfixing the
  753. mnemonic stub with `T'.
  754. </UL>
  755. <P>
  756. An address translation causes the chip to tell the memory system that
  757. this is a user mode transfer, regardless of whether the chip is in a
  758. user mode or a privileged mode at the time. This is useful e.g. when
  759. writing emulators: suppose for instance that a user mode program
  760. executes an STF instruction to an area of memory that may not be
  761. written by user mode code. If this is executed by an FPA, it will
  762. abort. If it is executed by the FPE, it should also abort. But the FPE
  763. runs in a privileged mode, so if it were to use normal stores, they
  764. wouldn't abort. To make aborts work properly, it instead uses normal
  765. stores if it was called from a privileged mode, but STRTs if it was
  766. called from a user mode.
  767. <P>
  768. If the immediate form of the instruction is used, the o field gives a
  769. 12-bit offset. If the register form is used, then it is decoded as for
  770. the data processing instructions, with the restriction that shifts by
  771. register amounts are not allowed.
  772. <P>
  773. If R15 is used as Rd, the PSR is not modified. The PC should not be
  774. used in Op2.
  775. <P>
  776. Other restrictions:
  777. <UL>
  778. <LI>
  779. Don't use writeback or post-indexing when the base register is the PC.
  780. <LI>
  781. Don't use the PC as Rd for an LDRB or STRB.
  782. <LI>
  783. When using post-indexing with a register offset, don't make Rn and Rm the
  784. same register (doing so makes recovery from aborts impossible).
  785. </UL>
  786. <P>
  787. A load takes 1S + 1N + 1I + (1S + 1N if PC changed) cycles, and a
  788. store takes 2N cycles.
  789. <P>
  790. <A NAME="Block"><H3>
  791. Block Data Transfer
  792. </H3></A>
  793. <P>
  794. <PRE>
  795. xxxx100P USWLnnnn llllllll llllllll
  796. </PRE>
  797. <P>
  798. Typical Assembler Syntax:
  799. <PRE>
  800.  
  801.         LDMFD   Rn!, {R0-R4, R8, R12}
  802.         STMEQIA Rn,   {R0-R3}
  803.         STMIB   Rn,   {R0-R3}^
  804. </PRE>
  805. <P>
  806. These instructions are used to load/store large numbers of registers
  807. from/to memory at a time. The memory addresses used are either
  808. increasing or decreasing in memory from a value held in a base
  809. register, Rn, (which may itself be stored), and the final address can
  810. be written back into the base. These instructions are ideal for
  811. implementing stacks, and storing/restoring the contents of registers
  812. on entry/exit from a subroutine.
  813. <P>
  814. The U bit indicates whether the address will be modified by +4 (set),
  815. or -4 (clear) for each register.
  816. <P>
  817. The W bit always indicates writeback.
  818. <P>
  819. If set, the L bit indicates a load operation should be performed. If
  820. clear, a save.
  821. <P>
  822. The P bit is used indicate whether to increment/decrement the base
  823. before or after each load/store (see the table below).
  824. <P>
  825. Bit l is set if Rl is to be loaded/stored by this operation.
  826. <P>
  827. Assemblers typically follow the mnemonic stub with a condition code,
  828. and then a two letter code to indicate the settings of the U and W
  829. bits.
  830. <! center BOXED ;
  831. l l l l. ><PRE>
  832. Stub    Meaning                             P    U
  833.  
  834. DA    Decrement Rn After each store/load    0    0
  835. DB    Decrement Rn Before each store/load    1    0
  836. IA    Increment Rn After each store/load    0    1
  837. IB    Increment Rn Before each store/load    1    1
  838. </PRE>
  839. <P>
  840. Synonyms for these exist which are clearer when implementing stacks:
  841. <! center BOXED ;
  842. l l. ><PRE>
  843. Stub    Meaning
  844.  
  845. EA    Empty Ascending stack
  846. ED    Empty Decending stack
  847. FA    Full Ascending stack
  848. FD    Full Decending stack
  849. </PRE>
  850. <P>
  851. In an empty stack, the stack pointer points to the next empty
  852. position. In a full one the stack pointer points to the topmost full
  853. position. Ascending stacks grow towards high locations, and descending
  854. stacks grow towards low locations.
  855. <P>
  856. The registers are always stored so that the lowest numbered register
  857. is at the lowest address in memory. This can affect stacking and
  858. unstacking code. For instance, if I want to push R1-R4 on to a stack,
  859. then load them back two at a time, to get them back to the same
  860. registers, I need to do something like:
  861. <PRE>
  862.  
  863.    STMFD R13!,{R1,R2,R3,R4}  ;Puts R1 low in memory, i.e. at end of stack
  864.    LDMFD R13!,{R1,R2}
  865.    LDMFD R13!,{R3,R4}
  866.  
  867. </PRE>
  868. for a descending stack, but something like:
  869. <PRE>
  870.  
  871.    STMFA R13!,{R1,R2,R3,R4}  ;Puts R4 high in memory, i.e. at end of stack
  872.    LDMFA R13!,{R3,R4}
  873.    LDMFA R13!,{R1,R2}
  874.  
  875. </PRE>
  876. for an ascending stack.
  877. <P>
  878. The codes are synonyms as follows:
  879. <! center BOXED ;
  880. c c c. ><PRE>
  881. Code    Load    Store
  882.  
  883. EA    DB    IA
  884. ED    IB    DA
  885. FA    DA    IB
  886. FD    IA    DB
  887. </PRE>
  888. The S bit controls two special functions, both of which are indicated
  889. to the assembler by putting "^" at the end of the instruction:
  890. <UL>
  891. <LI>
  892. If the S bit is set, the instruction is LDM and R15 is in the register
  893. list, then:
  894. <UL>
  895. <LI>
  896. In 26-bit privileged modes, all 32 bits of R15 will be loaded.
  897. <LI>
  898. In 26-bit user mode, the 4 flags and 24 PC bits of R15 will be loaded.
  899. Bits 27, 26, 1 and 0 of the loaded value will be ignored.
  900. <LI>
  901. In 32-bit modes, all 32 bits of R15 will be loaded, though note that
  902. the two bottom bits are always zero, so any ones loaded to them will
  903. be ignored. In addition, the SPSR of the current mode will be
  904. transferred to the CPSR; since user mode does not have an SPSR, this
  905. type of instruction should not be used in 32-bit user mode.
  906. </UL>
  907. <LI>
  908. If the S bit is set and either the instruction is STM or R15 is not in
  909. the register list, then the user mode registers will be transferred
  910. rather than those for the current mode. This type of instruction should
  911. not be used in user mode.
  912. </UL>
  913. <P>
  914. Special cases occur when the base register is used in the list of
  915. registers to be transferred.
  916. <UL>
  917. <LI>
  918. The base register can always be loaded without any problems.
  919. However, don't specify writeback if the base register is being
  920. loaded - you can't end up with both a written-back value and a
  921. loaded value in the base register!
  922. <LI>
  923. The base register can be stored with no complications as long
  924. as writeback is not used.
  925. <LI>
  926. Storing a list of registers including the base register using
  927. writeback will write the value of the base register before
  928. writeback to memory only if the base register is the first in
  929. the list. Otherwise, the value which is used is not defined.
  930. </UL>
  931. <P>
  932. Further special cases occur if the program counter is present in the
  933. list of registers to load and save.
  934. <UL>
  935. <LI>
  936. The PSR is always saved with the PC (in 26 bit modes) (and the PC will
  937. always be 12 bytes further on, rather than the usual 8 (in all
  938. modes)).
  939. <LI>
  940. On a load, only the bits of the PSR that are alterable in the
  941. current mode can be affected, and then only if the S bit is set.
  942. </UL>
  943. <P>
  944. The PC should not be used as the base register.
  945. <P>
  946. A block data load, takes nS + 1N + 1I + (1S + 1N if PC changed)
  947. cycles, and a block data store takes (n-1)S + 2N cycles, where "n" is
  948. the number of words being transferred.
  949. <P>
  950. <A NAME="Software"><H3>
  951. Software interrupt
  952. </H3></A>
  953. <P>
  954. <PRE>
  955. xxxx1111 yyyyyyyy yyyyyyyy yyyyyyyy
  956. </PRE>
  957. <P>
  958. Typical Assembler Syntax:
  959. <PRE>
  960.  
  961.        SWI   "OS_WriteI"
  962.        SWINE &400C0
  963. </PRE>
  964. <P>
  965. On encountering a software interrupt, the ARM switches into SVC mode,
  966. saves the current value of R15 into R14_SVC, and jumps to location 8
  967. in memory, where it assumes it will find a SWI handling routine to
  968. decode the lower 24 bits of the SWI just executed, and do whatever the
  969. SWI number concerned means on that particular operating system.
  970. <P>
  971. An operating system written on the ARM will typically use SWIs to
  972. provide miscellaneous routines for programmers.
  973. <P>
  974. A SWI takes 2S + 1N cycles to execute (plus whatever time is required
  975. to decode the SWI number and execute the appropriate routines).
  976. <P>
  977. <A NAME="CoproOp"><H3>
  978. Co-processor data operations
  979. </H3></A>
  980. <P>
  981. <PRE>
  982. xxxx1110 oooonnnn ddddpppp qqq0mmmm
  983. </PRE>
  984. <P>
  985. Typical Assembler Syntax:
  986. <PRE>
  987.  
  988.        CDP p, o, CRd, CRn, CRm, q
  989.        CDP p, o, CRd, CRn, CRm
  990. </PRE>
  991. <P>
  992. This instruction is passed on to co-processor p, telling it to perform
  993. operation o, on co-processor registers CRn and CRm, and place the
  994. result into Crd.
  995. <P>
  996. qqq may supply additional information about the operation concerned.
  997. <P>
  998. The exact meaning of these instructions depends on the particular
  999. co-processor in use; The above is only a recommended usage for the
  1000. bits (and indeed the FPA doesn't conform to it). The only part which
  1001. is obligatory is that pppp must be the coprocessor number: the
  1002. coprocessor designer is free to allocate oooo, nnnn, dddd, qqq and
  1003. mmmm as desired.
  1004. <P>
  1005. If the coprocessor uses the bits in a different way than the
  1006. recommended one, assembler macros will probably be needed to translate
  1007. the instruction syntax that makes sense to people into the correct CDP
  1008. instruction. For commonly used coprocessors such as the FPA, many
  1009. assemblers have the extra mnemonics built in and do this translation
  1010. automatically. (For example, assembling MUFEZ F0,F1,#10 as its
  1011. equivalent CDP 1,1,CR0,CR9,CR15,3.)
  1012. <P>
  1013. Currently defined co-processor numbers include:
  1014. <! center BOXED ;
  1015. l l. ><PRE>
  1016. 1 and 2    Floating Point unit
  1017. 15    Cache Controller
  1018. </PRE>
  1019. <P>
  1020. If a call to a coprocessor is made and the coprocessor does not
  1021. respond (normally becuase it isn't there!), the undefined instruction
  1022. vector is called (exactly as for one of the undefined instructions
  1023. given later). This is used to transparently provide FP support on
  1024. machines without an FPA.
  1025. <P>
  1026. These instructions take 1S + bI cycles to execute, where b is the
  1027. number of cycles that the coprocessor causes the ARM to busy-wait
  1028. before it accepts the instruction: again, this is under the
  1029. coprocessor's control.
  1030. <P>
  1031. <A NAME="CoproTrans"><H3>
  1032. Co-processor data transfer and register transfers
  1033. </H3></A>
  1034. <P>
  1035. <PRE>
  1036. xxxx110P UNWLnnnn DDDDpppp oooooooo LDC/STC
  1037. xxxx1110 oooLNNNN ddddpppp qqq1MMMM MRC/MCR
  1038. </PRE>
  1039. <P>
  1040. Again these depend on the particular co-processor p in use.
  1041. <P>
  1042. N and D signify co-processor register numbers, n and d are ARM
  1043. processor numbers. o is the co-processor operation to use. M signifies
  1044. bits the coprocessor is free to use as it wants.
  1045. <P>
  1046. The first form, denotes LDC if L=1, STC otherwise. The instruction
  1047. behaves like LDR or STR respectively, in each case with an immediate
  1048. offset, with the following exceptions.
  1049. <UL>
  1050. <LI>
  1051. The offset is 4*(oooooooo), not a general 12-bit constant.
  1052. <LI>
  1053. If P=0 (post-indexing) is specified, W must be 1, and W being 1 just
  1054. indicates that writeback is required, not that the memory system should be
  1055. told that this is a user mode transfer. Instructions with P=0 and W=0 are
  1056. reserved for future expansion.
  1057. <LI>
  1058. One or more coprocessor registers are loaded or stored. The coprocessor
  1059. determines how many and which registers are to be loaded or stored from
  1060. the DDDD and N bits: all the ARM does is transfer a word to or from the
  1061. indicated address, then another to or from the indicated address + 4, then
  1062. one to or from the indicated address + 8, etc., until the coprocessor
  1063. tells it to stop.
  1064. <LI>
  1065. By convention, DDDD denotes the (first) coprocessor register to load or
  1066. store and N denotes the length in some way, with N=1 indicating a "long"
  1067. form. Coprocessor designers are free to ignore this...
  1068. <LI>
  1069. The assembler syntax is along the lines of:
  1070. <PRE>
  1071.  
  1072. LDC    p,CRd,[Rn,#20]   ;short form (N=0), pre-indexed
  1073. STCL   p,CRd,[Rn,#-32]! ;long form (N=1), pre-indexed with writeback
  1074. LDCNEL p,CRd,[Rn],#-100 ;long form (N=1), post-indexed
  1075. </PRE>
  1076. </UL>
  1077. <P>
  1078. The second form denotes, MRC, if L=1, MCR otherwise.  MRC transfers a
  1079. coprocessor register to an ARM register, MCR the other way around (the
  1080. letters may seem the wrong way around, but remember that destinations
  1081. are usually written on the left in ARM assembler).
  1082. <P>
  1083. MCR transfers the contents of ARM register Rd to the coprocessor. The
  1084. coprocessor is free to do whatever it wants with it based on the values of
  1085. the ooo, dddd, qqq and MMMM fields, though as usual there is a "standard"
  1086. interpretation: write it to coprocessor register CRN, using operation ooo,
  1087. with possible additional control provided by CRM and qqq. The assembler
  1088. syntax is:
  1089. <PRE>
  1090.  
  1091.        MCR   p,o,Rd,CRN,CRM,q
  1092. </PRE>
  1093. <P>
  1094. Rd should not be R15 for an MCR instruction.
  1095. <P>
  1096. MRC transfers a single word from the coprocessor and puts it in ARM register
  1097. Rd. The coprocessor is free to generate this word in any way it likes using
  1098. the same fields as for MCR, with the standard interpretation that it comes
  1099. from CRN using operation ooo, with possible additional control provided by
  1100. CRM and qqq. The assembler syntax is:
  1101. <PRE>
  1102.  
  1103.        MRC   p,o,Rd,CRN,CRM,q
  1104. </PRE>
  1105. <P>
  1106. If Rd is R15 for an MRC instruction, the top 4 bits of the word transferred
  1107. are used to set the flags; the remaining 28 bits are discarded. (This is the
  1108. mechanism used e.g. by floating point comparison instructions.)
  1109. <P>
  1110. LDC and STC take (n-1)S + 2N + bI cycles to execute, MRC takes
  1111. 1S+bI+1C cycles, and MCR takes 1S + (b+1)I + 1C cycles, where b is the
  1112. number of cycles that the coprocessor causes the ARM to busy-wait
  1113. before it accepts the instruction: again, this is under the
  1114. coprocessor's control, and n is the number of words being transferred
  1115. (Note this is under the coprocessor's control, not the ARM's)
  1116. <P>
  1117. <A NAME="Swap"><H3>
  1118. Single Data Swap (ARM 3 and later including ARM 2aS)
  1119. </H3></A>
  1120. <P>
  1121. <PRE>
  1122. xxxx0001 0B00nnnn dddd0000 1001mmmm
  1123. </PRE>
  1124. <P>
  1125. Typical Assembler Syntax:
  1126. <PRE>
  1127.  
  1128.        SWP Rd, Rm, [Rn]
  1129. </PRE>
  1130. <P>
  1131. These instructions load a word of memory (address given by register
  1132. Rn) to a register Rd and store the contents of register Rm to the same
  1133. address. Rm and Rd may be the same register, in which case the
  1134. contents of this register and of the memory location are swapped. The
  1135. load and store operations are locked together by setting the LOCK pin
  1136. high during the operation to indicate to the memory manager that they
  1137. should be allowed to complete without interruption.
  1138. <P>
  1139. If the B bit is set, then a byte of memory is transferred, otherwise a
  1140. word is transferred.
  1141. <P>
  1142. None of Rd, Rn, and Rm may be R15.
  1143. <P>
  1144. This instruction takes 1S + 2N + 1I cycles to execute.
  1145. <P>
  1146. <A NAME="Status"><H3>
  1147. Status Register transfer (ARM 6 and later)
  1148. </H3></A>
  1149. <P>
  1150. <PRE>
  1151. xxxx0001 0s10aaaa 11110000 0000mmmm  MSR  Register form
  1152. xxxx0011 0s10aaaa 1111rrrr bbbbbbbb  MSR  Immediate form
  1153. xxxx0001 0s001111 dddd0000 00000000  MRS
  1154. </PRE>
  1155. <P>
  1156. Typical Assembler Syntax:
  1157. <PRE>
  1158.  
  1159.        MSR   SPSR_all, Rm          ;aaaa = 1001
  1160.        MSR   CPSR_flg, #&F0000000  ;aaaa = 1000
  1161.        MSRNE CPSR_ctl, Rm          ;aaaa = 0001
  1162.        MRS   Rd, CPSR
  1163. </PRE>
  1164. <P>
  1165. The s bit, when set means access the SPSR of the current privileged mode,
  1166. rather than the CPSR. This bit must only be set when executing the command
  1167. in a privileged mode.
  1168. <P>
  1169. MSR is used for transfering a register or constant to a status register.
  1170. <P>
  1171. The aaaa bits can take the following values:
  1172. <! center BOXED ;
  1173. l l. ><PRE>
  1174. Value    Meaning
  1175.  
  1176. 0001    Set the control bits of the PSR concerned.
  1177. 1000    Set the flag bits of the PSR concerned.
  1178. 1001    Set the control and flag bits of the PSR concerned (i.e. all the
  1179.     bits at present).
  1180. </PRE>
  1181. Other values of aaaa are reserved for future expansion.
  1182. <P>
  1183. In the register form, the source register is Rm. In the immediate
  1184. form, the source is #b, ROR #2r.
  1185. <P>
  1186. R15 should not be specified as the source register of an MRS
  1187. instruction.
  1188. <P>
  1189. MRS is used for transfering processor status to a register.
  1190. <P>
  1191. The d bits store the destination register number; Rd must not be R15.
  1192. <P>
  1193. N.B. The instruction encodings correspond to the data processing
  1194. instructions with opcodes 10xx (i.e. the test instructions) and the S bit
  1195. clear.
  1196. <P>
  1197. These instruction always execute in 1-S cycle.
  1198. <P>
  1199. <A NAME="Undefined"><H3>
  1200. Undefined instructions
  1201. </H3></A>
  1202. <P>
  1203. <PRE>
  1204. xxxx0001 yyyyyyyy yyyyyyyy 1yy1yyyy ARM 2 only
  1205. xxxx011y yyyyyyyy yyyyyyyy yyy1yyyy
  1206. </PRE>
  1207. <P>
  1208. These instructions are currently undefined. On encountering an
  1209. undefined instruction, the ARM switches to SVC mode, puts the old
  1210. value of R15 into R14_SVC and jumps to location, where it expects to
  1211. find code to decode the undefined instruction and behave accordingly.
  1212. <P>
  1213. Notes:
  1214. <UL>
  1215. <LI>
  1216. These instructions are documented as "undefined" because they enter the
  1217. undefined instruction processor trap in this way. Plenty of other
  1218. instructions are undefined in the looser sense that nothing says what
  1219. they do. For instance, bit patterns of the form:
  1220. <PRE>
  1221.                xxxx0000 01xxxxxx xxxxxxxx 1001xxxx
  1222. </PRE>
  1223. are related to data processing instructions, multiplies, long multiplies
  1224. and SWPs, but are none of these because:
  1225. <UL>
  1226. <LI>
  1227. Data processing instructions with bit 25 = 0 and bit 4 = 1 have
  1228. register controlled shifts, and so must have bit 7 = 0.
  1229. <LI>
  1230. Multiply instructions have bits 23:22 = 00.
  1231. <LI>
  1232. Long multiply instructions have bits 23:22 = 1U.
  1233. <LI>
  1234. SWPs have bit 24 = 1.
  1235. </UL>
  1236. What these instructions do simply isn't defined, whereas the ones
  1237. listed above are actually <B>defined</B> to enter the undefined
  1238. instruction trap, at least until some future use is found for them.
  1239. <LI>
  1240. Note that the "ARM2 only" undefined instructions include those that
  1241. became SWP instructions on ARM3/ARM2as and later.
  1242. </UL>
  1243. <P>
  1244. <HR><A NAME="Credits"><H2>
  1245. Credits
  1246. </H2></A>
  1247. <P>
  1248. This document was originally written by Robin Watts, with
  1249. considerable consultation with Steven Singer. It was then later updated
  1250. by Mark Smith to include more information on ARMs later than 2.
  1251. <P>
  1252. David Seal provided a huge list of corrections and amendments, and
  1253. unwittingly provided the basis for the timing information in a posting
  1254. to usenet.
  1255. <P>
  1256. Various corrections were also submitted/posted by Olly Betts, Clive
  1257. Jones, Alain Noullez, Sverker Wiberg and Mark Wooding.
  1258. <P>
  1259. Thanks to everyone that helped (and if I have missed you here, please
  1260. let me know.)
  1261. <P>
  1262. <B>
  1263. Just because I have included peoples addresses here, please do not
  1264. take this as an invitation to mail them any questions you may have!
  1265. </B>
  1266. <P>
  1267. <! center ;
  1268. l l. ><PRE>
  1269. Olly Betts    olly@mantis.co.uk
  1270. Paul Hankin    pdh13@uk.ac.cam.cus
  1271. Robert Harley    robert@edu.caltech.cs
  1272. Clive Jones    clive@armltd.co.uk
  1273. Alain Noullez    anoullez@zig.inria.fr
  1274. David Seal    <address withheld by request>
  1275. Steven Singer    s.singer@ph.surrey.ac.uk
  1276. Mark Smith    ee91mds2@brunel.ac.uk
  1277. Robin Watts    Robin.Watts@comlab.ox.ac.uk
  1278. Sverker Wiberg    sverkerw@Student.csd.UU.SE
  1279. Mark Wooding    csuov@csv.warwick.ac.uk
  1280. </PRE>
  1281. </BODY>
  1282. </HTML>
  1283.