5.115 · exercise

Basic quiz: loops

Pre-test and post-test loops: when the test runs, where the step goes, how a branch condition sets the last pass, and which register keeps a counter safe across a call.

0 of 6 correct

Multiple choice

A while loop and a do-while loop both repeat while i < n. If i and n both start at 0, how many times does each body run?

Multiple choice

In the pre-test layout these lessons use, the test sits below the body. What makes the test run before the first pass?

Multiple choice

A loop calls printf on every pass. Which register should hold its counter?

Multiple choice

for (i = 0; i < 4; i++) is rewritten as a while loop before it becomes assembly. Where does i++ go?

Multiple choice

A loop should print 1 to 5. i starts at 1, and the test at the bottom is cmp i_r, 5 followed by b.lt loop_body. What does it print?

Multiple choice

A countdown starts i at 10. Each pass ends with sub i_r, i_r, 1 and then cmp i_r, 0. Which branch back to the body makes the passes run for i = 10 down to 1, and no further?