MIPS

RISC vs CISC

Reduced Instruction Set Computer vs Complex Instruction Set Computer

RISCCISC
fixed size instructionsvariable size instructions (requires decode before fetch)
fixed formatvariable format (complex decode)
operations only with registersin-memory operands
many registersfew of registers
single access to memorymultiple accesses to memory
fixed instruction durationvariable instruction duration
simple conflictscomplex conflicts
faster pipelinecomplex pipeline

Registers

namenumberusekeep
at1reserved for assembler?
v12 - 3expression evaluation and results of functionsno
a34 - 7argumentsno
t78 - 15temporaryno
s716 - 23saved temporaryyes
t924 - 25temporaryno
k126 - 27reserved for OS Kernel?
sp29stack pointeryes
ra31return addressyes

Special registers

  • sp points to the last location in use on the stack
  • ra is written with the return address for a call by the jal instruction

Instructions

R-type Instructions

Arithmetic Instruction Format (type to a register)

add $t0, $s1, $s2
  • add opcode \(\to\) 000000
  • s1 in rs, \(\to\) 10001
  • s2 in rt, \(\to\) 10010
  • add funct \(\to\) 100000
oprsrtrdshamtfunct
00000010001100100100000000100000
6b5b5b5b5b6b
opcodefirst
register
source
second
register
source
register
destination
operand
shift
amount
function
code

I-type Instructions

Data Transfer Format (conditional jumps)

addi t2, <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">s</span><span class="mord">2</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord">4‘‘‘</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">a</span><span class="mord mathnormal">dd</span><span class="mord mathnormal">i</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord">∗</span><span class="mord mathnormal">o</span><span class="mord mathnormal">p</span><span class="mord mathnormal">co</span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.4653em;"></span><span class="mord">∗</span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mrel">→</span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mclose">)</span><span class="mord">001000</span><span class="mord">−</span></span></span></span>t2 in **rt** \\(\to\\) 01010
- s2 in **rs** \\(\to\\) 10010

| op | rs | rt | constant |
|:--:|:--:|:--:|:--:|
| 001000 | 10010 | 01010 | 0000000000000100 |
| 6b | 5b | 5b | 16b |
| opcode | first <br/> register | target <br/> register | constant value or <br/> address | 

<!-- | \\(0..5\\) | \\(6..10\\) | \\(11..15\\) | \\(16..31\\) | -->

### J-type Instructions

Unconditional Jumps

```armasm
j label
  • PC \(\leftarrow\) label \(\cdot\) 4
opaddress
00100010010010100000000000000100
6 bit26 bit

FR-type Instructions

MIPS handles floating point instructions like regular 32b instructions. FR-type don't access the memory, and are executed by the FPU.

add.s f0, <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord">1</span><span class="mpunct">,</span></span></span></span>f2 ; single precision
div.d <span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord">0</span><span class="mpunct">,</span></span></span></span>f2, f4 ; double precision
oprsrtrdshamtfunct
00000010001100100100000000100000
6b5b5b5b5b6b
opcodefirst
register
source
second
register
source
register
destination
operand
shift
amount
function
code

FI-type Instructions

FI-type are used for:

  • load / store
  • conditional jumps
lwc1 f1, indirizzo
bc1f cc, offset
oprsrtconstant
00100010010010100000000000000100
6b5b5b16b
opcodefirst
register
target
register
constant value or
address

Interrupts

TODO: Interrupts