Skip to content

Summary Checklist

The summary of all instructions covered in the module are shown below:

Basic

Operation Opcode MipC
Addition add $rd, $rs, $rt $rd = $rs + $rt
Subtraction sub $rd, $rs, $rt $rd = $rs - $rt
Shift Left Logical sll $rd, $rt, C5 $rd = $rt << C5
Shift Right Logical srl $rd, $rt, C5 $rd = $rt >> C5
Bitwise AND and $rd, $rs, $rt $rd = $rs & $rt
Bitwise OR or $rd, $rs, $rt $rd = $rs | $rt
Bitwise XOR xor $rd, $rs, $rt $rd = $rs ^ $rt
Bitwise NOR nor $rd, $rs, $rt currently unavailable

Shift

Note that the second operand is $rt instead of $rs. Additionally, C5 is basically 5-bits unsigned integer. Why only 5-bits? Well, 25 = 32. If we shift left/right 32-bits, we get all 0. So any number greater than 32 is immaterial.

Immediate

Operation Opcode MipC
Addition addi $rt, $rs, C162s $rt = $rs + C162s
Bitwise AND andi $rt, $rs, C16 $rt = $rs & C16
Bitwise OR ori $rt, $rs, C16 $rt = $rs | C16
Bitwise XOR xori $rt, $rs, C16 $rt = $rs ^ C16

Note how the destination register (i.e., $rd) is now changed to target register (i.e., $rt).

Arithmetic

C162s is 16-bits 2s complement (i.e., signed integer). The range is from -215 to 215-1. These values are sign-extended. In other words, we extend it from 16-bits to 32-bits by duplicating the most significant bit (MSB). If the MSB is 0, we append 0 to the front. If the MSB is 1, we append 1 to the front.

Logical

C16 is 16-bits unsigned integer. The range is from 0 to 216-1. However, they are typically given as 16-bit patterns (i.e., 0xAAAA) instead. These values are bit-extended. In other words, we extend it from 16-bits to 32-bits by appending 0.

Memory

Operation Word Byte Unaligned
Load lw $rt, offset($rs) lb $rt, offset($rs) ulw $rt, offset($rs)
Store sw $rt, offset($rs) sb $rt, offset($rs) usw $rt, offset($rs)

Unaligned

Unaligned memory operations are pseudo-instructions. Generally, pseudo-instructions cannot be use for assignments or other assessments unless specified otherwise.

Decision

Conditional

Operation Opcode C with goto and label
Branch on Equal beq $rs, $rt, label if ($rs == rt) goto label;
Branch on Not Equal bnq $rs, $rt, label if ($rs != rt) goto label;
Branch on Less Than blt $rs, $rt, label if ($rs < rt) goto label;
Branch on Greater Than bgt $rs, $rt, label if ($rs > rt) goto label;
Branch on Less Than or Equal ble $rs, $rt, label if ($rs <= rt) goto label;
Branch on Greater Than or Equal bge $rs, $rt, label if ($rs >= rt) goto label;

Italices

The operations written in italics are pseudo-instructions. Generally, pseudo-instructions cannot be use for assignments or other assessments unless specified otherwise.

Unconditional

Operation Opcode C with goto and label
Jump j label goto label;

Summary

Basic MIPS Programming

We will focus mainly on the following for CS2100.

  1. Arithmetic using only registers and possibly immediate values.
    • add, sub
    • addi
  2. Logical using only registers and possibly immediate values.
    • sll, srl, and, or, xor, nor
    • andi, ori, xori
  3. Handling of large constants.
    • ori + sll + ori
    • lui + ori
  4. Memory accesses using load/store.
    • Word: lw and sw
    • Byte: lb and sb
    • Unaligned: ulw and usw
  5. Control flow using conditional branches and unconditional jump.
    • Branch: beq, bne, slt
    • Jump: j
    • Pseudo: blt, bgt, ble, bge
  6. Accessing array elements.
  7. System calls (covered in labs).
    • Print: print_int, print_string
    • Read: read_int, read_string

Out of Scope

We will not cover the following.

  1. Support for procedures.
  2. Linkeds, loaders and memory layout.
  3. Stacks, frames and recursion.
  4. Interrupts and exceptions.

MIPS Interpreter

We have a simple MIPS interpreter implemented. The interpretation allows certain pseudo-instructions to be run directly. In other words, it is not translated into one or more real instructions. You can read on the documentation to know more.

MipC

We use the intermediate language called MipC. This is a simplified C language that only has certain operations to help in compiling to MIPS. The operations are chosen such that they are going to be rather easy to compile to MIPS. The use of MipC is entirely optional but once you are familiar with it, you can try compiling on our MIPS compiler. To learn more about the compilation process, go to the user guide.