In ARM assembly, compare and branch instructions are used to control program flow based on conditions. Which of the following best describes the purpose of the CBZ instruction?
Think about what the abbreviation CBZ stands for.
CBZ stands for Compare and Branch on Zero. It checks if a register's value is zero and branches if true.
Which ARM condition code suffix causes a branch if the previous comparison found the values to be not equal?
Recall that NE stands for 'Not Equal'.
The NE condition code means 'Not Equal' and causes a branch if the compared values differ.
Given the following ARM assembly snippet, what will be the value of register R2 after execution if R1 contains 0?
CMP R1, #0
BNE skip
MOV R2, #1
skip:
MOV R2, #2Consider what the BNE instruction does when R1 is zero.
CMP R1, #0 sets flags comparing R1 to zero. Since R1 is zero, the zero flag is set. BNE branches if not equal (zero flag clear), so it does not branch. The instruction MOV R2, #1 executes, then MOV R2, #2 executes unconditionally, so final R2 is 2.
Examine the following ARM code snippet. What error will occur when this code runs?
CMP R0, R1
BEQ label
MOV R2, #5
label:
MOV R2, #10Check the label syntax and branching logic carefully.
The label syntax is correct with a colon. The branch BEQ jumps to label if R0 equals R1, skipping MOV R2, #5. Otherwise, MOV R2, #5 runs followed by MOV R2, #10. No syntax or runtime error occurs.
You want to branch to done only if the value in R3 is less than the value in R4. Which ARM instruction should you use immediately after CMP R3, R4?
Remember that BLT means 'Branch if Less Than'.
After CMP R3, R4, BLT branches if R3 is less than R4. Other options check different conditions.