6 Addressingmodes
6 Addressingmodes
Chapter 6
Sepehr Naimi
www.NicerLand.com
Topics
• Alignment
• Little endian vs. Big endian
• Advanced Indexed Addressing Modes
• LDR pseudo-instruction & PC relative addressing
• Bit-addressable memory
2
ARM Memory
3
Alignment and misalignment
4
16-bit data and memory alignment
5
Little endian vs. Big endian
LDR R2, =0x7698E39F
; R2=0x7698E39F
LDR R1, =0x80000000
STR R2, [R1]
• Little endian
• Big endian
6
Advanced indexed
addressing modes
7
Advanced Indexed Addressing Modes
• Pre-indexed addressing
– with Fixed Offset
– with Offset register
– With scaled offset register
• Pre-indexed with write-back
– With fixed offset
• Post-indexed addressing
– With fixed offset
8
Pre-indexed Addressing Mode with Fixed Offset
EXPORT __main
AREA LOOKUP_EXAMP_6_16, READONLY, CODE
__main
LDR R1, =LOOKUP ; point to LOOKUP
LDR R3, [R1, R2, LSL #2] ; R3 = entry of lookup table index by R2
11
Pre-indexed Addressing mode with write-
back and fixed offset
• LDR Rd, [Rm, k]!
• STR Rd, [Rm, k]!
12
Post-indexed Addressing mode
• LDR Rd, [Rm], #k
• STR Rd, [Rm], #k
13
LDR and ADR Pseudo-
instructions and PC
Relative addressing
14
PC Relative addressing
• LDR Rd, [PC, #k]
15
LDR Pseudo-instruction
EXPORT __main
AREA EXAMPLE, READONLY, CODE
__main
LDR R0, =0x12345678
LDR R1, =0x86427531
ADD R2, R0, R1
H1 B H1
END
16
ADR Pseudo-instruction
• ADR Rn, Label
– ADD Rn, PC, #offset
17
ADR Pseudo-instruction Example
EXPORT __main
AREA LOOKUP_EXAMPLE, READONLY, CODE
__main
ADR R2, OUR_FIXED_DATA ; R2 points to OUR_FIXED_DATA
LDRB R0, [R2] ; load R0 with the contents
; of memory pointed to by R2
ADD R1, R1, R0 ; add R0 to R1
HERE B HERE ; stay here forever
OUR_FIXED_DATA
DCB 0x55, 0x33, 1, 2, 3, 4, 5, 6
END
18
Bit-addressable
Memory
19
SRAM bit-addressable Memory
Bit alias address = Bit alias base address + Byte offset × 32 + Bit number × 4
20
Peripheral bit-addressable region
21