Title | MIPS reference sheet 2018 |
---|---|
Course | Introduction To Computer Science |
Institution | Monash University |
Pages | 2 |
File Size | 105.3 KB |
File Type | |
Total Downloads | 117 |
Total Views | 152 |
Reference sheet for MIPS...
MIPS reference sheet
Service
Table 1: SPIM Arguments
Call code ($v0) 1
Print integer
4
Print string
5
Input integer
8
Input string
9 10
Allocate memory Exit
Number R00 R01 R02, R03 R04–R07 R08–R15 R16–R23 R24, R25 R26, R27 R28 R29 R30 R31
system calls
$a0 = value to print $a0 = address of string to print $a0 = address to store string at $a1 = maximum number of chars $a0 = number of bytes -
Returns
Notes
-
value is signed
-
string must be terminated with ’\0’ value is signed
$v0 = entered integer –
$v0 = address of first byte -
returns if $a1-1 characters or Enter typed, the string is terminated with ’\0’ ends tion
Table 2: General-purpose registers Name Purpose $zero provides constant zero $at reserved for assembler $v0, $v1 system call code, return value $a0--$a3 system call and function arguments $t0--$t7 temporary storage (caller-saved) $s0--$s7 temporary storage (callee-saved) $t8, $t9 temporary storage (caller-saved) $k0, $k1 reserved for kernel code $gp pointer to global area $sp stack pointer $fp frame pointer $ra return address
simula-
.data .text .byte b1[, b2, ...] .half h1[, h2, ...] .word w1[, w2, ...] .space n .align n .ascii ”string” .asciiz ”string”
Table 3: Assembler directives assemble into data segment assemble into text (code) segment allocate byte(s), with initial value(s) allocate halfword(s), with initial value(s) allocate word(s) with initial value(s) allocate n bytes of uninitialized, unaligned space align the next item to a 2n -byte boundary allocate ASCII string, do not terminate allocate ASCII string, terminate with ’\0’ Table 4:
Function calling convention On function call:
Caller: saves temporary registers on stack passes arguments on stack calls function using jal fn label
Callee: saves $ra and $fp on stack copies $sp to $fp allocates local variables on stack
On function return:
Callee: sets $v0 to return value clears local variables off stack restores saved $fp and $ra off stack returns to caller with jr $ra
Caller: clears arguments off stack restores temporary registers off stack uses return value in $v0
Table 5: Instruction Set A partial instruction set is on the next page. The following conventions apply. Instruction Format Rsrc, Rsrc1, Rsrc2: source operand(s), - must be a register value(s) Src2; source operand - may be an immediate value or a register value Rdest: destination, must be a register Imm: Immediate value, may be 32 or 16 bits Imm16: Immediate 16-bit value Addr: Address in the form: offset(Rsrc) ie. absolute address = Rsrc + offset label: label of an instruction ⋆: pseudoinstruction Immediate Form -: no immediate form, or this is the immediate form ⋆: immediate form synthesized as pseduoinstruction Unsigned form (append ’u’ to instruction name): - : no unsigned form, or this is the unsigned form Page 1
Table 6:
MIPS instruction set
Instruction format
Meaning
Operation
add Rdest, Rsrc1, Rsrc2 sub Rdest, Rsrc1, Rsrc2 mul Rdest, Rsrc1, Rsrc2 ⋆ mulo Rdest, Rsrc1, Rsrc2 ⋆
rem Rdest, Rsrc1, Rsrc2 ⋆ neg Rdest, Rsrc ⋆ and Rdest, Rsrc1, Rsrc2 or Rdest, Rsrc1, Rsrc2 xor Rdest, Rsrc1, Rsrc2 nor Rdest, Rsrc1, Rsrc2 not Rdest, Rsrc ⋆ sll Rdest, Rsrc1, Rsrc2 srl Rdest, Rsrc1, Rsrc2
Add Subtract Multiply Multiply (with 32-bit overflow) Multiply (machine instruction) Divide Divide (machine instruction) Remainder Negate Bitwise AND Bitwise OR Bitwise XOR Bitwise NOR Bitwise NOT Shift Left Logical Shift Right Logical
sra Rdest, Rsrc1, Rsrc2
Shift Right Arithmetic
move Rdest, Rsrc ⋆ mfhi Rdest mflo Rdest li Rdest, Imm ⋆ lui Rdest, Imm16 la Rdest, Addr(or label) ⋆
Move Move from Hi Move from Lo Load immediate Load upper immediate Load Address
lb Rdest, Addr (or label ⋆) lh Rdest, Addr (or label ⋆) lw Rdest, Addr (or label ⋆) sb Rsrc2, Addr (or label ⋆) sh Rsrc2, Addr (or label ⋆) sw Rsrc2, Addr (or label ⋆) beq Rsrc1, Rsrc2, label
Load byte Load halfword Load word Store byte Store halfword Store word Branch if equal
bne Rsrc1, Rsrc2, label
Branch if not equal
blt Rsrc1, Rsrc2, label ⋆
Branch if less than
ble Rsrc1, Rsrc2, label ⋆
Branch if less than or equal
bgt Rsrc1, Rsrc2, label ⋆
Branch if greater than
bge Rsrc1, Rsrc2, label ⋆ slt Rdest, Rsrc1, Rsrc2
Branch if greater than or equal Set if less than
j label jal label
Jump Jump and link
jr Rsrc jalr Rsrc
Jump register Jump and link register
syscall
System call
mult Rsrc1, Rsrc2 div Rdest, Rsrc1, Rsrc2 ⋆ div Rsrc1, Rsrc2
Rdest = Rsrc1 + Rsrc2 Rdest = Rsrc1 - Rsrc2 Rdest = Rsrc1 * Rsrc2 Rdest = Rsrc1 * Rsrc2
Immediate form addi ⋆ ⋆ ⋆
no overflow trap no overflow trap unsigned operands unsigned operands
Hi:Lo = Rsrc1 * Rsrc2
-
unsigned operands
Rdest=Rsrc1/Rsrc2 Lo = Rsrc1/Rsrc2; Hi = Rsrc1 % Rsrc2 Rdest = Rsrc1 % Rsrc2 Rdest = -Rsrc1 Rdest = Rsrc1 & Rsrc2 Rdest = Rsrc1 | Rsrc2 Rdest = Rsrc1 ∧ Rsrc2 Rdest = ∼(Rsrc1 | Rsrc2) Rdest = ∼(Rsrc) Rdest = Rsrc1 > Rsrc2 (MSB=0) Rdest = Rsrc1 >> Rsrc2 (MSB preserved) Rdest=Rsrc Rdest = Hi Rdest = Lo Rdest=Imm Rdest=Imm16 = Rsrc2) PC = label if (Rsrc1 < Rsrc2) Rdest=1 else Rdest=0 PC = label $ra = PC + 4; PC = label PC = Rsrc $ra = PC + 4; PC = Rsrc depends on call code in $v0
⋆ -
unsigned operands unsigned operands
⋆ andi ori xori ⋆ − -
unsigned operands no overflow trap -
-
-
-
-
⋆
zero-extends data zero-extends data -
⋆
-
⋆
unsigned operands
⋆
unsigned operands
⋆
unsigned operands
⋆
unsigned operands
slti
unsigned operands
-
-
-
-
-
-
Page 2
Unsigned form(u)...