Atmel SAM4S-XPLD Atmel ATSAM4S-XPLD ATSAM4S-XPLD Hoja De Datos

Los códigos de productos
ATSAM4S-XPLD
Descargar
Página de 1125
 102
SAM4S [DATASHEET]
11100E–ATARM–24-Jul-13
12.6.4.8 LDREX and STREX
Load and Store Register Exclusive.
Syntax
LDREX{condRt, [Rn {, #offset}]
STREX{condRdRt, [Rn {, #offset}]
LDREXB{condRt, [Rn]
STREXB{condRdRt, [Rn]
LDREXH{condRt, [Rn]
STREXH{condRdRt, [Rn]
where:
cond
Rd
is the destination register for the returned status.
Rt
is the register to load or store.
Rn
is the register on which the memory address is based.
offset
is an optional offset applied to the value in Rn
If offset is omitted, the address is the value in Rn.
Operation
LDREX, LDREXB, and LDREXH load a word, byte, and halfword respectively from a memory address.
STREX, STREXB, and STREXH attempt to store a word, byte, and halfword respectively to a memory address. The
address used in any Store-Exclusive instruction must be the same as the address in the most recently executed Load-
exclusive instruction. The value stored by the Store-Exclusive instruction must also have the same data size as the value
loaded by the preceding Load-exclusive instruction. This means software must always use a Load-exclusive instruction
and a matching Store-Exclusive instruction to perform a synchronization operation, see 
.
If an Store-Exclusive instruction performs the store, it writes 0 to its destination register. If it does not perform the store, it
writes 1 to its destination register. If the Store-Exclusive instruction writes 0 to the destination register, it is guaranteed
that no other process in the system has accessed the memory location between the Load-exclusive and Store-Exclusive
instructions.
For reasons of performance, keep the number of instructions between corresponding Load-Exclusive and Store-
Exclusive instruction to a minimum. 
The result of executing a Store-Exclusive instruction to an address that is different from that used in the preceding Load-
Exclusive instruction is unpredictable.
Restrictions
In these instructions:
Do not use PC
Do not use SP for Rd and Rt
For STREX, Rd must be different from both Rt and Rn
The value of offset must be a multiple of four in the range 0-1020.
Condition Flags
These instructions do not change the flags.
Examples
    MOV     R1, #0x1            ; Initialize the ‘lock taken’ value try
    LDREX   R0, [LockAddr]      ; Load the lock value
    CMP     R0, #0              ; Is the lock free?
    ITT     EQ                  ; IT instruction for STREXEQ and CMPEQ
    STREXEQ R0, R1, [LockAddr]  ; Try and claim the lock