Exercise · Volume 1 · 1.3.1-20
Exercise 1.3.1-20
not stated yet in Lean solution written
| Rating | 20 |
|---|---|
| Kind | K6, write a program: write a MIX or MMIX program from the written solution |
| Section | Section 1.3.1 of Volume 1. Companion chapter: Description of MIX |
The task
Write a program that puts a HLT into all 4000 cells and then stops.
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
Use MOVE with the source cell fixed and a block size that divides .
Hint 2
The program itself is in the memory, so the last copy overwrites the program. Make the last copy place a HLT where the next instruction would be.
Solution
Show the solution
Plan: put HLT into cell 0, then spread it by MOVE in blocks of words. Because , the block count is exact. The program is put at the end of memory, and the last block overwrites it.
ORIG 3995
START ENT1 0
MOVE 3999
LOOP MOVE 0(43)
JMP LOOP
HLT
The word in cell 3999 is the HLT. ENT1 0 sets the target, and MOVE 3999 copies the HLT into cell 0 and makes rI1 equal to . Each MOVE 0(43) copies the cells into the cells that start at rI1. After the first copy, the cells to hold HLT, and in general after copies the cells to hold HLT. The first MOVE 0(43) copies cell 0 to cell 1, then cell 1 (just written) to cell 2, and so on, so that the cells to all get HLT. After copies, rI1 is and all cells to hold HLT. The last copy overwrites the cells to , including the instruction JMP LOOP in cell 3998. The next instruction to be fetched is cell 3998, which is now HLT, and the machine stops. The time is , plus for the final HLT.
Check
Simulator runs with and , with all other cells set to a non-zero value at the start, ended with all 4000 cells equal to the HLT word () and with time and the HLT. The count in python: 3999 == 93 * 43. The other divisor of that is at most is with copies, which takes .
Remarks
The field of MOVE must be at most , so only and are possible block sizes. The choice is faster.
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.