In ARM assembly, which register is commonly used to hold the loop counter before entering a loop?
Think about the general-purpose registers used for data and counters.
R0 is a general-purpose register commonly used to hold values like loop counters. PC is the program counter, LR is the link register, and R7 is often used for system calls.
Which ARM assembly instruction is used to decrement a register value by 1?
Look for the instruction that subtracts a value.
SUB R0, R0, #1 subtracts 1 from R0, effectively decrementing it. ADD adds, MOV moves a value, CMP compares.
Given the following ARM assembly snippet, what condition causes the loop to exit?
loop:
SUB R0, R0, #1
CMP R0, #0
BNE loopConsider what BNE means and when it branches.
BNE means branch if not equal. The loop continues while R0 is not zero. When R0 reaches zero, the loop exits.
Which of the following ARM assembly loops correctly counts from 5 down to 1?
Check the order of instructions and the comparison value.
Option C initializes R0 to 5, decrements before comparing to zero, and loops while not zero, correctly counting down from 5 to 1.
Option C counts up, not down. Option C compares before decrementing, causing off-by-one. Option C compares before decrementing, causing incorrect behavior.
Consider this ARM assembly loop:
MOV R0, #10
loop:
SUB R0, R0, #2
CMP R0, #0
BGT loopHow many times will the loop execute before exiting?
Count how R0 changes each iteration and when the loop stops.
R0 starts at 10 and decreases by 2 each loop: 10, 8, 6, 4, 2, 0. The loop continues while R0 > 0. When R0 reaches 0, CMP sets zero flag and BGT (branch if greater than zero) fails, so loop exits. The loop runs 5 times (for R0=10,8,6,4,2).