What is the basic purpose of an if-else statement in programming?
An if-else statement lets the program choose between two paths based on a condition: one path if the condition is true, and another if it is false.
Click to reveal answer
beginner
How is a condition typically checked in ARM assembly for an if-else structure?
A condition is checked by comparing values using instructions like CMP, which sets flags in the processor. Then conditional branch instructions decide the flow based on those flags.
Click to reveal answer
beginner
What ARM instruction is used to compare two registers?
The CMP instruction compares two registers by subtracting one from the other and setting condition flags without storing the result.
Click to reveal answer
intermediate
Name two ARM conditional branch instructions used in if-else implementations.
BNE (Branch if Not Equal) and BEQ (Branch if Equal) are commonly used to control flow after a comparison.
Click to reveal answer
beginner
Why is it important to use labels in ARM assembly when implementing if-else?
Labels mark positions in code to jump to, allowing the program to skip or execute blocks of instructions based on conditions, mimicking if-else logic.
Click to reveal answer
Which ARM instruction sets the condition flags for branching decisions?
ACMP
BMOV
CADD
DSTR
✗ Incorrect
CMP compares two values and sets condition flags used by branch instructions.
What does the BNE instruction do in ARM assembly?
ABranches if values are not equal
BBranches if values are equal
CBranches always
DBranches if greater
✗ Incorrect
BNE means Branch if Not Equal, used after a CMP instruction.
In an if-else structure, what is the role of labels in ARM assembly?
AStore data
BMark jump points for branching
CPerform arithmetic
DLoad values
✗ Incorrect
Labels mark where the program should jump to based on conditions.
Which instruction would you use to jump unconditionally in ARM assembly?
ABEQ
BBNE
CB
DCMP
✗ Incorrect
The B instruction causes an unconditional branch to a label.
What is the first step in implementing an if-else in ARM assembly?
AUse a branch instruction
BDefine labels
CLoad values
DCompare values with CMP
✗ Incorrect
You first compare values to set condition flags for branching.
Explain how an if-else statement is implemented in ARM assembly language.
Think about how the program decides which code to run based on a condition.
You got /5 concepts.
Describe the role of the CMP and branch instructions in controlling program flow for if-else in ARM assembly.
Focus on how comparison and branching work together.
You got /5 concepts.
Practice
(1/5)
1. In ARM assembly, which instruction is primarily used to compare two values before an if-else branch?
easy
A. MOV
B. CMP
C. ADD
D. STR
Solution
Step 1: Understand the purpose of CMP
The CMP instruction compares two registers by subtracting one from the other and setting condition flags without storing the result.
Step 2: Identify its role in if-else
These condition flags are then used by branch instructions to decide which code path to take, implementing if-else logic.
Final Answer:
CMP -> Option B
Quick Check:
Compare = CMP [OK]
Hint: CMP sets flags for branching decisions in if-else [OK]
Common Mistakes:
Confusing CMP with MOV which moves data
Using ADD instead of CMP for comparison
Thinking STR stores comparison results
2. Which of the following is the correct syntax for a conditional branch in ARM assembly that jumps if two values are equal?
easy
A. BNE label
B. BL label
C. BEQ label
D. BGT label
Solution
Step 1: Understand branch conditions
BEQ means 'Branch if Equal', which jumps if the zero flag is set after a CMP instruction.
Step 2: Match condition to syntax
BNE means 'Branch if Not Equal', BGT means 'Branch if Greater Than', and BL is 'Branch with Link' (function call), so only BEQ matches the condition for equality.
Final Answer:
BEQ label -> Option C
Quick Check:
Equal branch = BEQ [OK]
Hint: BEQ branches when values are equal after CMP [OK]
If R2 equals 5, BNE is not taken, so MOV R3, #1 executes, then execution continues to else_label and MOV R3, #0 runs.
Step 2: Identify missing branch
There is no branch to skip the else block after the if block, so both blocks run sequentially, overwriting R3.
Final Answer:
Missing branch to skip else after if block -> Option A
Quick Check:
Missing jump after if causes both blocks to run [OK]
Hint: Add branch after if block to skip else [OK]
Common Mistakes:
Assuming else block is skipped automatically
Using wrong branch instruction
Ignoring label definitions
5. How would you implement a nested if-else in ARM assembly to check if R4 is greater than 10, then if R5 equals 20, setting R6 to 1; else set R6 to 0?
hard
A. Use CMP and BGT for R4, then CMP and BEQ for R5 with nested labels
B. Use only one CMP for both conditions combined
C. Use MOV instructions without branches
D. Use STR to store comparison results
Solution
Step 1: Implement outer if with CMP and BGT
Compare R4 with 10 using CMP, then branch with BGT to inner if block if true.
Step 2: Implement inner if with CMP and BEQ
Inside the inner block, compare R5 with 20 and branch with BEQ to set R6 to 1; else set R6 to 0.
Step 3: Use labels to separate blocks
Use labels to mark inner if, else, and end blocks to control flow clearly.
Final Answer:
Use CMP and BGT for R4, then CMP and BEQ for R5 with nested labels -> Option A
Quick Check:
Nested if uses CMP + BGT then CMP + BEQ [OK]
Hint: Use nested CMP and conditional branches with labels [OK]
Common Mistakes:
Trying to combine conditions in one CMP
Skipping branches for nested logic
Using STR instead of branch instructions
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.