bgtpseudo

bgt

pseudo
RISC-V Assembly Reference

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

Description

Branches to a label when one signed value is greater than another. In bgt rs1, rs2, label, the branch is taken when rs1 is above rs2. The assembler expands it to blt with the operands reversed.

Expands to

blt rs2, rs1, 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.