I use MIPS as the target language for my C- language. SPIM is a simulator for MIPS.
A SPIM Program must include a label “main” – this will be called by the SPIM startup code (allows you to have command line arguments).
Integer Instruction Set
|
|||
Name
|
Syntax
|
Space
|
Time
|
Add
|
add Rd, Rs, Rt
|
1
|
1
|
Add Immediate
|
addi Rt, Rs, Imm
|
1
|
1
|
Add Immediate Unsigned
|
addiu Rt, Rs, Imm |
1
|
1
|
Add Unsigned
|
addu Rd, Rs, Rt
|
1
|
1
|
And
|
and Rd, Rs, Rt
|
1
|
1
|
And Immediate
|
andi Rt, Rs, Imm
|
1
|
1
|
Branch if Equal
|
beq Rs, Rt, Label |
1
|
1
|
Branch if Greater Than or Equal to Zero
|
bgez Rs, Label
|
1
|
1
|
Branch if Greater Than or Equal to Zero and Link
|
bgezal Rs, Label
|
1
|
1
|
Branch if Greater Than Zero
|
bgtz Rs, Label
|
1
|
1
|
Branch if Less Than or Equal to Zero
|
blez Rs, Label
|
1
|
1
|
Branch if Less Than Zero and Link
|
bltzal Rs, Label
|
1
|
1
|
Branch if Less Than Zero
|
bltz Rs, Label
|
1
|
1
|
Branch if Not Equal
|
bne Rs, Rt, Label |
1
|
1
|
Divide
|
div Rs, Rt
|
1
|
38
|
Divide Unsigned
|
divu Rs, Rt
|
1
|
38
|
Jump
|
j Label
|
1
|
1
|
Jump and Link
|
jal Label
|
1
|
1
|
Jump and Link Register
|
jalr Rd, Rs
|
1
|
1
|
Jump Register
|
jr Rs
|
1
|
1
|
Load Byte
|
lb Rt, offset(Rs) |
1
|
1
|
Load Byte Unsigned
|
lbu Rt, offset(Rs) |
1
|
1
|
Load Halfword
|
lh Rt, offset(Rs) |
1
|
1
|
Load Halfword Unsigned
|
lhu Rt, offset(Rs) |
1
|
1
|
Load Upper Immediate
|
lui Rt, Imm
|
1
|
1
|
Load Word
|
lw Rt, offset(Rs) |
1
|
1
|
Load Word Left
|
lwl Rt, offset(Rs) |
1
|
1
|
Load Word Right
|
lwr Rt, offset(Rs) |
1
|
1
|
Move From High
|
mfhi Rd
|
1
|
1
|
Move From Low
|
mflo Rd
|
1
|
1
|
Move to High
|
mthi Rs
|
1
|
1
|
Move to Low
|
mtlo Rs
|
1
|
1
|
Multiply
|
mult Rs, Rt
|
1
|
32
|
Multiply Unsigned
|
multu Rs, Rt
|
1
|
32
|
NOR
|
nor Rd, Rs, Rt
|
1
|
1
|
OR
|
or Rd, Rs, Rt
|
1
|
1
|
OR Immediate
|
ori Rt, Rs, Imm
|
1
|
1
|
Store Byte
|
sb Rt, offset(Rs) |
1
|
1
|
Store Halfword
|
sh Rt, offset(Rs) |
1
|
1
|
Shift Left Logical
|
sll Rd, Rt, sa
|
1
|
1
|
Shift Left Logical Variable
|
sllv Rd, Rt, Rs
|
1
|
1
|
Set on Less Than
|
slt Rd, Rt, Rs
|
1
|
1
|
Set on Less Than Immediate
|
slti Rt, Rs, Imm
|
1
|
1
|
Set on Less Than Immediate Unsigned
|
sltiu Rt, Rs, Imm |
1
|
1
|
Set on Less Than Unsigned
|
sltu Rd, Rt, Rs
|
1
|
1
|
Shift Right Arithmetic
|
sra Rd, Rt, sa
|
1
|
1
|
Shift Right Arithmetic Variable
|
srav Rd, Rt, Rs
|
1
|
1
|
Shift Right Logical
|
srl Rd, Rt, sa
|
1
|
1
|
Shift Right Logical Variable
|
srlv Rd, Rt, Rs
|
1
|
1
|
Subtract
|
sub Rd, Rs, Rt
|
1
|
1
|
Subtract Unsigned
|
subu Rd, Rs, Rt
|
1
|
1
|
Store Word
|
sw Rt, offset(Rs) |
1
|
1
|
Store Word Left
|
swl Rt, offset(Rs) |
1
|
1
|
Store Right
|
swr Rt, offset(Rs) |
1
|
1
|
System Call
|
syscall
|
1
|
1
|
Exclusive OR
|
xor Rd, Rs, Rt
|
1
|
1
|
Exclusive OR Immediate
|
xori Rt, Rs, Imm
|
1
|
1
|
Macro instructions
|
|||
Name
|
Syntax
|
Space
|
Time
|
Absolute Value
|
abs Rd, Rs
|
3
|
3
|
Branch if Equal to Zero
|
beqz Rs, Label
|
1
|
1
|
Branch if Greater Than or Equal
|
bge Rs, Rt, Label |
2
|
2
|
Branch if Greater Than or Equal Unsigned
|
bgeu Rs, Rt, Label |
2
|
2
|
Branch if Greater Than
|
bgt Rs, Rt, Label |
2
|
2
|
Branch if Greater Than Unsigned
|
bgtu Rs, Rt, Label |
2
|
2
|
Branch if Less Than or Equal
|
ble Rs, Rt, Label |
2
|
2
|
Branch if Less Than or Equal Unsigned
|
bleu Rs, Rt, Label |
2
|
2
|
Branch if Less Than
|
blt Rs, Rt, Label |
2
|
2
|
Branch if Less Than Unsigned
|
bltu Rs, Rt, Label |
2
|
2
|
Branch if Not Equal to Zero
|
bnez Rs, Label
|
1
|
1
|
Branch Unconditional
|
b Label
|
1
|
1
|
Divide
|
div Rd, Rs, Rt
|
4
|
41
|
Divide Unsigned
|
divu Rd, Rs, Rt
|
4
|
41
|
Load Address
|
la Rd, Label
|
2
|
2
|
Load Immediate
|
li Rd, value
|
2
|
2
|
Move
|
move Rd, Rs
|
1
|
1
|
Multiply
|
mul Rd, Rs, Rt
|
2
|
33
|
Multiply (with overflow exception)
|
mulo Rd, Rs, Rt 7
|
37
|
|
Multiply Unsigned (with overflow exception)
|
mulou Rd, Rs, Rt 5 |
35
|
|
Negate
|
neg Rd, Rs
|
1
|
1
|
Negate Unsigned
|
negu Rd, Rs
|
1
|
1
|
Nop
|
nop
|
1
|
1
|
Not
|
not Rd, Rs
|
1
|
1
|
Remainder Unsigned
|
remu Rd, Rs, Rt
|
4
|
40
|
Rotate Left Variable
|
rol Rd, Rs, Rt
|
4
|
4
|
Rotate Right Variable
|
ror Rd, Rs, Rt
|
4
|
4
|
Remainder
|
rem Rd, Rs, Rt
|
4
|
40
|
Rotate Left Constant
|
rol Rd, Rs, sa
|
3
|
3
|
Rotate Right Constant
|
ror Rd, Rs, sa
|
3
|
3
|
Set if Equal
|
seq Rd, Rs, Rt
|
4
|
4
|
Set if Greater Than or Equal
|
sge Rd, Rs, Rt
|
4
|
4
|
Set if Greater Than or Equal Unsigned
|
sgeu Rd, Rs, Rt
|
4
|
4
|
Set if Greater Than
|
sgt Rd, Rs, Rt
|
1
|
1
|
Set if Greater Than Unsigned
|
sgtu Rd, Rs, Rt
|
1
|
1
|
Set if Less Than or Equal
|
sle Rd, Rs, Rt
|
4
|
4
|
Set if Less Than or Equal Unsigned
|
sleu Rd, Rs, Rt
|
4
|
4
|
Set if Not Equal
|
sne Rd, Rs, Rt
|
4
|
4
|
Unaligned Load Halfword Unsigned
|
ulh Rd, n(Rs)
|
4
|
4
|
Unaligned Load Halfword
|
ulhu Rd, n(Rs)
|
4
|
4
|
Unaligned Load Word
|
ulw Rd, n(Rs)
|
2
|
2
|
Unaligned Store Halfword
|
ush Rd, n(Rs)
|
3
|
3
|
Unaligned Store Word
|
usw Rd, n(Rs)
|
2
|
2
|