taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.4.3.1-4

Exercise 1.4.3.1-4

not stated yet in Lean solution written

Rating14
KindK6, write a program: write a MIX or MMIX program from the written solution
SectionSection 1.4.3.1 of Volume 1. Companion chapter: A MIX simulator

The task

Change the simulator so that it begins as if the GO button was pressed.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Read what the GO button does in Exercise 1.3.1-26: one card goes into locations 0000 to 0015, then rJ and the overflow toggle are cleared, and control goes to location 0000.

Hint 2

The simulator already clears the overflow toggle, sets the J-register to zero, and starts at location 0.

Solution

Show the solution

Only the card must be read. Put two instructions at the start of the program, after the first line that clears the clock:

BEGIN   STZ  TIME(0:2)
        IN   0(16)          Read one card into locations 0000 to 0015.
        JBUS *(16)          Wait until the card has been read.
        STZ  OVTOG
        ...

The remaining lines stay. The simulated memory is part of the real memory, so the card words are at once the simulated locations 0,…,150, \ldots, 15. The line STZ OVTOG makes the overflow toggle off, JREG is zero from its initial value, and the location counter rI6 is set to zero by the line ENT6 0, which is the jump to location 0. The card cannot spoil the simulator, because the 16 words are far below location BEGIN.

Check

The changed simulator was run on a MIX simulator with a card whose first five characters were BE (the word of the instruction HLT), and with the overflow toggle set to one before the start. The simulated machine halted at once, location 0 and location 1 held the first two card words, JREG was zero, and OVTOG was zero.

Remarks

In a simulator for a computer with another character code, the card must also be translated from its own code to the MIX character code. This is why the real change is longer there.

This solution is drafted, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.