Books and References © Rance Necaise
Integer ArithmeticChapter 3. MIPS Assembly LanguageInstruction Encodings

Pseudo Instructions

MIPS also provides several instructions that make it easier to program in assembly, but which are not directly translated into a machine code instruction. These are known as pseudo instructions. A pseudo instruction can be used in an assembly language program and is recognized by the assembler. When used, the assembler will convert the pseudo instruction to one or more real machine code instructions. For example, MIPS provides a move instruction

move $t3, $t2

which takes two registers and copies the contents of the second register to the first register. This is a pseudo instruction that is actually implemented using the add instruction

addi $t3, $t2, 0

By including the pseudo instructions, programmers can use instructions that are more familiar to them for common operations without having to remember how to implement those operations.

Question 1.

The load immediate instruction is actually a pseudo instruction that is provided for convenience. How can the li instruction be implemented using a real instruction? That is, given the instruction

li $t2, 58

how would it be implemented using real MIPS instructions?

The li instruction is implemented in MIPS using the add immediate instruction with the $zero register.

addi $t2, $zero, 58
Question 2.

The MIPS neg instruction is also a pseudo instruction. Given the statement

neg $t0, $t1

it negates the value in register $t1 and stores it into register $t0. That is, it performs

$t0 = -$t1

How would this pseudo instruction be implemented using real MIPS instructions?

The neg instruction is implemented in MIPS using the subtraction instruction and the $zero register.

sub $t0, $zero, $t1
Integer ArithmeticChapter 3. MIPS Assembly LanguageInstruction Encodings
Page last modified on September 12, 2021, at 03:01 PM