162k views
2 votes
Fill in the following with different types of branches so that A will be performed only if r0 > 2

and B will be performed if r0 < 5. Treat ro as signed. (Three blanks to fill)
cmp r0, #2
Next
Next
cmp r0, #5
Exit
;A (only happens if r0 > 2)
Exit
B (only happens if r0 < 5)

1 Answer

2 votes

Final answer:

To conditionally execute instructions A and B based on the value of r0, we need to use the appropriate branch instructions such as BLT and BGT after comparison instructions.

Step-by-step explanation:

To ensure that instruction A is executed only if r0 > 2, and B is executed only if r0 < 5, we need to use appropriate branch instructions after comparing the value of r0 with the constants 2 and 5 respectively. Given that we have limited context, the assembly mnemonic used for the branch will depend on the specific assembly language, but typically BLT (Branch if Less Than) and BGT (Branch if Greater Than) or their equivalents are used.

The code with the filled branches could look something like this:

cmp r0, #2
BGT A ; Branch to A if r0 > 2
Next
B < Exit ; Continue to next instruction if r0 <= 2
A: ; A (only happens if r0 > 2)

Next
cmp r0, #5
BLT B ; Branch to B if r0 < 5
Exit
B: ; B (only happens if r0 < 5)
User Armbrat
by
8.8k points