Module 2 (Lecture 3)
Module 2 (Lecture 3)
SYSTEMS (17EC62)
1
4. Special instructions
Assembler Language: Instruction Barrier and Memory Barrier Instructions
ISB instruction should be used after updating the value of the CONTROL register.
DMB is very useful for multi-processor systems.
Barrier Instructions
Instruction Description
DMB Data memory barrier; ensures that all memory accesses are completed before new
memory access is committed\
Data synchronization barrier; ensures that all memory accesses are completed before
DSB
next instruction is executed
ISB Instruction synchronization barrier; flushes the pipeline and ensures that all previous
instructions are completed before executing new instructions
Assembly Language: Saturation Operations
The Cortex-M3 supports two instructions that provide signed and unsigned
saturation operations: SSAT and USAT (for signed data type and unsigned data
type, respectively).
Saturation is commonly used in signal processing—for example, in signal
amplification.
When an input signal is amplified, there is a chance that the output will be larger than
If the value is adjusted simply by removing the unused MSB, an overflowed result will
the allowed
cause output
the signal range. to be completely deformed.
waveform
The saturation operation does not prevent the distortion of the signal, but at least the
amount of distortion is greatly reduced in the signal waveform.
Assembly Language: Saturation Operations
Saturation Instructions
Instruction Description
SSAT.W <Rd>, #<immed>, <Rn>,
{,<shift>} Saturation for signed value
USAT.W <Rd>, #<immed>, <Rn>, Saturation for a signed value into an
{,<shift>} unsigned value
Shift: Shift operation for input value before saturation; optional, can be #LSL N or
#ASR N Immed: Bit position where the saturation is carried out Rd: Destination
register
Besides the destination register, the Q-bit in the APSR can also be affected by
the result. The Q flag is set if saturation takes place in the operation, and it can
be cleared by writing to the APSR
For example, if a 32-bit signed value is to be saturated into a 16-bit signed
value, the following instruction can be used:
SSAT.W R1, #16, R0
Similarly, if a 32-bit unsigned value is to saturate into a 16-bit unsigned value,
• For example, the following code can be used to set up the process stack
pointer:
LDR R0,=0x20008000 ; new value for Process Stack Pointer (PSP)
MSR PSP, R0
Several Useful Instructions in the Cortex-M3
REV reverses the byte order in a data word, and REVH reverses the byte order
REV and REVH are particularly useful for converting data between big
endian
and little endian.
REVSH is similar to REVH except that it only processes the lower half word,
and then it sign extends the result.
• For example, if R0 is 0x33448899, running:
SXTB, SXTH, UXTB, AND UXTH:
• The four instructions SXTB, SXTH, UXTB, and UXTH are used to extend
a byte or half word data into a word.
For SXTB/SXTH, the data are sign extended using bit[7]/bit[15] of Rn. With
UXTB and UXTH, the value is zero extended to 32-bit.
Bit Field Clear (BFC) : Clears 1-31 adjacent bits in any position of a register.
The syntax of the instruction is as follows:
BFC.W <Rd>, <#lsb>, <#width>
• For example,
LDR R0,=0x 1234FFFF BFC.W R0, #4, #8
This will give R0 = 0x1234F00F.
Bit Field Insert (BFI): Copies 1-31 bits (#width) from one register to any location
(#lsb) in another register.
The syntax is as follows:
BFI.W <Rd>, <Rn>, <#lsb>, <#width>
• For example,
LDR R0,=0x12345678
LDR R1,=0x3355AACC
BFI.W R1, R0, #8, #16 ; Insert R0[15:0] to R1[23:8]
This will give R1 = 0x335678CC.
UBFX and SBFX:
UBFX and SBFX are the unsigned and signed bit field extract instructions.
The syntax of the instructions is as follows:
UBFX.W <Rd>, <Rn>, <#lsb>, <#width>
SBFX.W <Rd>, <Rn>, <#lsb>, <#width>
UBFX extracts a bit field from a register starting from any location (specified by #lsb)
with any width (specified by #width), zero extends it, and puts it in the destination
register. For example,
LDR R0,=0x5678ABCD
UBFX.W R1, R0, #4, #8
This will give R1 = 0x000000BC.
Similarly, SBFX extracts a bit field, but its sign extends it before putting it in a
destination register. For example,
LDR R0,=0x5678ABCD
SBFX.W R1, R0, #4, #8
This will give R1 = 0xFFFFFFBC.
LDRD and STRD:
The two instructions LDRD and STRD transfer two words of data from or into two
table
of half word offset.
Since the bit 0 of a program counter is always zero, the value in the branch table is
multiplied by two before it’s added to PC.
Furthermore, because the PC value is the current instruction address plus four,
the branch range for TBB is (2 x 255) + 4 = 514, and
the branch range for TBH is (2 x 65535) + 4 = 131074.
Both TBB and TBH support forward branch only. TBB has this general syntax:
TBB.W [Rn, Rm]
where Rn is the base memory offset and Rm is the branch table index.
Table Branch Byte and Table Branch Halfword
TBB Operation
Table Branch Byte and Table Branch Halfword
For TBH instruction, the process is similar except the memory location of the
branch table item is located at Rn + 2 x Rm and the maximum branch offset is
higher. Again, we assume that Rn is set to PC.
If Rn in the table branch instruction is set to R15, the value used for Rn will be
TBH Operation
These two instructions are more likely to be used by a C compiler to generate code for
switch (case) statements.
Miscellaneous Instruction
Other 16-Bit Instructions
Instruction Function
SVC Supervisor call
NOP No operation
Enable PRIMASK (CPSIE i)/FAULTMASK (CPSIE f ) register (set the
CPSIE
register to 0)
Disable PRIMASK (CPSID i)/ FAULTMASK (CPSID f ) register (set the
CPSID
register to 1)
Miscellaneous Instruction
Other 32-Bit Instructions
Instruction Function
Instruction Function
STREXH Exclusive store half word WFE Sleep and wait for event
STREXB Exclusive store byte WFI Sleep and wait for interrupt
CLREX Clear the local exclusive access ISB Instruction synchronization barrier
record of local processor
DSB Data synchronization barrier
MRS Move special register to general-
purpose register DMB Data memory barrier
Thank You