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

Exercise 1.4.3.1-5

not stated yet in Lean solution written

Rating24
KindK3, find a value: compute a number, a set or a closed form from the written solution
SectionSection 1.4.3.1 of Volume 1. Companion chapter: A MIX simulator

The task

Find the time that the simulator needs for the operators LDA and ENTA, and compare it with the time of the real MIX instructions.

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

Add the time of the control routine, the time of the subroutines that the operator calls, and the time of the operator routine itself.

Hint 2

The operator ENTA does not call GETV. Find out which routine it uses.

Hint 3

State the cases that change the result: indexing, a field specification with L≠0L \ne 0, and M=0M = 0.

Solution

Show the solution

Count the units of time on the instructions of the program. Loads and stores take 2 units, shifts 2, DIV 12, and jumps and address transfers 1.

The control routine, lines 007 to 036, takes 34 units when the instruction is not indexed. Indexing takes 15 units more (lines 018 to 026, with the first jump of line 017 not taken).

LDA. The subroutine GETV takes 52 units. It calls FCHECK (28 units, of which 12 are for the division) and MEMORY (14 units). One more unit is for the jump that calls GETV. If the field has L≠0L \neq 0, five units more are needed for the lines that clear the bytes to the left of the field. The part of the operator routine after GETV takes 10 units. So

LDA=34+52+1+10=97 units,\text{LDA} = 34 + 52 + 1 + 10 = 97 \text{ units},

plus 15 for indexing and plus 5 for L≠0L \ne 0.

ENTA. The routine ADDROP does not call GETV, because the value of MM is already known. It takes 21 units to reach the common exit, and 2 more if M=0M = 0 (to find the sign of the instruction). So

ENTA=34+21=55 units,\text{ENTA} = 34 + 21 = 55 \text{ units},

plus 15 for indexing, plus 2 if M=0M = 0. For the index registers, the routine SIZECHK must also test the size of the result, and this adds 2 units to LDi and ENTi.

The real MIX runs LDA in 2 units and ENTA in 1 unit. The ratios are 97/2=48.597/2 = 48.5 and 55/1=5555/1 = 55. So a simulated program is about 50 times slower than a real one, when it uses simple operators. The slow parts are the control routine and the checks of the fields and the addresses.

Check

I ran the simulator program of the text on a MIX simulator that has the true instruction times, with 50 copies of one simulated instruction between the start and a HLT, and divided the difference by 50. The results were: LDA 97, LDA with a field (1 ⁣: ⁣5)(1\!:\!5) 102, LDA with an index 112, ENTA 55, ENTA 0 57, ENT1 57 (the size check of an index register adds 2). These values are the same as the sums above.

Remarks

The ratio of 50 is typical for a simulator written for a machine that is like the machine that it runs on. For the programs that use many multiplications the ratio is smaller, because the real multiplication is part of the work. For the jumps it is larger.

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.