QUESTION 4 Which of the following code snippets will branch to the label, is one
ID: 3741316 • Letter: Q
Question
QUESTION 4 Which of the following code snippets will branch to the label, is one, only if bit 0 of $t0 contains the value, 1? Hint: Make sure you understand "bit masking" explained in the video lecture. andi $to, Sto, 0 beq Sto, s0, is_one nop code for when bit 0 of Sto is zero is_one: code for when bit 0 of $to is one andi Sto, Sto, bne Sto, s0, is_one nop -# code for when bit 0 of $t0 is zero is one: code for when bit 0 of $t0 is one andi Sto. St0, 1 beq Sto, s0,is one nop -# code for when bit 0 of $to is zero is zero: code for when bit o of sto is oneExplanation / Answer
Assmply program in question sepcified is:
andi $t0, $0, 0 or 1 ( based on option)
beq or bne $t0, $0, is_one ( based on option)
nop
# code for when bit 0 of $t0 is 0
is_one:
... # code for when bit 0 of $t0 is 1
1. The instruction andi does the bitwise 'and' of the 2 operand passed and stores the same in first operand. Therfore in option 1 and 2 $t0 is cleared and all bits are set '0'. While in option 3 & 4 the bit 0 of $t0 is et to 1
2. Intruction beq check the 2 operand passed is equal or not if equal control is paased to label specified by third operand. In first option we are cheking that 2 operand are equal but the the operand are zero. So they are not cheking the bit 0 of $t0 is one or not.
3. Now the option 3 is setting the bit 0 of $t0 as 1 using instruction andi $t0, $t0, 1 and rest are cleared.
4. beq instruction in option 3 checks if value in $t0 is eqal to 1 or not. It brances to Is_one label. Effectively it is checking if bit 0 of $t0 is one and brances to is_one label.
4. Therfore option 3 (below) is the corect option:
andi $t0, $0, 1
beq $t0, $1, is_one
nop
# code for when bit 0 of $t0 is 0
is_one:
... # code for when bit 0 of $t0 is 1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.