Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please show work if you can. You can also send a picture of it if that\'s easier

ID: 3801410 • Letter: P

Question

Please show work if you can. You can also send a picture of it if that's easier.

1. Convert the following MIPS instructions into machine instructions in hexadecimal form. Show every step in the conversion (40 pts).

ADD       $t0,$s3,$s2

SRL         $s5, $s2, 3

ADDI      $s5, $t2, -10

LW         $t0, 100($s3)

2. Convert the following machine instructions into MIPS instructions. (20 pts).

AD6803EB16

3. Convert the following C program to MIPS program. Assuming that i, j, k, f, are stored in registers $s0, $s1, $s2, $s3 already. (40 pts)

1) f = i – (j – k);

2) f = j + ( i – 12 );

3) f = -i + (j – 5);   (Hint: $zero)

4) f = i*8;          (MUL instruction is not allowed. Hint: relationship between multiplication and shift)

5) f = i/4 + 3;

6) f = i;

7) f = – i;

8) f = – – i;

Explanation / Answer

Here is the solution for question 1:

1. Convert the following MIPS instructions into machine instructions in hexadecimal form.
Show every step in the conversion (40 pts).

ADD   $t0,$s3,$s2:
ADD $t0, $s3, $s2
The syntax for ADD is: ADD rd, rs, rt(offset)

ADD - 100000
rd - $t0 - 01000
rs - $s3 - 10011
rt - $s2 - 10010
And remember ADD is a special instruction, so the leading 6 bits for special instruction
will be 000000
And the offset here is: 0 which means: 000000
The MIPS format for ADD is:
SPECIAL   rs   rt   rd   offset   ADD

So, keeping it all together:

SPECIAL $s3    $s2    $t0    offset ADD
000000    10011   10010   01000   00000   100000
So, the binary instruction is: 00000010011100100100000000100000
And its hex equivalent is:
0000   0010   0111   0010   0100   0000   0010   0000
0       2       7       2       4      0       2       0
= 0x02724020.

SRL $s5, $s2, 3:
The syntax for SRL (Shift Right Logical) is: SRL rd, rt, sa(offset)

SRL - 000010
rd - $s5 - 10101
rt - $s2 - 10010
sa - 3 - 00011
And SRL is a special instruction, so the leading 6 bits for special instruction
will be 000000
The MIPS format for SRL is:
SPECIAL 0 rt rd sa SRL
So, keeping it all together:
SPECIAL   0       $s2       $s5       0x3       SRL
000000   00000 10010 10101 00011   000010
So, the binary instruction is: 00000000000100101010100011000010
And its hex equivalent is:
0000   0000   0001   0010   1010   1000   1100   0010
0       0       1       2       A       8       C       2
= 0x0012A8C2

ADDI $s5, $t2, -10:
The syntax for ADDI (ADD Immediate) is: ADDI rt, rs, immediate

ADDI - 001000
rt - $s5 - 10101
rs - $t2 - 01010
immediate - -10 and its hexadecimal representation is: 0xFFF6.
The MIPS format for ADDI is:
ADDI rs rt immediate
So, keeping it all together:
ADDI   $t2   $s5   immediate
001000   01010   10101   1111111111110110
So, the binary instruction is: 00100001010101011111111111110110
And its hex equivalent is:
0010   0001   0101   0101   1111   1111   1111   0110
2       1       5       5       F       F       F       6
= 0x2155FFF6

LW $t0, 100($s3):
The syntax for LW (Load Word) is: LW rt, offset(base)

LW   - 100011
rt   - $t0 - 01000
base - $s0 - 10011
offset - 100 and its hexadecimal representation is: 0x64.
The MIPS format for LW is:
LW base rt offset
So, keeping it all together:
LW   $s3   $t0       offset
100011   10011   01000   0000000001100100
So, the binary instruction is: 10001110011010000000000001100100
And its hex equivalent is:
1000   1110   0110   1000   0000   0000   0110   0100
8       E       6       8       0       0       6       4
= 0x8E680064