MIPS Assembly/Pseudoinstructions

The MIPS instruction set is very small, so to do more complicated tasks we need to employ assembler macros called pseudoinstructions.

List of Pseudoinstructions

edit

The following is a list of the standard MIPS instructions that are implemented as pseudoinstructions:

  • abs
  • blt
  • bgt
  • ble
  • neg
  • negu
  • not
  • bge
  • li
  • la
  • move
  • sge
  • sgt


Branch Pseudoinstructions

edit

Branch if less than (blt)

The blt instruction compares 2 registers, treating them as signed integers, and takes a branch if one register is less than another.

blt $8, $9, label

translates to

slt $1, $8, $9
bne $1, $0, label

Other Pseudoinstructions

edit

Load Immediate (li)

The li pseudo instruction loads an immediate value into a register.

li $8, 0x3BF20

translates to

lui $at, 0x0003
ori $8, $at, 0xBF20


Absolute Value (abs)

The absolute value pseudo instruction loads the absolute value contained in one register into another register.

abs $1, $2

translates to

addu $1, $2, $0
bgez $2, 8 (offset=8 → skip 'sub' instruction)
sub $1, $0, $2

Move (move)

The move pseudo instruction moves the contents of the second register operand into the first register operand.

move $1, $2

translates to

add $1, $2, $0

Load Address (la)

la $a0,address

translates to

  lui $at, 4097 (0x1001 → upper 16 bits of $at).
  ori $a0,$at,disp 

where the immediate (“disp”) is the number of bytes between the first data location (always 0x 1001 0000) and the address of the first byte in the string.


Set on greater than or equal (sge)

The sge instruction compares 2 registers, treating them as signed integers, and sets a given register($1) if the value of the 1st register($8) >= the value of the 2nd register($9), else the given register($1) == 00.

sge $1, $8, $9

translates to

addiu $9, $9, -0x01
slt $1, $9, $8