March 18

SLT MIPS: Set If Less Than Instruction

0  comments

Slt is a MIPS Assembly instruction stand for “Set If Less Than”. Slt in MIPS is used for a specific condition like if one value is less than another value then set the value of a particular register. It can be used with both register or can be used with an immediate value(Slti). 

slt Mips pic example

  • The general form of SLT is: slt $t0, $f1, $f2

$t0 is the register of which value will be set to 1 if $f1 is less than $f2, else it will be zero.

  • The general form of SLTI is: slti $t0, $f1, 5

$t0 register will be set to 1 if the value in $f1 is greater than 5, else it will remain zero.

To get the better understanding of slt instruction(opcode) in Mips try the below program on your computer.

PROGRAM:

.data
.text

li $t1,6
li $t2,10

slt $t0,$t1,$t2

bgtz $t0, Exit
Add $t1,$t1,$t2

li $v0,1
Move $a0,$t1
syscall

Exit:
li $v0,10
syscall

EXPLANATION:

In the above example program of slt we have initialized two registers $t1 and $t2 with values and then we applied the instruction of slt. As $t1 is less than $t2, one will be stored in $t0. Then we applied the condition to check the value in $t0 as it is greater than zero so control will be moved downward and addition will be performed.


Tags


You may also like