Académique Documents
Professionnel Documents
Culture Documents
to register
Register to memory
Load/Store Instructions
Load/Store Instructions
The
Load
LDR
Syntax:
<LDR|STR>{<cond>}{<size>}
Rd, <address>
Memory
STR Word
STRB Byte
STRH Halfword
Signed byte load
Signed halfword load
Syntax:
LDR{<cond>}{<size>}
Rd, <address>
STR{<cond>}{<size>} Rd, <address>
e.g. LDREQB
Computer
Processor
Control
brain
Datapath
Registers
Memory
Devices
Input
Store (to)
Load (from)
Output
r0-r15
Memory address: more difficult
Think of memory as a single onedimensional array, so we can address it
simply by supplying a pointer to a memory
address.
Other times, we want to be able to offset
from this pointer.
Example:
specifies
[r0]
Instruction Syntax:
1 2, [3]
where
1) operation name
2) register that will receive value
3) register containing pointer to memory
ARM
Instruction Name:
LDR
Example:
LDR r0,[r1]
This instruction will take the pointer in r1, and then load the
value from the memory pointed to by this calculated sum
into register r0
Notes:
r1
Example:
STR r0,[r1]
Memory
r0
Source
Register
for STR
Base
Register
;
;
;
;
0x5
r1
0x200
r2
0x200
0x5
0x5
Destination
Register
for LDR
Instruction Syntax:
2,[3,#4]
where
1) operation name
2) register that will receive value
3) register containing pointer to memory
4) numerical offset in bytes
LDR r0,[r1,#12]
STR r0,[r1,#-8]
r1
0x200
Memory
0x20c
r0
0x5
Source
Register
for STR
0x5
0x200
Original
Base
Register
r1
0x20c
r1
Memory
r0
Offset
12
0x5
0x20c
0x200
Source
Register
for STR
0x5
0x200
1
* If we want to step through every
0
element of the array, for instance
r0
to produce sum of elements in the
array, then we can use post-indexed addressing within a loop:
r1 is address of current element (initially equal to r0).
LDR r2, [r1], #4
4
0
Rn
temp
2
3
Memory
Rm
Rd
Memory[1], Memory[2],
Computers
Memory[4], Memory[8],
Compile
1st
Next
Called Alignment:
Compiler
Smaller
is faster:
registers are faster than memory
Registers more versatile:
Conclusion
is byte-addressable, but LDR and STR
access one word at a time.
A pointer (used by LDR and STR) is just a
memory address, so we can add to it or subtract
from it (using offset).
Memory
Conclusion
Instructions
so far:
Previously:
ADD,
AND,
MOV,
LSL,
CMP,
New: