Skip to content

MIPS pseudo instructions

Pavel Kryukov edited this page Jun 20, 2017 · 23 revisions

Pseudo-instructions

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:

Data moves

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 address la $t, C lui $at, 0x1001
ori $t, $at, C
t = 0x10010000 I C

Branches

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

Multiplication/Division

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

Jumps

Name Assembly syntax Expansion Operation in C
jump register and link to ra jalr $s jalr $s, $ra ra = PC + 4; goto s;

Logical operations

Name Assembly syntax Expansion Operation in C
not not $t, $s nor $t, $s, $zero t = ~s

No-operations

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 access memory and/or I/O system, 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.


Shall I implement pseudo-instructions

Since 2014/2015, you don't have to implement pseudo-instructions output in MIPT-MIPS, all instructions must be printed as real MIPS instructions. Unexpanded pseudo-instructions are left only in testing traces source files (.s files).

Clone this wiki locally