| |||
| Home > ARM Instruction Reference > ARM memory access instructions > LDR and STR, halfwords and signed bytes | |||
Load register, signed 8-bit bytes and signed and unsigned 16-bit halfwords.
Store register, 16-bit halfwords.
Signed loads are sign-extended to 32 bits. Unsigned halfword loads are zero-extended to 32 bits.
These instructions have four possible forms:
zero offset
pre-indexed offset
program-relative
post-indexed offset.
The syntax of the four forms, in the same order, are:
op{cond}typeRd, [Rn]
op{cond}typeRd, [Rn,Offset]{!}
op{cond}typeRd,label
op{cond}typeRd, [Rn],Offset
where:
opis either LDR or STR.
condis an optional condition code (see Conditional execution).
typemust be one of:
SHfor
Signed Halfword (LDR only)
Hfor unsigned Halfword
SBfor
Signed Byte (LDR only).
Rdis the ARM register to load or save.
Rnis the register on which the memory address is based.
must
not be the sameas Rn,
if the instruction is either:Rd
pre-indexed with writeback
post-indexed.
labelis a program-relative expression. See Register-relative and
program-relative expressions for more information. must
be within ±255 bytes of the current instruction.label
Offsetis an offset applied to the value in (see Offset syntax).Rn
!is
an optional suffix. If ! is present, the address
including the offset is written back into .
You cannot use the Rn! suffix if is
r15.Rn
The offset is applied to the value in before
the transfer takes place. The result is used as the memory address
for the transfer. If the Rn! suffix is used,
the result is written back into .Rn
This is an alternative version of the pre-indexed form. The
assembler calculates the offset from the PC for you, and generates
a pre-indexed instruction with the PC as .Rn
You cannot use the ! suffix.
The value in is
used as the memory address for the transfer. The offset is applied
to the value in Rn after
the transfer takes place. The result is written back into Rn.Rn
Both pre-indexed and post-indexed offsets can be either of the following:
#expr
{-}Rm
where:
-is an optional minus sign. If - is
present, the offset is subtracted from . Otherwise,
the offset is added to Rn.Rn
expris an expression evaluating to an integer in the range –255 to +255. This is often a numeric constant (see examples below).
Rmis a register containing a value to be used as the offset.
The offset syntax is the same for LDR and STR, doublewords.
The address must be even for halfword transfers.
If your system has a system coprocessor (cp15), you can enable alignment checking. Non halfword-aligned 16-bit transfers cause an alignment exception if alignment checking is enabled.
If your system does not have a system coprocessor (cp15), or alignment checking is disabled:
a non halfword-aligned 16-bit load
corrupts Rd
a non halfword-aligned 16-bit save corrupts two bytes at [address] and [address–1].
LDREQSH r11,[r6] ; (conditionally) loads r11 with a 16-bit halfword
; from the address in r6. Sign extends to 32 bits.
LDRH r1,[r0,#22] ; load r1 with a 16 bit halfword from 22 bytes
; above the address in r0. Zero extend to 32 bits.
STRH r4,[r0,r1]! ; store the least significant halfword from r4
; to two bytes at an address equal to contents(r0)
; plus contents(r1). Write address back into r0.
LDRSB r6,constf ; load a byte located at label constf. Sign extend.