1. Write the following instruction in Hex: ADDU $t0, $s4, $t3 2. Decode the foll
ID: 3877126 • Letter: 1
Question
1. Write the following instruction in Hex: ADDU $t0, $s4, $t3
2. Decode the following instruction: 0x36890010
3. Write the following instruction in Hex: ADDU $s2, $s3, $t4
4. Decode the following instruction: 0x25b40005
ADD -- Add
Description:
Adds two registers and stores the result in a register
Operation:
$d = $s + $t; advance_pc (4);
Syntax:
add $d, $s, $t
Encoding:
0000 00ss ssstttttdddd d000 0010 0000
ADDI -- Add immediate (with overflow)
Description:
Adds a register and a sign-extended immediate value and stores the result in a register
Operation:
$t = $s + imm; advance_pc (4);
Syntax:
addi $t, $s, imm
Encoding:
0010 00ss ssstttttiiiiiiiiiiiiiiii
ADDIU -- Add immediate unsigned (no overflow)
Description:
Adds a register and a sign-extended immediate value and stores the result in a register
Operation:
$t = $s + imm; advance_pc (4);
Syntax:
addiu $t, $s, imm
Encoding:
0010 01ss ssstttttiiiiiiiiiiiiiiii
ADDU -- Add unsigned (no overflow)
Description:
Adds two registers and stores the result in a register
Operation:
$d = $s + $t; advance_pc (4);
Syntax:
addu $d, $s, $t
Encoding:
0000 00ss ssstttttdddd d000 0010 0001
AND -- Bitwise and
Description:
Bitwise ands two registers and stores the result in a register
Operation:
$d = $s & $t; advance_pc (4);
Syntax:
and $d, $s, $t
Encoding:
0000 00ss ssstttttdddd d000 0010 0100
ANDI -- Bitwise and immediate
Description:
Bitwise ands a register and an immediate value and stores the result in a register
Operation:
$t = $s &imm; advance_pc (4);
Syntax:
andi $t, $s, imm
Encoding:
0011 00ss ssstttttiiiiiiiiiiiiiiii
OR -- Bitwise or
Description:
Bitwise logical ors two registers and stores the result in a register
Operation:
$d = $s | $t; advance_pc (4);
Syntax:
or $d, $s, $t
Encoding:
0000 00ss ssstttttdddd d000 0010 0101
ORI -- Bitwise or immediate
Description:
Bitwise ors a register and an immediate value and stores the result in a register
Operation:
$t = $s | imm; advance_pc (4);
Syntax:
ori $t, $s, imm
Encoding:
0011 01ss ssstttttiiiiiiiiiiiiiiii
SB -- Store byte
Description:
The least significant byte of $t is stored at the specified address.
Operation:
MEM[$s + offset] = (0xff & $t); advance_pc (4);
Syntax:
sb $t, offset($s)
Encoding:
1010 00ss ssstttttiiiiiiiiiiiiiiii
SLL -- Shift left logical
Description:
Shifts a register value left by the shift amount listed in the instruction and places the result in a third register. Zeroes are shifted in.
Operation:
$d = $t << h; advance_pc (4);
Syntax:
sll $d, $t, h
Encoding:
0000 00ss ssstttttdddddhhh hh00 0000
SLT -- Set on less than (signed)
Description:
If $s is less than $t, $d is set to one. It gets zero otherwise.
Operation:
if $s < $t $d = 1; advance_pc (4); else $d = 0; advance_pc (4);
Syntax:
slt $d, $s, $t
Encoding:
0000 00ss ssstttttdddd d000 0010 1010
SLTI -- Set on less than immediate (signed)
Description:
If $s is less than immediate, $t is set to one. It gets zero otherwise.
Operation:
if $s <imm $t = 1; advance_pc (4); else $t = 0; advance_pc (4);
Syntax:
slti $t, $s, imm
Encoding:
0010 10ss ssstttttiiiiiiiiiiiiiiii
SLTU -- Set on less than unsigned
Description:
If $s is less than $t, $d is set to one. It gets zero otherwise.
Operation:
if $s < $t $d = 1; advance_pc (4); else $d = 0; advance_pc (4);
Syntax:
sltu $d, $s, $t
Encoding:
0000 00ss ssstttttdddd d000 0010 1011
SRL -- Shift right logical
Description:
Shifts a register value right by the shift amount (shamt) and places the value in the destination register. Zeroes are shifted in.
Operation:
$d = $t >> h; advance_pc (4);
Syntax:
srl $d, $t, h
Encoding:
0000 00-- ---t ttttdddddhhh hh00 0010
SUB -- Subtract
Description:
Subtracts two registers and stores the result in a register
Operation:
$d = $s - $t; advance_pc (4);
Syntax:
sub $d, $s, $t
Encoding:
0000 00ss ssstttttdddd d000 0010 0010
SW -- Store word
Description:
The contents of $t is stored at the specified address.
Operation:
MEM[$s + offset] = $t; advance_pc (4);
Syntax:
sw $t, offset($s)
Encoding:
1010 11ss ssstttttiiiiiiiiiiiiiiii
Name
Register Number
Usage
Preserved by callee?
$zero
0
hardwired 0
N/A
$v0-$v1
2-3
return value and expression evaluation
no
$a0-$a3
4-7
arguments
no
$t0-$t7
8-15
temporary values
no
$s0-$s7
16-23
saved values
YES
$t8-$t9
24-25
more temporary values
no
$gp
28
global pointer
YES
$sp
29
stack pointer
YES
$fp
30
frame pointer
YES
$ra
31
return address
YES
Description:
Adds two registers and stores the result in a register
Operation:
$d = $s + $t; advance_pc (4);
Syntax:
add $d, $s, $t
Encoding:
0000 00ss ssstttttdddd d000 0010 0000
Explanation / Answer
1) answer : = 0x028B4021 = 0000 0010 1000 1011 0100 0000 0010 0001
comparing addu $d, $s, $t with given instruction addu $t0, $s4, $t3.
Here we get ddddd = t0 = 8(register number) =(01000) in binary
sssss = s4 = 20(register number) = 10100 in binary
ttttt = t3 = 11(register number) = 01011 in binary
Instruction format is 0000 00ss ssst tttt dddd d000 0010 0001
we get : 0000 0010 1000 1011 0100 0000 0010 0001
2) answer : ori $t1, $s4, 0x0010
0x36890010 = 0011 0110 1000 1001 0000 0000 0001 0000 in binary
ORI instruction has instruction code 0011 01
comparing ORI instruction format with given instruction,
we get sssss = 10100 = $s4
ttttt = 01001 = $t1
iiii iiii iiii iiii = 0000 0000 0001 0000
instruction format : ori $t, $s, imm
hence we get ori $t1, $s4, 0x0010
here 0010 is in hex.
3) answer := 0x026C9021 = 0000 0010 0110 1100 1001 0000 0010 0001
comparing addu $d, $s, $t with given instruction addu $s2, $s3, $t4.
Here we get d = s2 = 18 (register number) =(10010) in binary
t = t4 = 12(register number) = 01100 in binary
s = s3 = 19(register number) = 10011 in binary
Instruction format is 0000 00ss ssst tttt dddd d000 0010 0001
we get : 0000 0010 0110 1100 1001 0000 0010 0001
4) addiu $s4, $t4, 0x0005
0x25b40005 = 0010 0101 1011 0100 0000 0000 0000 0101
0010 01 is opcode for ADDIU.
format of ADDIU : addiu $t, $s, imm
stored in hex as : 0010 01ss ssst tttt iiii iiii iiii iiii
we get sssss = 01 101 = 13(register number) = $t5
ttttt = 10100 = 20(register number) = $s4
instruction : addiu $s4, $t4, 0x0005
if you have any doubts then you can ask in comment section.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.