I repeat the (summary of the) material here for review (and reminder).
Syntax Meaning of the instruction ---------------- -------------------------------------------------- ldr rN, [rM] Load 4 bytes from memory at the address given in rM into the (destination) register rN The 4 bytes are stored in the register as follows: ldrsh rN, [rM] Load 2 bytes from memory at the address given in rM into the (destination) register rN AND fill the left half of register with the sign bit The 2 bytes are stored at the right and then sign extended to 32 bits: ldrsb rN, [rM] Load 1 byte from memory at the address given in rM into the (destination) register rN AND fill the left 3/4 of register with the sign bit The byte is stored at the right and then sign extended to 32 bits: |
Syntax Meaning of the instruction ---------------- -------------------------------------------------- str rN, [rM] Store 4 bytes from register rN to memory (consecutively) at the address given in register rM The 4 bytes are taken from the register as follows: strh rN, [rM] Store 2 bytes from register rN to memory (consecutively) at the address given in register rM The 2 bytes are taken from the register as follows: strb rN, [rM] Store 1 byte from register rN to memory (consecutively) at the address given in register rM The byte is taken from the register as follows: |
Although the basic form is sufficient to access simple variable, it is not adequate when we need to compute the address of an array element using:
address of array element A[i] = base address (A) + i×size(one array element) |
Syntax and meaning of the base+offset form of the load register instruction is:
Syntax Meaning of the instruction ---------------- -------------------------------------------------- ldr rN, [rM,off] Load 4 bytes from memory at the address given by rM+off into the (destination) register rN The 4 bytes are stored in the register as follows: ldrsh rN, [rM,off] Load 2 bytes from memory at the address given by rM+off into the (destination) register rN AND fill the left half of register with the sign bit The 2 bytes are stored at the right and then sign extended to 32 bits: ldrsb rN, [rM,off] Load 1 byte from memory at the address given by rM+off into the (destination) register rN AND fill the left 3/4 of register with the sign bit The byte is stored at the right and then sign extended to 32 bits: |
For offset, you can use:
|
How to use the base + offset form of the load instruction to access array elements:
|
Syntax and meaning of the base+offset form of the store register instruction is:
Syntax Meaning of the instruction ---------------- -------------------------------------------------- str rN, [rM,off] Store 4 bytes from register rN to memory (consecutively) at the address given by the sum rM+off The 4 bytes are taken from the register as follows: strh rN, [rM,off] Store 2 bytes from register rN to memory (consecutively) at the address given by the sum rM+off The 2 bytes are taken from the register as follows: strb rN, [rM,off] Store 1 byte from register rN to memory (consecutively) at the address given by the sum rM+off The byte is taken from the register as follows: |
For offset, you can use:
|
How to use the base + offset form of the store instruction to update an array element:
|