What does the given MIPS assembly language code do Sums the
Solution
I\'ll give a brief description what the code does and arrive at the correct option
QUESTION 10
$s2 is initialised to 0 and $t1 = 10 (because size of array)
$s3 is loaded with the value at address $t0. So it loads the first element of the array.
Then s2 = s2 + s3. Now s2 = first element of array.
T0 is increased by 4. because to get to next integer. 4 b\'cos it the size of integer.
T1 is decremented by 1. Acts as a count and says how many the loop will have to run further
So, this code \"sums the values in an integer array\" - OPTION (a)
QUESTION 9
S0 is initialised to 0
lbu is the Load Byte Unsigned
In each iteration, T0, S0 is incremented by 1. (to increase count and moving to next element of array)
At the start of each iteration, it is checked that if the present element S1 is null or not using \"beq\".
The loop ends when then element is NULL and till then the count increases.
So, the code \"Determines the length of a null-terminated string\" OPTION C
QUESTION 8
c= c+1. ie., s2 = s2+s0. the code should be add $s2,$s2,$s0
a = a-1 i.e., s0=s0+(-1) the code should be addi $s0,s0,-1
The loop should run as along as a is not equal to b. so we can use bne command.
the code should be bne $s1,$s0,loop (here s1 and s0 can be interchanged)
So, the code is option D.
PS: There is no \'subi\' instruction in MIPS
QUESTION 6
sw is the instruction for storing or writing contents.
Size of integer is 4 bits. So, the 4th element is 16 bits away from start address ie., $s0.
The instruction sw $t2,16($s0) means contents of $t2 are stored in 4th integer address from $s0.
So this is our answer. OPTION B
