slti
slti
rd, rs1, imm
rd = (rs1 < imm) ? 1 : 0
R
31–25funct7
24–20rs2
19–15rs1
14–12funct3
11–7rd
6–0opcode
I
31–20imm[11:0]
19–15rs1
14–12funct3
11–7rd
6–0opcode
S
31–25imm[11:5]
24–20rs2
19–15rs1
14–12funct3
11–7imm[4:0]
6–0opcode
B
31–25imm[12,10:5]
24–20rs2
19–15rs1
14–12funct3
11–7imm[4:1,11]
6–0opcode
U
31–12imm[31:12]
11–7rd
6–0opcode
J
31–12imm[20,10:1,11,19:12]
11–7rd
6–0opcode

slti compares a register against a constant and sets the destination to 1 or 0. It is slt (compare two registers, store the yes/no answer as a number — see that page) with the second value supplied as an immediate, a constant written into the instruction itself, which the i suffix marks.

The form is slti rd, rs1, imm: if the value in rs1 is less than the constant imm, write 1 into rd, otherwise 0. The comparison is signed, so the constant and the register are both read as numbers that may be negative.

This is the natural tool whenever you are comparing a variable against a fixed threshold known in advance. Checking whether an index is below 10, or whether a value has dropped under some limit, is a single slti. A particularly common case: slti t1, t0, 0 asks is t0 less than zero, which is simply a test for whether t0 is negative — it sets t1 to 1 for negative values and 0 otherwise.

The constant is limited to the range -2048 to 2047. To compare against something larger, first load the constant into a register with li, then use the register form slt. The assembler will not quietly trim an out-of-range constant; it rejects it, so you find out immediately.