|
Command
|
Explanation
|
|
add $rd, $rs, $rt
|
- Reg[ d ] = Reg[ s ] + Reg[ t ]
- R-type instruction
- B31-26 = 000000 (SPECIAL)
- B10-6 = 000000
- B5-0 = 100000 (ADD)
|
|
addi $rt, $rs, immed
|
- Reg[ t ] = Reg[ s ] +
(immed15)16 || immed15-0
- I-type instruction
- B31-26 = 001 000
- Immediate value is sign extended
- Immediate value written in signed base 10
|
|
sub $rd, $rs, $rt
|
- Reg[ d ] = Reg[ s ] - Reg[ t ]
- R-type instruction
- B31-26 = 000 000 (SPECIAL)
- B10-6 = 00000
- B5-0 = 100 010 (SUB)
|
|
addu $rd, $rs, $rt
|
- Reg[ d ] = Reg[ s ] + Reg[ t ]
- Unsigned addition
- R-type instruction
- B31-26 = 000 000 (SPECIAL)
- B10-6 = 00000
- B5-0 = 100 001 (ADD)
|
|
addiu $rt, $rs, immed
|
- Reg[ t ] = Reg[ s ] +
(0)16 || immed15-0
- I-type instruction
- B31-26 = 001 001
- Immediate can be stored as 16 bit UB in immediate field in
instruction.
- Immediate value is zero extended
- Immediate value written in unsigned base 10
|
|
subu $rd, $rs, $rt
|
- Reg[ d ] = Reg[ s ] - Reg[ t ]
- Unsigned subtraction
- R-type instruction
- B31-26 = 000 000 (SPECIAL)
- B10-6 = 00000
- B5-0 = 100 011 (SUBU)
|
|
and $rd, $rs, $rt
|
- Reg[ d ] = Reg[ s ] & Reg[ t ]
- Bitwise AND
- R-type instruction
- B31-26 = 000 000 (SPECIAL)
- B10-6 = 00000
- B5-0 = 100 100 (AND)
|
|
andi $rt, $rs, immed
|
- Reg[ t ] = Reg[ s ] &
016 || immed15-0
- I-type instruction
- B31-26 = 001 100
- Immediate value is zero extended
- Immediate value written in 4 hex digits (e.g., 0xcafe)
|
|
or $rd, $rs, $rt
|
- Reg[ d ] = Reg[ s ] | Reg[ t ]
- Bitwise OR
- R-type instruction
- B31-26 = 000 000 (SPECIAL)
- B10-6 = 00000
- B5-0 = 100 101 (OR)
|
|
ori $rt, $rs, immed
|
- Reg[ t ] = Reg[ s ] |
016 || immed15-0
- I-type instruction
- B31-26 = 001 101
- Immediate value is zero extended
- Immediate value written in 4 hex digits (e.g., 0xcafe)
|
|
xor $rd, $rs, $rt
|
- Reg[ d ] = Reg[ s ] ^ Reg[ t ]
- Bitwise XOR
- R-type instruction
- B31-26 = 000 000 (SPECIAL)
- B10-6 = 00000
- B5-0 = 100 110 (XOR)
|
|
xori $rt, $rs, immed
|
- Reg[ t ] = Reg[ s ] ^
016 || immed15-0
- I-type instruction
- B31-26 = 001 110
- Immediate value is zero extended
- Immediate value written in 4 hex digits (e.g., 0xcafe)
|
|
beq $rs, $rt, LABEL
|
- if ( Reg[ s ] == Reg[ t ] )
jump to LABEL
else
go to next instruction
- I-type instruction
- B31-26 = 000 100
- offset is B15-0
- Jump to PC + [ (offset15)14 || offset || 02 ]
- i.e., the offset is shifted to the left by 2, then sign extended.
- Immediate written using signed base 10 (divide by 4)
- CORRECTION: LABEL is written as signed based
10 number, ignore divide by 4 (e.g., LABEL might be -21)
|
|
bne $rs, $rt, LABEL
|
- if ( Reg[ s ] != Reg[ t ] )
jump to LABEL
else
go to next instruction
- I-type instruction
- B31-26 = 000 101
- offset is B15-0
- Jump to PC + [ (offset15)14 || offset || 02 ]
- i.e., the offset is shifted to the left by 2, then sign extended.
- Immediate written using signed base 10 (divide by 4)
- CORRECTION: LABEL is written as signed based
10 number, ignore divide by 4 (e.g., LABEL might be -21)
|
|
slt $rd, $rs, $rt
|
- if ( Reg[ s ] < Reg[ t ] )
Reg[ d ] = 0311
else
Reg[ d ] = 032
- R-type instruction
- B31-26 = 000 000 (SPECIAL)
- B10-6 = 00000
- B5-0 = 101 010 (SLT)
|
|
slti $rt, $rs, immed
|
- if ( Reg[ s ] <
(immed15)16 || immed15-0)
Reg[ d ] = 0311
else
Reg[ d ] = 032
- I-type instruction
- B31-26 = 001 010
- Immediate written in signed base 10
|
|
jr $rs
|
- R-type instruction (sort of)
- B31-26 = 000 000 (SPECIAL)
- B25-21 is $rs
- B20-6 = 000 0000 0000 0000
- B5-0 = 001 000 (JR)
|
|
j LABEL
|
- PC <- PC31-28 || immed || 02
- immed is 26 bit value
- J-type instruction
- B31-26 = 000 010
- LABEL is written using 8 hex digits,
e.g. 0x00ff00ff. Assume that upper 6 bits is 0.
|
|
jal LABEL
|
- PC <- PC31-28 || immed || 02
- immed is 26 bit value
- Reg[ 31 ] <- PC + 4 (In the real MIPS, it should
be PC + 8, but that's mostly because of pipelining--we use
the simpler PC + 4, which is the next instruction).
- J-type instruction
- B31-26 = 000 011
- Label is 8 hex digits (e.g., 0xcafe1234).
- CORRECTION: LABEL is written using 8 hex digits,
e.g. 0x00ff00ff. Assume that upper 6 bits is 0.
|
|
jalr $rs
|
- Jump-and-link using register (instead of label)
- PC <- Reg[ s ]
- B31-26 = 000 000 (SPECIAL)
- B25-21 is register s
- B20-16 = 00000
- B15-11 = 11111
- B10-6 = 00000
- B5-0 = 001 001 (JALR)
- Reg[ 31 ] <- PC + 4 (In the real MIPS, it should
be PC + 8, but that's mostly because of pipelining--we use
the simpler PC + 4, which is the next instruction).
- R-type instruction
|
|
lw $rt, offset($rs)
|
- I-type instruction
- offset is sign-extended to 32 bits, and added to
Reg[ s ] to produce address. The content
of that address (which must be word-aligned), is
placed in Reg[ t ]
- B31-26 = 100 011
- B15-0 is the offset (2C)
- offset written in signed base 10
|
|
lbu $rt, offset($rs)
|
- I-type instruction
- offset is sign-extended to 32 bits, and added to
Reg[ s ] to produce address. The content
of that address (which does NOT have to be word-aligned), is
placed in Reg[ d ]
- B31-26 = 100 100
- B15-0 is the offset (2C)
- offset written in signed base 10
|
|
sw $rt, offset($rs)
|
- I-type instruction
- offset is sign-extended to 32 bits, and added to
Reg[ s ] to produce address. The content
of Reg[ t ] is saved at that address (which must
be word-aligned)
- B31-26 = 101 011
- B15-0 is the offset (2C)
- offset written in signed base 10
|
|
sb $rt, offset($rs)
|
- I-type instruction
- offset is sign-extended to 32 bits, and added to
Reg[ s ] to produce address. The content
of Reg[ t ] is saved at that address (which does NOT
have to be word-aligned)
- B31-26 = 101 000
- B15-0 is the offset, written in signed base ten.
|
|
lui $rt, immed
|
- I-type instruction
- Reg[ t ] = immed || 016
- B31-26 = 001 111
- B25-21 = 00000 (normally where rs goes,
but leave it all zeroes)
- Immediate written using 4 hex digits (as in 0xcafe).
|
|
bgtz $rs, LABEL
|
- I-type instruction
- B31-26 = 000 111
- B20-16 = 00000
- Let offset = B15-0
- PC-relative addressing. Let target =
(offset15)14 || offset || 02
- PC <- PC + target
- Immediate written using signed base 10 (divide by 4)
- CORRECTION: LABEL is written as signed based
10 number, ignore divide by 4 (e.g., LABEL might be -21)
|
|
bgez $rs, LABEL
|
- I-type instruction
- B31-26 = 000 001 (REGIMM)
- B20-16 = 00001 (BGEZ)
- Let offset = B15-0
- PC-relative addressing. Let target =
(offset15)14 || offset || 02
- PC <- PC + target
- Immediate written using signed base 10 (divide by 4)
- CORRECTION: LABEL is written as signed based
10 number, ignore divide by 4 (e.g., LABEL might be -21)
|
|
bltz $rs, LABEL
|
- I-type instruction
- B31-26 = 000 001 (REGIMM)
- B20-16 = 00000 (BLTZ)
- Let offset = B15-0
- PC-relative addressing. Let target =
(offset15)14 || offset || 02
- PC <- PC + target
- Immediate written using signed base 10 (divide by 4)
- CORRECTION: LABEL is written as signed based
10 number, ignore divide by 4 (e.g., LABEL might be -21)
|
|
blez $rd, LABEL
|
- I-type instruction
- B31-26 = 000 110
- B20-16 = 00000
- Let offset = B15-0
- PC-relative addressing. Let target =
(offset15)14 || offset || 02
- PC <- PC + target
- Immediate written using signed base 10 (divide by 4)
- CORRECTION: LABEL is written as signed based
10 number, ignore divide by 4 (e.g., LABEL might be -21)
|
|
sll $rd, $rt, shift_amt
|
- R-type instruction
- Shift left logical
- B10-6 is the shift amount (between 0-31)
- B31-26 = 000 000 (SPECIAL)
- B5-0 = 000 000 (SLL)
- B10-6 is a 5 bit UB shift amount.
- Shift a copy of Reg[ t ] left by shift_amt
bits, inserting zeroes into the low order bits (right end).
|
|
srl $rd, $rt, shift_amt
|
- R-type instruction
- Shift right logical
- B10-6 is the shift amount (between 0-31)
- B31-26 = 000 000 (SPECIAL)
- B25-21 = 00000 ($rs is zeroed out)
- B5-0 = 000 010 (SRL)
- B10-6 is a 5 bit UB shift amount.
- Shift a copy of Reg[ t ] right by shift_amt
bits, inserting zeroes into the high order bits (left end)
- shift_amt is base 10 number between 0 and 31
|
|
sra $rd, $rt, shift_amt
|
- R-type instruction
- Shift right arithmetic
- B10-6 is the shift amount (between 0-31)
- B31-26 = 000 000 (SPECIAL)
- B25-21 = 00000 ($rs is zeroed out)
- B5-0 = 000 011 (SRA)
- B10-6 is a 5 bit UB shift amount.
- Shift a copy of Reg[ t ] right by shift_amt
bits, inserting the sign bit into the high order bits (left
end)
- shift_amt is base 10 number between 0 and 31
|
sllv $rd, $rt, $rs
|
- R-type instruction
- Shift left logical variable
- B31-26 = 000 000 (SPECIAL)
- B10-6 = 00000
- B5-0 = 000 100 (SLLV)
- Shift a copy of Reg[ t ] left by the amount
stored in low 5 bits of
Reg[ s ], placing shifted result in Reg[ d ].
- Zeroes should be shifted from least significant end (right
end)
|
srlv $rd, $rt, $rs
|
- R-type instruction
- Shift right logical variable
- B31-26 = 000 000 (SPECIAL)
- B10-6 = 00000
- B5-0 = 000 110 (SRLV)
- Shift a copy of Reg[ t ] right by the amount
stored in low 5 bits of
Reg[ s ], placing shifted result in Reg[ d ].
- Zeroes are shifted in from most significant end (left
end)
|
|
srav $rd, $rt, $rs
|
- R-type instruction
- Shift right arithmetic variable
- B31-26 = 000 000 (SPECIAL)
- B10-6 = 00000
- B5-0 = 000 111 (SRAV)
- Shift a copy of Reg[ t ] right by the amount
stored in low 5 bits of
Reg[ s ], placing shifted result in Reg[ d ].
- Sign bit is shifted in from most significant end (left
end)
|