Skip to content

MIPS pseudo instructions

Pavel Kryukov edited this page Apr 26, 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:

Name Assembly syntax Expansion Operation in C
Data moves
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
Branches
branch unconditionally b C beq $zero, $zero, C goto PC + 4 + (C << 2)
branch unconditionally and link bal C bgezal $zero, C ra = PC + 8; goto PC + 4 + (C << 2)
branch if greater than bgt $s, $t, C slt $at, $t, $s
bne $at, $zero, C
if (s > t) goto PC + 4 + (C << 2)
branch if less than blt $s, $t, C slt $at, $s, $t
bne $at, $zero, C
if (s < t) goto PC + 4 + (C << 2)
branch if greater than or equal bge $s, $t, C slt $at, $s, $t
beq $at, $zero, C
if (s >= t) goto PC + 4 + (C << 2)
branch if less than or equal ble $s, $t, C slt $at, $t, $s
beq $at, $zero, C
if (s <= t) goto PC + 4 + (C << 2)
branch if greater than unsigned bgtu $s, $t, C sltu $at, $t, $s
bne $at, $zero, C
if (s > t) goto PC + 4 + (C << 2)
branch if zero beqz $s, C beq $s, $zero, C if (s == 0) goto PC + 4 + (C << 2)
Multiplications/Divisions
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
jump register and link to ra jalr $s jalr $s, $ra ra = PC + 4; goto s;
Logical operations
not not $t, $s nor $t, $s, $zero t = ~s
No-operations
nop nop sll $zero, $zero, 0 {}

No-operations

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 in assignments?

Since 2014/2015, you don't have to implement pseudo-instructions output in MIPT-MIPS assignments, 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