Question 1
Translate the following programs to assembly language. Assume that i is in $s0 and the base address of array x is in $s1. Provide a meaningful comment for each instruction of your assembly program. 32-bit MIPS
int i;
int x[50];
for (i = 0; i < 50; i++)
{
if (x[i] >= 5)
x[i] = x[i] + i;
else
x[i] = x[i] – 5;
}
Question 2
Write a MIPS assembly program that swaps the contents of two registers, $A and $B. Do not use any other registers. 32-bit MIPS
Question 3
Convert the following MIPS assembly code into machine language. Express the machine code in hexadecimal. 32-bit MIPS
label: lw $t0, 0x20 ($t7)
ori $s0, $0, 20
sw $t1, -7 ($t2)
sra $t1, $s7, 5
beq $t0, $0, label
Question 4
Translate the machine code given below to assembly code and specify the addressing mode used by each instruction. 32-bit MIPS
0x8C0A0020
0x02328020
0x2268FFF4
0x016D4022
0x08400000
Question 5
Translate the following assembly code to C code. Also, explain, in simple words, what the program below is doing. 32-bit MIPS
add $v0, $0, $0
count: beq $a0, $0, done
andi $t0, $a0, 0x1
beq $t0, $0, shift
addi $v0, $v0, 1
shift: srl $a0, $a0, 1
j count
done: