bltzpseudo

bltz

pseudo
RISC-V Assembly Reference

lyszt.net covers bltz and other RISC-V instructions in more detail.

Description

Branches to a label when a register holds a negative value. In bltz rs, label, the branch is taken when rs is below zero under the signed reading. Failed calls and subtractions that underflow are its usual cases, and the assembler expands it to blt rs, zero, label.

Expands to

blt rs, zero, label

The assembler replaces this pseudo-instruction with the real instruction or instructions listed above.

Official definition

RISC-V Instruction Set Manual

All branch instructions use the B-type instruction format. The 12-bit B-immediate encodes signed offsets in multiples of 2 bytes. The offset is sign-extended and added to the address of the branch instruction to give the target address. The conditional branch range is ±4 KiB.

Branch instructions compare two registers. BEQ and BNE take the branch if registers rs1 and rs2 are equal or unequal respectively. BLT and BLTU take the branch if rs1 is less than rs2, using signed and unsigned comparison respectively. BGE and BGEU take the branch if rs1 is greater than or equal to rs2, using signed and unsigned comparison respectively. Note, BGT, BGTU, BLE, and BLEU can be synthesized by reversing the operands to BLT, BLTU, BGE, and BGEU, respectively.