What does the given MIPS assembly language code do Sums the

What does the given MIPS assembly language code do? Sums the values in an integer array. Compares two strings (i.e. character arrays). Searches a null-terminated string for the letter \'A\'. Sorts the array. None of the above. What does the given MIPS assembly language code do? Copies a string (i.e. a character array). Sums the values in an integer array. Determines the length of a null-terminated string. Determines the maximum value in an array. None of the above. Write the MIPS assembly code to implement the given C code. Write the MIPS assembly language instruction to write the contents of register $t2 to array element A[4]. Assume the following $s0 contains the starting address of array A. A is an array of 32-bit integers. sb $t2, 4($s0) sw $t2, 16($s0) lw $t2, 16 ($s0) lbu $s0, 4($t2) sw $s0, 4($t2)

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

 What does the given MIPS assembly language code do? Sums the values in an integer array. Compares two strings (i.e. character arrays). Searches a null-terminat

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site