Branch Instruction - muneeb-mbytes/computerArchitectureCourse GitHub Wiki

Pseudo-instructions

Pseudo-instructions do not have a direct hardware implementation. They are provided as a convenience for the programmer. When pseudo-instructions are used the assembler translates them into equivalent real instructions.

Branch if less than (blt)

blt is a pseudo instruction that compares 2 registers, treating them as signed integers, and takes the label if one register is less than another register.

Example:

blt $8, $9, label

This is equivalent to two real instructions.

slt $1, $8, $9               # If $8 is less that $9 then $1 is set to 1

bne $1, $0, label.           # $1 is not equal to $0 label is executed 

Note : Register $0 always contains the value 0.

C CODE

    if(i<n) goto L;

MIPS CODE

    blt $s0, $zero, L          # Checks if $s0 is less than zero

RISC-V CODE

    blt s0, zero               # Checks if s0 is less than zero

ARM CODE

    CMP X0, XZR    # Compare X0 with zero (XZR is the zero register)
    BLT L                  # Branch to L if X0 is less than zero