Base CS from zero
Control flow: multiple-choice review
Six questions that cut across the whole unit. None asks for a definition. Each asks you to reason about what the program counter does next — which is the single question every branch and every loop reduces to.
Confirm you can connect the four lessons into one model: the program counter drives flow, a compare sets flags, a conditional jump reads one flag bit, a backward jump repeats the body, and an if/else is just two destinations for the PC.
Two running machines hold identical instruction bytes at identical addresses, yet they execute completely different sequences of instructions. How is that possible?
A CMP R0, R1 executes, then a JNE (jump if not equal) is reached. Which single piece of state does the JNE actually inspect to decide jump-or-fall-through?
An if/else compiles to: CMP; conditional-jump-to-ELSE; if-true block; unconditional JUMP to END; ELSE: if-false block; END. Why is the unconditional JUMP after the if-true block necessary?
At the machine level, what is the only structural difference between a compiled while loop and a compiled for loop?
A countdown loop decrements a counter and should exit when it hits 0, but it never exits and pins the CPU at 100%. Which explanation is consistent with how the machine actually runs the loop?
In sumPositives over [3, -1, 4], the inner if skips the negative element. When nums[i] is non-positive, what does the machine do, and does the loop end early?
The whole unit is one through-line: the program counter decides what runs next, and only a jump can change it. A compare sets a flag; a conditional jump reads that one flag and either jumps or falls through; an if/else is two PC destinations with a skip-JUMP guarding the boundary; a loop is a backward jump whose conditional test at the top decides whether to fall into the body again; and a loop runs forever when the tested value never changes. Every branch and loop you will ever read reduces to one question: where does the PC point next, and why.