Exercise 2: Tracing the Broken Return Path in A-Calls-B-Calls-C — Possible Solution ==================================================================== WHICH REGISTER GETS OVERWRITTEN, AND WHEN ------------------------------ R7 is the register that gets overwritten. Per the chapter's own example: 1. A executes JSR B. This sets R7 to "the address right after this JSR in A" -- call it return-to-A. 2. B executes JSR C. This OVERWRITES R7, setting it to "the address right after this JSR in B" -- call it return-to-B. At this exact moment, return-to-A is gone; nothing in the CPU still holds it anywhere. WHY THE RETURN PATH BREAKS ------------------------------ By the chapter's own reasoning, R7 can only ever hold ONE return address at a time, because it's a single ordinary register, not a structure capable of holding multiple values. The moment B's own JSR C runs, R7's contents change from return-to-A to return-to-B -- there is no mechanism preserving the old value anywhere else. When B eventually executes RET, it correctly jumps to return-to-B (since that's genuinely what R7 holds by then) -- but this only appears to "work" because C's own execution and B's own RET happen to run before anyone needs return-to-A again. return-to-A itself has already been permanently lost the instant B's JSR C executed -- if A's own caller later needed to actually resume A's flow via that original return address, there would be no way to recover it, since it was never saved anywhere once R7 got reused. THE ROOT CAUSE ------------------------------ The failure isn't really about A, B, or C individually -- it's that a single shared register (R7) is being used to hold what is really TWO separate pending return addresses (A's and B's) at overlapping points in the program's execution, and a single register has no way to hold two values simultaneously. This is precisely the situation the chapter identifies as needing a stack -- a structure that can hold more than one pending value and give them back in the correct (last-in-first-out) order. WHY THIS WORKS AS AN ANSWER ------------------------------ It traces the exact moment R7 changes value, names both addresses it holds at different points (return-to-A, then return-to-B), and explains the root cause as a single register being asked to hold two simultaneously-pending values -- exactly the problem a stack solves.