SEXT.B

RISC-V SEXT.B Instruction Details

Instruction ManualR-type

Sign-extend byte

Instruction Syntax

sext.b rd, rs1
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
BZbbBit ManipulationInteger Operation

Instruction Behavior

Sign-extends the least-significant 8 bits of rs to XLEN. Replaces slli+srai (sign-ext) or slli+srli (zero-ext) sequences. Part of Zbb.

Quick Understanding & Search Notes

SEXT.B is a B/Zbb instruction for sign-extend low byte. This page is checked against the official B extension semantics, with emphasis on XLEN, W suffixes, .uw suffixes, and bitwise or rotate boundaries.

Only the low 8 bits are read and bit 7 is sign-extended.
It is not zero-extension; use masking or an appropriate zero-extension form for unsigned bytes.

Common Usage Scenarios

Bit Operations & Masks

Understand this scenario with real code like «sext.b x10, x11 ; x10 = sign_ext(x11[7:0])».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is R-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

Pitfalls / Common Confusions

Only extends lower 8 bits

FAQ

Does SEXT.B access memory?

No. It only reads and writes integer registers; any memory access must be performed by a separate load or store instruction.

What is the result width of SEXT.B?

Except that W-suffixed forms produce a 32-bit result then sign-extend and .uw forms first extract a 32-bit unsigned operand, the result is written to rd at XLEN width.