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

Suppose you wish to convert the following pseudo-code to PLP: if(a == 0) { a = 2

ID: 671923 • Letter: S

Question

Suppose you wish to convert the following pseudo-code to PLP:

if(a == 0)
{
a = 2;
}
else
{
a = 1;
}

Select the PLP snippet that will have the same functionality as the pseudo-code. Assume a is contained in $t0.

None of the above

a.
  bne $t0, $0, label_1  nop  li $t0, 1  j label_2  nop  label_1:  li $t0, 2  label_2:  
b.
  beq $t0, $0, label_1  nop  li $t0, 2  j label_2  nop  label_1:  li $t0, 1  label_2:  
c.
  beq $t0, $0, label_2  nop  bne $t0, $0, label_1  nop    label_1:  li $t0, 1  label_2:  li $t0, 2    label_3:    
d.
  beq $t0, $0, label_1  nop  bne $t0, $0, label_2  nop    label_1:  li $t0, 2  j label_3  nop  label_2:  li $t0, 1  j label_3  nop    label_3:    
e.

None of the above

Explanation / Answer

if(a == 0)
{
a = 2;
}
else
{
a = 1;
}

--------
Answer:
--------

d.  
   beq $t0, $0, label_1
   nop
   bne $t0, $0, label_2
   nop

   label_1:
       li $t0, 2
       j label_3
   nop

   label_2:
       li $t0, 1
       j label_3
   nop

   label_3:

--------------
Explanation:
--------------
   Option d is the correct answer.

If Branch On Equal on 0 value with 'a' value then jump to lable_1
If not then check for Branch on Not Equal on 0 with 'a' value then jump to lable_2

On each lable if lable_1 is selected the value 2 is assigned to 'a' and exit the program with jump label_3
On each lable if lable_2 is selected the value 3 is assigned to 'a' and exit the program with jump label_3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote