Exercise · Volume 1 · 1.3.1-18
Exercise 1.3.1-18
not stated yet in Lean solution written
| Rating | 22 |
|---|---|
| Kind | K8, compute by machine: find a number or an object by a large computation from the written solution |
| Section | Section 1.3.1 of Volume 1. Companion chapter: Description of MIX |
The task
Trace the "number one" program and give the final values of rI1, rA, rX, the toggle, the indicator and the memory cells that it changed.
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
Start with a table of the registers and cells that the program can change: the cells 1 and 2, rA, rX, rI1.
Hint 2
Follow the instructions in order. The instruction ADD 1 is the interesting one: look at the sizes of the two numbers.
Hint 3
NUM and CHAR work on the ten bytes of rA and rX: bytes are taken mod 10 by NUM.
Solution
Show the solution
Assume that the program does not stand in the cells 0, 1 and 2. Step by step:
STZ 1: cell 1 is .ENNX 1: rX is .STX 1(0:1): the field of cell 1 gets the sign and the last byte of rX. So cell 1 is , which is the number .SLAX 1: rX becomes .ENNA 1: rA is .INCX 1: rX becomes , which is .ENT1 1: rI1 is .SRC 1: the ten bytes rotate one place right. The byte goes from the end of rX to the front of rA. So rA is and rX is .ADD 1: rA gets . This does not fit, so the overflow toggle is on and rA is .DEC1 -1: rI1 is .STZ 1: cell 1 is .CMPA 1: rA is and the cell is : they are equal, so the indicator is EQUAL.MOVE -1,1(1): the address is . One word goes from cell 1 to cell 2, and rI1 is . So cell 2 is .NUM 1: the ten bytes are , so the number is , with the sign of rA. So rA is .CHAR 1: the ten digits of are written as character codes, . So rA becomes and rX becomes (the sign of rX is not changed byCHAR; it was ).HLT 1: the machine stops.
The final state: overflow toggle on, indicator EQUAL, , , , cells 1 and 2 hold , all other cells unchanged. The result does not depend on .
Check
The program was run in a simulator with and . Both runs gave the final state above and the register contents after each step as in the list. Note that in the step NUM 1 the number shows as bytes for and for , because .
Remarks
The next exercise adds the execution times of the steps. In the run, the ADD is the only overflow.
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.