-
Notifications
You must be signed in to change notification settings - Fork 141
MIPS pseudo instructions
Pavel I. Kryukov edited this page Nov 8, 2017
·
23 revisions
In MIPS, some operations can be performed with help of other instructions. The most common operations are unified in pseudo-instructions — they can be coded in assembly language, and assembler will expand them to real instructions according to following rules:
Name | Assembly syntax | Expansion | Operation in C |
---|---|---|---|
move | move $t, $s |
addiu $t, $s, 0 |
t = s |
clear | clear $t |
addu $t, $zero, $zero |
t = 0 |
load 32-bit immediate | li $t, C |
lui $t, C_hi ori $t, $t, C_lo
|
t = C |
load label address | la $t, A |
lui $t, A_hi ori $t, $t, A_lo
|
t = A |
Name | Assembly syntax | Expansion |
---|---|---|
branch unconditionally | b C |
beq $zero, $zero, C |
branch unconditionally and link |
bal C |
bgezal $zero, C |
branch if greater than | bgt $s, $t, C |
slt $at, $t, $s bne $at, $zero, C
|
branch if less than | blt $s, $t, C |
slt $at, $s, $t bne $at, $zero, C
|
branch if greater than or equal |
bge $s, $t, C |
slt $at, $s, $t beq $at, $zero, C
|
branch if less than or equal |
ble $s, $t, C |
slt $at, $t, $s beq $at, $zero, C
|
branch if greater than unsigned |
bgtu $s, $t, C |
sltu $at, $t, $s bne $at, $zero, C
|
branch if zero | beqz $s, C |
beq $s, $zero, C |
Name | Assembly syntax | Expansion | Operation in C |
---|---|---|---|
multiplicate and return 32 bits |
mul $d, $s, $t |
mult $s, $t mflo $d
|
d = (s * t) & 0xFFFFFFFF |
quotient | div $d, $s, $t |
div $s, $t mflo $d
|
d = s / t |
remainder | rem $d, $s, $t |
div $s, $t mfhi $d
|
d = s % t |
Name | Assembly syntax | Expansion | Operation in C |
---|---|---|---|
jump register and link to ra | jalr $s |
jalr $s, $ra |
ra = PC + 4; goto s; |
Name | Assembly syntax | Expansion | Operation in C |
---|---|---|---|
not | not $t, $s |
nor $t, $s, $zero |
t = ~s |
Name | Assembly syntax | Expansion | Operation in C |
---|---|---|---|
nop | nop |
sll $zero, $zero, 0 |
{} |
In fact, every MIPS instruction that has $zero
as its destination and doesn't touch memory, access I/O system, and/or call a trap, can be treated as a nop
; but using sll $zero, $zero, 0
is the most convinient because it's byte code is all-zeroes 0x00000000
.
Since 2014/2015, all instructions are printed as real MIPS instructions in MIPT-MIPS. Unexpanded pseudo-instructions are left only in testing traces source files (.s
files).
MIPT-V / MIPT-MIPS — Cycle-accurate pre-silicon simulation.