7 0
B0
B1
B2
B3
31 24 23 16 15 8 7 0
B3 B2 B1 B0
Memory Register
Address A
A+1
l
sbyte
A+2
A+3
msbyte
www.ti.com
Functional Description
61
SWRU543–January 2019
Submit Documentation Feedback
Copyright © 2019, Texas Instruments Incorporated
Cortex
®
-M4 Processor
2.2.3.2 Data Storage
The processor views memory as a linear collection of bytes numbered in ascending order from zero. For
example, bytes 0 to 3 hold the first stored word, and bytes 4 to 7 hold the second stored word. Data is
stored in little-endian format, with the least significant byte (LSByte) of a word stored at the lowest-
numbered byte, and the most significant byte (MSByte) stored at the highest-numbered byte. Figure 2-4
shows how data is stored.
Figure 2-4. Data Storage
2.2.3.3 Synchronization Primitives
The Cortex
®
-M4 instruction set includes pairs of synchronization primitives which provide a nonblocking
mechanism that a thread or process can use to obtain exclusive access to a memory location. Software
can use these primitives to perform an ensured read-modify-write memory update sequence or for a
semaphore mechanism.
A pair of synchronization primitives consists of:
• A load-exclusive instruction, to read the value of a memory location and request exclusive access to
that location.
• A store-exclusive instruction, to try to write to the same memory location and return a status bit to a
register. If this status bit is clear, it indicates that the thread or process gained exclusive access to the
memory and the write succeeds; if this status bit is set, it indicates that the thread or process did not
gain exclusive access to the memory and no write was performed.
The pairs of load-exclusive and store-exclusive instructions are:
• The word instructions LDREX and STREX
• The halfword instructions LDREXH and STREXH
• The byte instructions LDREXB and STREXB
Software must use a load-exclusive instruction with the corresponding store-exclusive instruction. To
perform an exclusive read-modify-write of a memory location, software must:
1. Use a load-exclusive instruction to read the value of the location.
2. Modify the value, as required.
3. Use a store-exclusive instruction to try to write the new value back to the memory location.
4. Test the returned status bit. If the status bit is clear, the read-modify-write completed successfully. If
the status bit is set, no write was performed, which indicates that the value returned at Step 1 might be
out of date. The software must retry the entire read-modify-write sequence.