Professional Documents
Culture Documents
Storage (RS)
Example1 * Example2 * Example3 * Example4 * LABEL1 * EQU * BAL B LABEL1 B X'010'(R15) B 4(R15) Branch to the location in R15 plus the (16 bit) decimal displacement of 4 Branch to the location in R15 plus the (16 bit) hex displacement of decimal 16 Branch to the location with the specified address (Base & displacement set by the Assembler) R14,X'010'(R15) Branch to location in (R15 plus displacement), put return address in R14. A location (within the range of the base register for the program)
Indexed (RX)
Example * B 4(R15,R1) Branch to location whose address is calculated from R15 plus 4 plus R1
Conditional branch
Storage (RS)
Example * Example * * * Example * BC 7,X'010'(R15) BC 8,4(R15) BE 4(R15) Branch to the location in (R15 plus 4), if previous comparison gave "Equal" condition (8) Branch to the location in (R15 plus 4), if previous comparison gave "Equal" condition (8) (same as above but specifying actual condition code value = 8) Branch to the location in (R15 plus X'010') if previous comparison gave "Unequal" condition (7)
Indexed (RX)
Example * BCT R1,4(R15) Reduce value in R1 by 1 and, if it is then zero, branch to location in (R15 plus 4 )
Arithmetic Operations * Operations are: ADD operand1 + operand2 ADC operand1 + operand2 + carry SUB operand1 - operand2 SBC operand1 - operand2 + carry -1 RSB operand2 - operand1 RSC operand2 - operand1 + carry - 1 * Syntax: <Operation>{<cond>}{S} Rd, Rn, Operand2 * Examples ADD r0, r1, r2 SUBGT r3, r3, #1 RSBLES r4, r5, #5 Logical Operations * Operations are: AND operand1 AND operand2 EOR operand1 EOR operand2 ORR operand1 OR operand2 BIC operand1 AND NOT operand2 [ie bit clear] * Syntax: <Operation>{<cond>}{S} Rd, Rn, Operand2 * Examples: AND r0, r1, r2 BICEQ r2, r3, #7 EORS r1,r3,r0 Data Movement * Operations are: MOV operand2 MVN NOT operand2 Note that these make no use of operand1. * Syntax: <Operation>{<cond>}{S} Rd, Operand2 * Examples: MOV r0, r1 MOVS r2, #10 MVNEQ r1,#0
Operation
rd = n
Example
mov r7, r5 ; r7 = r5
add rd, rn, n rd = rn + n add r0, r0, #1 ; r0 = r0 + 1 sub rd, rn, n rd = rn - n sub r0, r2, r1 ; r0 = r2 + r1 cmp rn, n rn - n cmp r1, r2 ; r1 - r2
<shift>
is <shiftname> <register> or <shiftname> #expression, or RRX (rotate right one bit with extend). <shiftname> is: ASL, LSL, LSR, ASR, ROR. (ASL is a synonym for LSL; they assemble to the same code.)
Example
ADDEQ R2,R4,R5 TEQS R4,#3 SUB R4,R5,R7,LSR R2; ;logical right shift R7 by the number in ;the bottom byte of R2, subtract result ;from R5, and put the answer into R4 ;return from subroutine ;return from exception and restore CPSR ;from SPSR_mode ;if the Z flag is set make R2:=R4+R ;test R4 for equality with 3 ;(the S is in fact redundant as the ;assembler inserts it automatically)