Home/Instructions/Set Less Than Immediate
SLTI

RISC-V SLTI Instruction Details

Instruction ManualI-type

Set rd to 1 if rs1 is less than the immediate (signed), else 0

Instruction Syntax

slti rd, rs1, imm
Operand Breakdown
Destination rd: general-purpose register receiving the result.
Source rs1: register holding the first operand.
Immediate imm: 12-bit signed value, sign-extended before operation with rs1.
RV32IArithmeticCompare

Instruction Encoding

31..20
imm[11:0]
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

SLTI uses opcode 0010011 (0x13), funct3 010. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.

Format: I-type
opcode: 0010011 (0x13)
funct3: 010 (0x2)

Instruction Behavior

SLTI (signed) compares rs1 with the sign-extended 12-bit immediate, setting rd to 1 if rs1 < imm (signed), else 0. Used for single-step comparison and range checking in loops.

Quick Understanding & Search Notes

SLTI performs signed comparison rs1 < imm; rd is set to 1 when true and 0 otherwise. It turns a comparison result into an integer value usable by later arithmetic or branches.

The immediate form uses a sign-extended 12-bit immediate.
Signed and unsigned comparisons differ in how the bit patterns are interpreted, not in register width.

Common Usage Scenarios

Branch & Jump

Understand this scenario with real code like «slti x5, x6, 10 # x5 = (x6 < 10) ? 1 : 0 (signed)».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is I-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

Result is boolean (0 or 1), not difference sign
Immediate is sign-extended before comparison

FAQ

What value does SLTI write?

It writes 1 when the comparison is true, otherwise 0.

What is the difference between SLT and SLTU?

SLT/SLTI compare as signed integers; SLTU/SLTIU compare as unsigned integers.