Exercise · Volume 1 · 1.3.1-21
Exercise 1.3.1-21
not stated yet in Lean solution written
| Rating | 24 |
|---|---|
| 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
Decide if rJ can be zero, and write a program that sets rJ to a given without changing any memory cell.
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
What instructions change rJ? Which ones can put the value in it?
Hint 2
To set rJ to a jump must be made from the cell . So an instruction must stand there for a moment.
Solution
Show the solution
(a) The only operations that change rJ are the jumps (except JSJ). A jump from the cell sets rJ to . No operation loads rJ from memory or from a register. So rJ can be only at the start, after the machine start (the "GO button" of Exercise 1.3.1-26), and never again.
(b) Place a JMP into the cell for a moment, jump there, and then restore the cell:
ORIG 3000
START LDX -1,4
LDA JUMPW
STA -1,4
JMP -1,4
BACK STX -1,4
HLT
JUMPW JMP BACK
The instruction LDX -1,4 saves the word of cell in rX. Then LDA JUMPW loads the word JMP BACK and STA -1,4 stores it into the cell . The instruction JMP -1,4 goes to that cell. The word there is JMP BACK. It is a jump from the cell , so rJ becomes . Then it goes to BACK, which restores the old word from rX. Memory is unchanged and the machine stops with rJ equal to . Because , the cell lies in and does not touch the program. The time is without the HLT.
Check
A simulator run for and for and gave rJ every time. A comparison of all 4000 cells before and after the run showed no change except in rA and rX.
Remarks
The same trick sets rJ to any value from to if the program is put in other cells.
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.