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-7

Exercise 1.4.3.1-7

not stated yet in Lean solution written

Rating32
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 solutions of Exercise 6 so that an IN or OUT does not move data at once. The transmission takes place after about half of the time of the device.

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

Keep for each unit a time of transmission and the address of the area. The time has a value that is never reached when no transmission waits.

Hint 2

The control routine must look at these times at each cycle, after the clock has been advanced.

Hint 3

When a new operation comes to a unit that has a transmission waiting, or when IOC or HLT is simulated, finish the waiting transmission first.

Solution

Show the solution

The unit now has two additional cells: PEND holds the time when the data is moved, and PADDR holds the address MM. When there is no waiting transmission, PEND holds a very large value NEVER, for example 10910^9, which is less than 64564^5.

The routine XMIT does the real transmission for the unit in rI1, if one is waiting, and then sets PEND to NEVER.

XMIT    STJ  9F
        LDA  PEND,1
        CMPA NEVER
        JE   9F             Nothing waits.
        LD2  PADDR,1
        J1NZ 1F
        IN   0,2(16)
        JBUS *(16)
        JMP  2F
1H      OUT  0,2(18)
        JBUS *(18)
2H      LDA  NEVER
        STA  PEND,1
9H      JMP  *
PEND    CON  1000000000
        CON  1000000000
PADDR   CON  0
        CON  0
NEVER   CON  1000000000
T5000   CON  5000
T3750   CON  3750

In IN, OUT and IOC insert JMP XMIT directly after JMP WAIT. Without this a waiting transmission of the same unit would be lost, because the clock was moved by WAIT beyond its time. In IN and OUT replace the two lines of the real transmission (IN 0,5(16) with the JBUS, or OUT 0,5(18) with the JBUS) by lines that remember the transmission, with T/2=5000T/2 = 5000 for IN and 37503750 for OUT:

        LDA  T5000          (T3750 for OUT)
        ADD  CLOCK
        STA  PEND,1
        ST5  PADDR,1

The control routine looks at both times after the line STA CLOCK (line 009). The instructions below are inserted there. They use rI1, rI2 and rA, and these registers are free at this place.

        LDA  CLOCK
        CMPA PEND
        JL   1F
        ENT1 0
        JMP  XMIT
1H      LDA  CLOCK
        CMPA PEND+1
        JL   2F
        ENT1 1
        JMP  XMIT
2H      NOP

At last, the simulation of HLT must call XMIT for the units 0 and 1 before it stops, so that no transmission is lost. For the JBUS * that moves the clock, nothing more is needed: the next cycle sees the new time and does the transmission.

This costs about 7 more units in each cycle of the simulator, and it gives the effect that was wanted. A program that reads the buffer right after an IN, or that changes the buffer right after an OUT, now works with the old contents, as it does on a real machine that moves the data later. A program that waits with JBUS before it uses the buffer works as before.

Check

On a MIX simulator three kinds of simulated programs were run. First, programs that wait for the unit before they use the buffer gave the same lines, the same memory and the same final clock as the real instructions: 45007 and 27513 in two cases. Second, a program with IN 1000(16) followed at once by LDA 1000 saw the old content of location 1000 (777 in the test) and not the card. Third, a program with OUT 1100(18) followed by STZ 1100 and JBUS *(18) printed the line with the changed first word, and a program that ends right after an OUT still printed its line, because HLT finishes the transmission.

Remarks

If more units must be handled, the cells PEND could be kept in a sorted list, as the time to the next event. The comparison at each cycle would be one test only.

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.