sbfx
Signed Bit Field Extract (Thumb)
SBFX <Rd>, <Rn>, #<lsb>, #<width>
Extracts and sign-extends bits.
Details
Signed Bit Field Extract: Extracts a bit field from Rn starting at bit position lsb with width width, sign-extends the result, and writes it to Rd. The condition flags are not affected. This instruction is available in Thumb state (T32) and A32.
Pseudocode Operation
lsb_val ← ZeroExtend(imm3:imm2, 6)
width_val ← ZeroExtend(width, 5)
msb ← lsb_val + width_val - 1
extracted ← (Rn >> lsb_val)[width_val-1:0]
if extracted[width_val-1] == 1 then
Rd ← SignExtend(extracted, 32)
else
Rd ← ZeroExtend(extracted, 32)
Example
SBFX r0, r1, #0, #width
Encoding
Binary Layout
11110
0
11
01
0
0
Rn
0
imm3
Rd
imm2
0
widthm1
Operands
-
Rd
Destination general-purpose register -
Rn
First source / base general-purpose register
Reference (Arm AArch32 ISA)
Instruction Forms
| Encoding | Instruction | ISA | Bit pattern | ||
|---|---|---|---|---|---|
| 0x07A00050 | SBFX{<c>}{<q>} <Rd>, <Rn>, #<lsb>, #<width> | A32 | cond | 01111 | 0 | 1 | widthm1 | Rd | lsb | 101 | Rn | ||
| 0xF3400000 | SBFX{<c>}{<q>} <Rd>, <Rn>, #<lsb>, #<width> | T32 | 11110 | 0 | 11 | 01 | 0 | 0 | Rn | 0 | imm3 | Rd | imm2 | 0 | widthm1 |
Description
Signed Bit Field Extract extracts any number of adjacent bits at any position from a register, sign-extends them to 32 bits, and writes the result to the destination register.
Operation
if ConditionPassed() then
EncodingSpecificOperations();
R[d] = SignExtend(R[n]<msbit:lsbit>, 32);