QUESTION 5 Consider the following fragment of MIPS assembly code. Assumethat bef
ID: 3608672 • Letter: Q
Question
QUESTION 5 Consider the following fragment of MIPS assembly code. Assumethat before the invocation of the program the register $a0 contains a positive value. START: addi $t0, $a0, 0 addi $t1, $zero, 1 addi $t3, $zero, 0 LOOP: beq $t0, $zero, FINISH and $t2, $t0, $t1 srl $t0, $t0, 1 xor $t3, $t3, $t2 j LOOP FINISH: addi $v0, $t3, 0 What will contain register $v0 after the execution of theprogram? QUESTION 5 Consider the following fragment of MIPS assembly code. Assumethat before the invocation of the program the register $a0 contains a positive value. START: addi $t0, $a0, 0 addi $t1, $zero, 1 addi $t3, $zero, 0 LOOP: beq $t0, $zero, FINISH and $t2, $t0, $t1 srl $t0, $t0, 1 xor $t3, $t3, $t2 j LOOP FINISH: addi $v0, $t3, 0 What will contain register $v0 after the execution of theprogram? QUESTION 5 Consider the following fragment of MIPS assembly code. Assumethat before the invocation of the program the register $a0 contains a positive value. START: addi $t0, $a0, 0 addi $t1, $zero, 1 addi $t3, $zero, 0 LOOP: beq $t0, $zero, FINISH and $t2, $t0, $t1 srl $t0, $t0, 1 xor $t3, $t3, $t2 j LOOP FINISH: addi $v0, $t3, 0 What will contain register $v0 after the execution of theprogram?Explanation / Answer
START: addi $t0, $a0, 0 start with a0 with 3 sot0=3addi $t1, $zero,1 t1=1
addi $t3, $zero,0 t3=0
LOOP: beq $t0, $zero, FINISH t0!=3 socontinues $t0=1 so continues $t0=0 soexits
and $t2, $t0,$t1 t2=t0 andt1=1 t2=t0 and t1=1
srl $t0, $t0,1 shift t0 right 1 (1 shifted out)t0=1 shift t0 right 1(1 shiftedout)t0=0
xor $t3, $t3,$t2 t3=1 t3=0
jLOOP go toloop go to loop
FINISH: addi $v0, $t3,0 v0=0+0=0
if the number in $a0 has an odd number of bits set (odd number of1's) $v0 will have a 1 in it
if the number in $a0 has an even number of bits set(even number of1's) $v0 will have a 0 in it
example: if $a0 starts with12,1112,11012,102 these all have an odd number of bits so $vowill finish with a value of 1
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.