From Wikibooks, the open-content textbooks collection
[edit] Jump Instruction
The jump instructions load a new value into the IP register. This causes the next instruction read from memory to be retrieved from the new location.
The j instruction loads an immediate value into the IP register. This immediate value is either a numeric offset or a label (and the assembler converts the label into an offset).
The jr instruction loads the IP register with a value stored in a register. As such, the jr instruction can be called as such:
jr $t0
assuming the target jump location is located in $t0.
[edit] Jump and Link
Jump and Link instructions are similar to the jump instructions, except that they store a return address in the $ra ($31) register. This allows a subroutine to return to the main body routine after completion.
Like the j instruction, except that the return address is loaded into the $ra register.
|
Instruction:
|
jalr |
type:
|
R Type |
The same as the jr instruction, except that the return address is loaded into the $ra register.
[edit] Example
Let's say that we have a subroutine that starts with the label MySub. We can call the subroutine using the following line:
jal MySub
...
And we can define MySub as follows to return to the main body of the parent routine:
jr $ra
[edit] Branch Instructions
|
Instruction:
|
blez |
type:
|
I Type |
|
Instruction:
|
bgtz |
type:
|
I Type |
[edit] Set Instructions
|
Instruction:
|
slti |
type:
|
I Type |
|
Instruction:
|
sltu |
type:
|
R Type |
|
Instruction:
|
sltiu |
type:
|
I Type |