TAOCP 1.4.3.1 Exercise 4

Exercise 1.

Section 1.4.3.1: A MIX Simulator

Exercise 4. [14] Change the program in the text so that it begins as though MIX's "GO button" had been pushed (see exercise 1.3.1-26).

Verified: yes
Solve time: 39s


Solution

Exercise 1.4.3.1.4 [14] asks to modify the MIX simulator program so that it begins execution as though MIX's "GO button" had been pushed. In the MIX hardware, pushing the GO button causes the following actions (see exercise 1.3.1-26):

  1. The location counter $rI6$ is set to 0, indicating the first instruction to fetch.
  2. The overflow toggle OVTOG is cleared.
  3. The comparison indicator COMPI is set to 0.
  4. The simulated clock CLOCK is reset to 0.
  5. The instruction fetch cycle begins immediately.

In Program M, the original initialization sequence is as follows:

003 BEGIN   STZ  TIME(0:2)
004         STZ  OVTOG
005         STZ  COMPI
006         ENT6 0

Here, ENT6 0 sets the instruction location rI6 <- 0. The simulated time TIME is initialized to zero, and the overflow toggle and comparison indicator are cleared. This already partially corresponds to pushing the GO button. However, in the original simulator, execution begins with the first instruction of the simulator itself, rather than the simulated program at location 0000. Therefore, to mimic the GO button, we must redirect the simulator to fetch the first instruction of the simulated program at location 0000.

Define a new label GO as the start of the GO-button initialization. The necessary steps are:

  1. Clear the registers that MIX clears upon GO: OVTOG, COMPI, and CLOCK. The STZ instruction already sets a memory location to zero. Since CLOCK is incremented in TIME, we also zero TIME.
  2. Set rI6 <- 0 to start at the first simulated instruction.
  3. Jump to the standard fetch-execute cycle at CYCLE.

The modified initialization sequence is therefore:

002         ORIG 3500
003 GO      STZ  TIME(0:2)       Clear simulated clock
004         STZ  OVTOG           Clear overflow toggle
005         STZ  COMPI            Clear comparison indicator
006         ENT6 0                Set instruction counter to first location
007         JMP  CYCLE            Begin fetch-execute cycle

With this modification, the simulator begins execution as though the GO button had been pushed: the simulated program's location counter starts at 0, the overflow toggle and comparison indicator are cleared, and the simulated clock begins at 0. The control then transfers to the CYCLE routine, which implements the standard instruction fetch, unpack, indexing, and execution process.

All other parts of Program M remain unchanged, so that the switching table, subroutines, and register conventions are unaffected. The BEGIN label is no longer required and can be removed or retained for reference; it is now superseded by GO.

This completes the solution.