Assembly Language Programming

Byte Load and Store

The LDR and STR instructions transfer full words, not individual bytes. The ARM can transfer bytes using the LDRB and STRB instructions.

LDRB r0, [r1] ; load r0 with the byte at memory location pointed to by r1
STRB r0, [r1] ; store the byte held in r0 into the memory location pointed to by r1

The byte chosen for LDRB transfer depends on the memory address. If the address is word aligned, bits 0 to 7 are loaded into the destination register. If the address is word aligned plus one byte, bits 8 to 15 are loaded into the destination register and so on. The chosen bits are loaded into the bottom 8 bits of the destination register and all other bits are set to zero.

In STRB transfer, the bottom 8 bits of the source register are repeated across the entire word as it is sent over the data bus. It is the responsibility of the external memory hardware to ensure that the correct byte is updated.