Lecture 2 - ARM Instruction Set
Lecture 2 - ARM Instruction Set
Lecture 2 - ARM Instruction Set
CF Destination 0
Barrel Shifter - Right Shifts
Rotate Right
Rotate Right (ROR)
•Similar to an ASR but the bits Destination CF
wrap around as they leave the
LSB and appear as the MSB.
ROR #5
• Note the last bit rotated is
also used as the Carry Out.
Rotate Right Extended Rotate Right through Carry
(RRX)
• This operation uses the CPSR Destination CF
C flag as a 33rd bit.
Data processing instructions
• If <shifter_operand> is shifted registers
It may be shifted by
– a constant number of bit positions
ADD r3,r2, r1,LSL #3 ; r3 := r2+(r1<<3)
B{<cond>} <target_address>
if (cond is true)
PC PC + (signed_immediate_24 << 2)
• Flags are not affected
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 1 0 1 0 signed_immediate_24
Branch and Link: Syntax
BL{<cond>} <target_address>
if (cond is true)
R14 next instruction address
PC PC + (signed_immediate_24 << 2)
• Flags are not affected
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 1 0 1 1 signed_immediate_24
Branch and link
• ARM’s subroutine call mechanism
• saves the return address in r14
BL SUBR ; branch to SUBR
... ; return to here
SUBR ; subroutine entry point
...
BX r14 ; return (MOV pc, r14)
• note the use of a data processing instruction for return
• r14 is often called the link register (lr)
– the only special register used other than the PC
(r15)
Example
MOVS R0, R1
MOVEQS R0, R2
MOVEQ R0, R3
• Example
– if (r0 != 5) {r1 := r1 + r0 - r2}
31 28 27 24 23 21 20 19 16 15 12 11 8 7 4 3 0
cond 0000 mul S Rd/RdHi Rn/RdLo Rs 1001 Rm
UMLALS R1,R5,R2,R3
; R1 := (R2*R3)[31:0] + R1
; R5 := (R2*R3)[63:32] + R5 + carry from((R2*R3)[31:0] + R1)
N, Z Flags will be set
Example 2
AREA ex02, CODE READONLY
ENTRY
MOV r6, #10 ; load 10 into r6
MOV r4, r6 ; copy n into a temp register
loop SUBS r4, r4, #1 ; decrement next multiplier
MULNE r7, r6, r4 ; multiply
MOV r6, r7
BNE loop ;repeat until...
stop B stop ;stop here
END
Example 3
AREA ex03, CODE READONLY
ENTRY
LDR r0, =0XF631024C ; load data
LDR r1, =0X17539ABD ; load data
EOR r0, r0, r1 ; r0 XOR r1
EOR r1, r0, r1 ; r0 XOR r1
EOR r0, r0, r1 ; r0 XOR r1
stop B stop ;stop here
END