TAOCP 1.3.2 Exercise 2

The instruction on line 12 is located at `EXIT`, and it is initially assembled as `JMP *`, that is, a jump to itself.

Section 1.3.2: The MIX Assembly Language

Exercise 2. ▶ [10] Line 12 of Program M says JMP *, where * denotes the location of that line. Why doesn't the program go into an infinite loop, endlessly repeating this instruction?


* The author was astonished to learn in 1971 that MIXAL is also the name of a laundry detergent in Yugoslavia, developed for use with automate [automatics].

Verified: yes
Solve time: 1m13s


The instruction on line 12 is located at EXIT, and it is initially assembled as JMP *, that is, a jump to itself. However, line 03 executes

$$ \text{STJ EXIT}, $$

which stores the contents of register rJ into the address field of the instruction at EXIT.

When the main program executes

JMP MAXIMUM

the MIX machine automatically places the return address, namely the location of the instruction following that jump, into rJ. Therefore line 03 changes the instruction at EXIT from

JMP *

to

JMP <return address>.

Consequently, when control reaches line 12, the instruction no longer jumps to itself. It jumps back to the calling program at the stored return address, and the subroutine returns normally instead of entering an infinite loop. ∎