Skip to content

MIPS Basis

1. Introduction

CISC: complex instruction set computer; e.g. x86-64

RISC: reduced instruction set computers

MIPS: Microprocessor without Interlocked Pipeline Stages; a typical RISC

5-Stage Pipeline

  • Fetch instruction
  • Read registers
  • Arithmetic operation
  • Memory access
  • Write back

Compare to x86-64

Screen Shot 2021-08-25 at 10.16.32 PM

Screen Shot 2021-08-25 at 10.19.22 PM

Screen Shot 2021-08-25 at 10.20.20 PM

Branch Delay Slot is visible too software to provide the possibility of optimization at upper-level:

Screen Shot 2021-08-25 at 10.23.26 PM

No branch prediction!

2. Registers

There are 32 general-purpose registers for your program to use: $0 to $31.

  • $0 Always returns zero, no matter what you store in it.
  • $31 Is always used by the normal subroutine-calling instruction jal for the return address.
    • jalr can use any register for the return address

The floating-point math coprocessor (floating-point accelerator, or FPU), if available, adds 32 floating-point registers; in simple assembly language, they are called $f0 to $f31.

Screen Shot 2021-08-26 at 12.49.31 AM

3. Passing Arguments

Screen Shot 2021-09-07 at 5.09.08 PM

Screen Shot 2021-08-26 at 10.35.57 AM

4. Data Types

Screen Shot 2021-08-26 at 9.58.08 AM

5. Coprocessor 0

Screen Shot 2021-09-07 at 5.05.38 PM

mtc0    <register s of CPU>, <n_th register of CP0> # Move to coprocessor 0
mfc0    d, $n   # d is loaded with the values from CPU control register number n
mfc0    t0, SR  # Status Register
and     t0, <complement of bits to clear>
or      t0, <bits to set>
mtc0    t0, SR

6. Address Layout

Screen Shot 2021-09-07 at 5.06.00 PM

7. Instructions

lw $1, offset($2)

lb $1, offset($2)   # load byte with sign extension
lbu $1, offset($2)  # load byte with zero extension

Add

Screen Shot 2021-08-26 at 11.24.56 AM

Count leading zeros / ones

Screen Shot 2021-08-26 at 11.25.14 AM

Multiply / Divide

Screen Shot 2021-08-26 at 11.28.19 AM

Multiply and Add / Subtract

Screen Shot 2021-08-26 at 11.31.31 AM

Unsigned / Signed compare, less than

Screen Shot 2021-08-26 at 11.32.18 AM

Branch

Screen Shot 2021-08-26 at 11.50.25 AM

Screen Shot 2021-08-26 at 11.57.36 AM

Load / Save

Screen Shot 2021-08-26 at 12.00.33 PM

Load Linked / Store Conditional

Screen Shot 2021-08-26 at 12.11.42 PM

Logical

Screen Shot 2021-08-26 at 12.14.00 PM

7.1 Directives

Screen Shot 2021-08-26 at 12.42.07 PM

Screen Shot 2021-08-26 at 12.42.18 PM

Screen Shot 2021-08-26 at 12.42.36 PM

7.2 Pseudo-instruction

Screen Shot 2021-08-26 at 3.24.26 PM

Screen Shot 2021-08-26 at 3.24.38 PM

7.3 Syscall

Screen Shot 2021-09-07 at 4.36.44 PM

8. Exception

Synchronous exception:

  • Traps: system call, break point, trap instruction → return to the next instruction

  • Faults: page fault → re-execute the instruction; Recoverable

  • Aborts: parity error (parity, the evenness or oddness of an integer; results from irregular changes to data), machine check → exit

Asynchronous exception:

  • Interrupt: IO Interrupt, hard reset, soft reset

Status Register

Screen Shot 2021-08-26 at 5.05.23 PM

Cause Register

Screen Shot 2021-08-26 at 5.05.53 PM

9. Virtual Memory

9.1 Page Fault

Faults: page fault → re-execute the instruction; Recoverable

Address Translation:

Screen Shot 2021-08-31 at 1.42.38 PM

Screen Shot 2021-08-31 at 1.43.23 PM

9.2 Memory Management

Virtual Page, Physical Page, Address Translation and Shared Library

Screen Shot 2021-08-31 at 2.38.43 PM

Screen Shot 2021-08-31 at 2.51.56 PM

Protection: Access Permission

Screen Shot 2021-08-31 at 2.42.26 PM

Translation Lookaside Buffer

Screen Shot 2021-08-31 at 2.54.38 PM

Screen Shot 2021-08-31 at 2.56.01 PM

9.3 MIPS Memory Management

Screen Shot 2021-08-31 at 4.33.15 PM

Screen Shot 2021-08-31 at 4.33.34 PM


Last update: September 8, 2021
Authors: Co1lin