Exercise · Volume 1 · 2.2.4-14
Exercise 2.2.4-14
not stated yet in Lean solution written
| Rating | 22 |
|---|---|
| Kind | K6, write a program: write a MIX or MMIX program from the written solution |
| Section | Section 2.2.4 of Volume 1 |
The task
Write a MIX subroutine ZERO, called by JMP ZERO, that leaves in rI2 the address of a new polynomial equal to .
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
The zero polynomial is the sentinel alone, with its link pointing to itself.
Solution
Show the solution
ZERO STJ ZEXIT
LD2 AVAIL rI2 <- new node.
J2Z OVERFLOW
LDX 1,2(LINK)
STX AVAIL
STZ 0,2 Coefficient 0.
ST2 1,2(LINK) Link of the sentinel to itself.
ENNA 1
STA 1,2(ABC) ABC = -1, in the ABC field only.
ZEXIT JMP *
The store ST2 1,2(LINK) is done before the store into the ABC field, so the second store does not change the link, since it writes only the field .
The time is units, with the call.
Check
In the simulator the subroutine gave a polynomial that read as in every one of 300 runs, each used one node of the AVAIL list, and each took units.
Remarks
Together with Exercises 11 and 13 this subroutine completes the set of operations that a program on polynomials needs: make, copy and free.
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.