Home/Instructions/Set Less Than
SLT

RISC-V SLT Instruction Details

Instruction ManualR-type

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

Instruction Syntax

slt rd, rs1, rs2
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
RV32IArithmeticCompare

Instruction Encoding

31..25
funct7
24..20
rs2
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

SLT uses opcode 0110011 (0x33), funct3 010, funct7 0000000. The rs1 and rs2 fields select the two source registers, and rd selects the destination register.

Format: R-type
opcode: 0110011 (0x33)
funct3: 010 (0x2)
funct7: 0000000 (0x00)

Instruction Behavior

SLT (R-type) compares rs1 and rs2 as signed integers, setting rd to 1 if rs1 < rs2, else 0. funct7=0000000, funct3=010. Produces a boolean result, used to implement signed comparison logic and branch condition preparation. SLT + BNE can implement any conditional branch.

Quick Understanding & Search Notes

SLT performs signed comparison rs1 < rs2; 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 register form compares rs1 with rs2.
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 «slt x5, x6, x7 # x5 = (x6 < x7) ? 1 : 0 (signed)».

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

Result is boolean (0 or 1), not the difference value
Use SLTU for unsigned comparison

FAQ

What value does SLT 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.