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.
RV32IRV64IArithmeticCompare

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.

SLTI Decode And Execute Animation

Starts with machine-code field decoding, then shows operand reads, instruction-specific execution, and ISA-visible state update.

rd
rs1
imm
slti
,
,
Execution Context
a6(x16)
0xFFFFFFF0
31..20
19..15
14..12
11..7
6..0
000000001010
imm[11:0]
10000
rs1
010
funct3
00101
rd
0010011
opcode
Execution Data Path
instruction
0x00A82293
opcode
0010011 -> OP-IMM
funct3
010 -> SLTI
rd / rs1
t0(x5) / a6(x16)
imm[11:0]
imm[11:0]=000000001010 -> sign_extend=0x0000000A (signed)
compare
signed: 0xFFFFFFF0 (-16) < 0x0000000A (10) -> 1
x5
t0(x5) = 0x00000001
Current Step

Concept Step: receive the 32-bit instruction encoding

The machine code is split by the current instruction format; the animation starts from encoding/decode.

encoding: 0x00A82293
syntax : slti t0(x5), a6(x16), 10
result : t0(x5) = 0x00000001
Architectural Result
t0(x5) = 0x00000001

This animation shows ISA-visible decode and state changes, not any specific CPU pipeline, cache, prediction, or timing implementation.

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

Comparison & Detection

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

Pre-Use Checklist

Syntax Check
  • Verify the immediate field is within the valid range.
  • Confirm source register rs1 points to the correct operand.
Semantic Check
  • Check if the immediate sign-extension matches expectations.
  • Ensure the result register rd has a clear purpose.

Pitfalls / Common Confusions

Result is boolean (0 or 1), not difference sign
Immediate is sign-extended before comparison
With rd=x0, SLTI is a HINT and does not perform the normal destination-register update.

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.