Professional Documents
Culture Documents
1
ARM register organization
ro
r1 usable in user mode
r2
system modes only
r3
r4
r5
r6
r7
r8_fiq
r8
r9_fiq
r9
r10_fiq
r10
r11_fiq
r11 r13_und
r12_fiq r13_irq
r12 r13_abt
r13_svc r14_und
r13_fiq r14_irq
r13 r14_abt
r14_svc
r14_fiq
r14
SPSR_und
R15 (PC) SPSR_irq
SPSR_abt
SPSR_svc undefined
SPSR_fiq irq
CPSR abort mode
svc mode
fiq mode
mode
mode
user mode
2
ARM memory organization
! Memory is a linear array
of 232 byte locations.
23 22 21 20
! ARM can address:
19 18 17 16 ! individual bytes
----------------- word 16----------------
! 32-bit words on 4-byte
15 14 13 12
3
a) Data processing instructions
! ALL operands are 32-bits wide and either:
! come from registers, or
! are literals (´immediate´ values ) specified in the
instruction
! The result, if any, is 32-bits wide and goes
into a register
! except long multiplies generate 64-bit results
! All operand and result registers are specified
independently
Arithmetic operations
4
Bit-wise logical operations
MOV r0, r2 ; r0 := r2
MVN r0, r2 ; r0 := not r2
5
Comparison operations
Immediate operands
! the 2nd source operand (r2) may be replaced
by a constant:
ADD r3,r3, #1 ; r3 := r3 + 1
AND r8,r7, #&ff ; r8 := r7 [7:0]
6
Shifted register operands
! the 2nd source operand may be shifted
! by a constant number of bit positions:
ADD r3, r2, r1, LSL #3 ; r3 := r2 + 8*r1
00000 00000
LSL #5 LSR #5
31 0 31 0
0 1
00000 0 11111 1
ASR #5, positive operand ASR #5, negative operand
31 0 31 0
C
C C
ROR #5 RRX
7
Setting condition codes
! All data processing instructions may set the
condition codes
! ’S’ means “set condition codes”
! Example : 64–bit addition
Multiplication
! ARM has special multiply instructions
MUL r4, r3, r2 ; r4 := (r3 *r2)[31:0]
! only the least significant 32 bits are returned
! immediate operands are not supported
! ´multiply-accumulate´:
MLA r4, r3, r2, r1 ; r4 := (r3*r2+r1)[31:0]
8
Data processing instructions - Summary
Opcode Mnemonic Meaning Effect
[24:21]
0000 AND Logical bit-wise AND Rd:= Rn AND Op2
0001 EOR Logical bit-wise exclusive OR Rd:= Rn EOR Op2
0010 SUB Subtract Rd:= Rn - Op2
0011 RSB Reverse subtract Rd:= Op2 - Rn
0100 ADD Add Rd:= Rn + Op2
0101 ADC Add with carry Rd:= Rn + Op2 + C
0110 SBC Subtract with carry Rd:= Rn - Op2 + C - 1
0111 RSC Reverse subtract with carry Rd:= Op2 - Rn + C - 1
1000 TST Test Scc on Rn AND Op2
1001 TEQ Test equivalence Scc on Rn EOR Op2
1010 CMP Compare Scc on Rn - Op2
1011 CMN Compare negated Scc on Rn + Op2
1100 OPR Logical bit-wise OR Rd:= Rn OR Op2
1101 MOV Move Rd:= Op2
1110 BIC Bit clear Rd:= Rn AND NOT Op2
1111 MVN Move negated Rd:= NOT Op2
destination register
first operand register
set condition codes
arithmetic/logic function
25 11 8 7 0
1 # rot 8-bit immediate
immediate alignment
11 7 6 5 4 3 0
# shift Sh 0 Rm
immediate shift length
25 shift type
0 second operand register
11 8 7 6 5 4 3 0
Rs 0 Sh 1 Rm
9
Multiply instructions - Encoding
31 28 27 24 23 21 20 19 16 15 12 11 8 7 4 3 0
cond 0000 mul S Rd / Rd Hi Rn / Rd Lo Rs 1001 Rm
10
Single register load / store
! 32 bit
LDR r0, [r1] ; r0 := mem [r1]
STR r0, [r1] ; mem [r1] := r0
! 8 bit
LDRB r0, [r1] ; r0 := mem [r1] [7:0]
STRB r0, [r1] ; mem [r1] [7:0] := r0
Address Specification
! Register – indirect with displacement
LDR r0,[r1, #4] ; r0 := mem[r1+4]
! The offset must be within +/- 4 kBytes
11
Updating the address register
! Auto - indexing
LDR r0,[r1, #4] ! ; r0 := mem[r1+4]
; r1 := r1 + 4
Write effective address back to base register
! Post - indexing
LDR r0, [r1], #4 ; r0 := mem[r1]
; r1 := r1 + 4
12
Block copy adressing
! Addresses can be
! incremented or decremented
! before or after
each transfer
! May be used to implement stacks
Examples
r 9´ 101816 r 9´ r5 101816
r5 r1
r1 r0
r9 r0 100c16 r9 100c16
100016 100016
101816 101816
r9 r5 100c16 r9 100c16
r1 r5
r0 r1
r 9´ 100016 r 9´ r0 100016
13
Encoding - single word and unsigned byte data
transfer instructions
31 28 27 26 25 24 23 22 21 20 19 16 15 12 11
0 cond 01 # P U B W L Rn Rd offset
source/destination register
base register
load/store
write-back (auto-index)
unsigned byte/word
up/down
pre-/post-index
25 11 0
0 12-bit immediate
25 11 7 6 5 4 3
1 0 # shift Sh 0 Rm
31 28 27 25 24 23 22 21 20 19 16 15 12 11 8 7 6 5 4 3 0
cond 000 P U # W L Rn Rd offset H 1 S H 1
offsetL
source/destination register
base register
load/store
write-back (auto-index)
up/down
pre-/post-index
11 8 3 0
1
22 Imm7:4] Imm[3:0]
22 11 8 3 0
0 0000 Rm
offset register
14
Encoding - multiple register data transfers
31 28 27 25 24 23 22 21 20 19 16 15 0
cond 100 P U S W L Rn register list
base register
load/store
write- back (auto-index)
restore PSR and force user bit
up/down
pre-/post-index
Assembler format:
LDM | STM {<cond>} <add> Rn {!}, <regs>
<add> = IA etc, <regs> = {rn,..rm}
Design & Test of Systems-on-a-Chip Winter 2000/2001 29
31 28 27 23 22 21 20 19 16 15 12 11 43 0
cond 0 0 0 1 0 B 0 0 Rn Rd 00001001 Rm
destination register
Assembler format:
SWP {<cond>} {B} Rd, Rm, [Rn]
15
c) Control flow instructions
! Unconditional branches
B LABEL
.. ; these instructions are skipped
LABEL ..
! Conditional branches
MOV r0, #0 ; initialize counter
LOOP ...
ADD r0, r0, #1 ; increment counter
CMP r0, #10 ; compare with limit
BNE LOOP ; repeat if not equal
... ; else continue
! here the branch depends on how CMP sets Z
Branch conditions
Branch Interpretation Normal Uses
16
Conditional execution
! All instructions may be conditional:
CMP r0, #5 ; if (r0 != 5) {
ADDNE r1, r1, r0 ; r1 := r1 + r0 - r2
SUBNE r1, r1, r2 ; }
17
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
MOV pc, r14 ; return
Nested subroutines
! r14 must be saved before the next BL
BL SUB1 ; branch to SUB1
...
SUB1 STMDA r13!, {r0-r2, r14}; save regs
BL SUB2
...
LDMIB r13!, {r0-r2, pc} ; restore regs + return
SUB2 ...
MOV pc, r14 ; return
18
Software Interrupt
! Assembler format:
SWI {<cond>} <24-bit immediate>
! The instruction:
! puts the processor into supervisor mode
! saves the CPSR in SPSR_svc
! sets the PC to 0x8
! Typically used for calls to operating system
functions, e.g.:
SWI SWI_WriteC ; output character in r0
SWI SWI_Exit ; return to monitor
19
Instruction encoding
31 28 27 25 24 23 0
B, BL cond 1 0 1 L 24-bit signed word offset
31 28 27 4 3 0
BX cond 0 0 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 Rm
31 28 27 24 23 0
SWI cond 1111 24-bit ( interpreted ) immediate
d) Special instructions
! Transfer between status register & general
register
MRS{<cond>} Rd, CPSR | SPSR
MSR{<cond>} CPSR | SPSR, #<imm.> | Rm
! Coprocessor instructions
! Data operations
! Depend on coprocessor
! Data transfers, e.g.
LDC p6, c0, [r1]
STC p4, c1, [r2, #4]!
! Register transfers
! More a 32-bit value between the processor and ARM
(including CPSR)
20
6.3. Operating modes and exceptions
21
Registers and modes
ro
r1 usable in user mode
r2
system modes only
r3
r4
r5
r6
r7
r8_fiq
r8
r9_fiq
r9
r10_fiq
r10
r11_fiq
r11 r13_und
r12_fiq r13_irq
r12 r13_abt
r13_svc r14_und
r13_fiq r14_irq
r13 r14_abt
r14_svc
r14_fiq
r14
R15 (PC) SPSR_und
SPSR_irq
SPSR_abt
CPSR SPSR_svc undefined
SPSR_fiq irq
abort mode
svc mode
fiq mode
user mode mode
mode
22
Modes - Summary
23
Exception vector addresses
24
Memory faults
25