Assembly Language Programming
Register-Indirect Addressing
Register-Indirect addressing is perhaps the simplest of ARM's addressing modes.
Register-indirect addressing in action
To load a value from memory into a register using register-indirect addressing, we use a second register, known as the base register. This base register holds the actual memory address that the program is interested in. The LDR instruction inspects the base register, interprets its value as the memory address, fetches the value stored at that memory location, and then loads it into a destination register.
LDR | r0, [r1] | ; r0 receives the value held at the memory address pointed to by r1 |
; r0 is the destination register, r1 is the base register |
To store a value to memory from a register using register-indirect addressing, a base register is again employed to hold the actual memory address. The STR instruction inspects the base register, interprets its value as a memory address location, and places the value held in the source register into the memory location.
STR | r0, [r1] | ; the memory location pointed to by r1 receives the value held in r0 |
; r0 is the source register, r1 is the base register |