This is a homework assignment for Computer Architecture and
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language.
1. In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x1fff0000.
Loop: sw $t1, 4($s0)
addi $t1, $t1, -1
sll $t1, $t1, 2
bne $t1, $s5, Exit
addi $s0, $s0, 4
j Loop
Exit: …
2. Find the MIPS instruction with the machine code 0x02108020.
3. Find the decimal value of the 2\'s complement number 0xffffffab.
4. Compile the following C code into MIPS:
i=0;
while (i<=100) do
A[4*i]=0;
where integer i is in register $s0 and the base memory address of array A is in$s1.
Solution
1.
Loop: sw $t1, 4($s0)
The syntax is: SW rt, offset(base)
SW - 101011
rt - 01001
base - 10000
offset - 4 - 0000000000000100
So,the binary instruction is: 101011 10000 01001 0000000000000100
And its hex equivalent is: 0xAE090004
addi $t1, $t1, -1
The syntax is: ADDI rt, rs, immediate
ADDI - 001000
rt - 01001
rs - 01001
immediate - 1111111111111111
So, the binary instruction is: 001000 01001 01001 1111111111111111
And its hex equivalent is: 0x2129FFFF
sll $t1, $t1, 2
The syntax is: SLL rd, rt, sa
SPECIAL - 000000
SLL - 000000
0 - 00000
rd - 01001
rt - 01001
sa - 00010
So, the instruction is: 000000 00000 01001 01001 00010 000000
And its hex equivalent is: 0x00094880
bne $t1, $s5, Exit
The syntax is: BNE rs, rt, offset
BNE - 000101
rs - 01001
rt - 10101
offset - 0000000000011000
So, the instruction is: 000101 01001 10101 0000000000011000
And its hex equivalent is: 0x15350018
addi $s0, $s0, 4
The syntax is: ADDI rt, rs, immediate
ADDI - 001000
rt - 10000
rs - 10000
immediate - 0000000000000100
So, the instruction is: 001000 10000 10000 0000000000000100
And its hex equivalent is: 0x22100004
j Loop
The syntax is: J target
J - 000010
target - 11111111110000000000000000
So, the instruction is: 000010 11111111110000000000000000
And its hex equivalent is: 0x0BFF0000
Exit: …

