Webcentive RISC-V Reference

sext.b

Sign-extend byte

Extension
Zbb
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
sext.b xd, xs1
Length
32-bit

Encoding

3120191514121176210
011000000100rs1001rd0010011

Match 0x60401013, mask 0xfff0707f. Source: sext.b rd rs1 31..20=0x604 14..12=1 6..2=0x04 1..0=3 in riscv-opcodes/extensions/rv_zbb.

FieldBitsriscv-opcodes name
rs119:15rs1
rd11:7rd

Description

Sign-extends the least-significant byte in the source to XLEN by copying the most-significant bit in the byte (i.e., bit 7) to all of the more-significant bits.

Description from riscv-unified-db, reformatted.

Operation

if (xlen() == 32) {
  X[xd] = {{24{X[xs1][7]}}, X[xs1][7:0]};
} else if (xlen() == 64) {
  X[xd] = {{56{X[xs1][7]}}, X[xs1][7:0]};
}

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages