Since registers are referred to by almost all instructions, there must be a convention to map register names into numbers. MIPS software follows the following convention for procedure calling in allocating its 32 registers:
Figure 2.1 MIPS register conventions.
MIPS assembly language includes two decision-making instructions, similar to an if
statement with a go to.
The beq
instruction is called branch if equal.
beq register1, register2, L1
This instruction means go to the statement labeled L1
if the value in register1
equals the value in register2
.
The bne
instruction is called branch if not equal.
bne register1, register2, L1
It means go to the statement labeled L1
if the value in register1
does not equal the value in register2
.
The test for equality or inequality is probably the most popular test, but sometimes it is useful to see if a variable is less than another variable, like a for
loop.
The slt
instruction is called set on less than.
slt $t0, $s3, $s4
The instruction means that register $t0
is set to 1
if the value in register $s3
is less than the value in register $s4
— otherwise, register $t0
is set to 0
.
It also includes an instruction just for the procedures: it jumps to an address and simultaneously
saves the address of the following instruction in register $ra
— return address.
The jal
instruction
jal ProcedureAddress
The jr
instruction jumps to the address stored in register $ra
— which is just what we want.
jr $ra