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

•What value is contained in $t2 upon completion of the MIPS code below: addi $t1

ID: 3602836 • Letter: #

Question

•What value is contained in $t2 upon completion of the MIPS code below:

addi $t1, $zero, 1

sll $t2, $t1, 8

•What value is contained in $t2 upon completion of the MIPS code below:

addi $t0, $zero, 0

addi $t1, $zero, 1

addi $t2, $zero, 2

add $t0, $t1, $t2

slt $t1, $t0, $t1

beq $t0, $zero, L1

add $t2, $t1, $t0

L1: add $t2, $t2, $t0

•Consider the following segment of C code where the variables {u, w, z} reside in {$t1,$t2,$t3} respectively. Complete the corresponding assembly language fragment by writing in the correct instruction or register

while (u == w) { while: __________ $t1, $t2, b

u = u + 1; __________ $t1, $t1, 1
   w = u – z; sub _______, _______, _______

} __________ while

exit:

Explanation / Answer

Please like if you found this solution helpful.Thanks.

1.

addi $t1, $zero, 1

sll $t2, $t1, 8

After execution of the above two line ---

$t1=1 (because addi command adds up $zero and 1 and $zero holds 0)

$t2=256 (sll is left shift operator and it shifts 1 to 8th time left that is

before execution 1's binary value is 0000000001 and after execution

it becomes 100000000 that is 256 in decimal )

2.

addi $t0, $zero, 0 #means $t0= $zero+ 0 where $zero=0 ,after this line $t0=0

addi $t1, $zero, 1 #means $t1= $zero+ 1 where $zero=0 ,after this line $t1=1

addi $t2, $zero, 2 #means $t2= $zero+ 2 where $zero=0 ,after this line $t2=2

add $t0, $t1, $t2 #means $t0= $t1+ $t2 ,after this line $t0=3

slt $t1, $t0, $t1 #SLT -- Set on less than this command means if $t0<$t1 then $t1 =1 else $t1 =0

#after this line $t1=0 as the condition is false

beq $t0, $zero, L1 # beq – Branch on equal this command means if $t0=$zero then execution

#will go to L1 and codes below of this line will be skipped else normal execution

add $t2, $t1, $t0 #after this line $t2=3

L1: add $t2, $t2, $t0 #after this line $t2=$t2+ $t0 =3+3 =6

So after execution of the above lines of code ---

$t0=3

$t1=0

$t2=6

3.

MIPS implementation of the above C program

Loop:

BNE $t1, $t2, exit

addi $t1, $t1, 1

sub $t2,$t1,$t3

j Loop

exit: