Exercise · Volume 1 · 2.2.4-13
Exercise 2.2.4-13
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 2.2.4 of Volume 1 |
The task
Write a MIX subroutine ERASE, called by JMP ERASE with rI1 , that returns all nodes of to the AVAIL list.
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 polynomial is a circular list. Operation (2) of the text gives the way to free a whole circular list in constant time.
Solution
Show the solution
The nodes form a circle with the sentinel. Let the AVAIL list be . We set , which is , and . Now the old circle has been opened at the sentinel, and runs through .
ERASE STJ EEXIT
LDA AVAIL rA <- old top of AVAIL.
LDX 1,1(LINK) rX <- first node of the polynomial.
STX AVAIL
STA 1,1(LINK) The sentinel now points to the old top.
EEXIT JMP *
The time is units, with the call, whatever the number of terms.
Check
I applied the subroutine in the simulator to random polynomials. After the call the AVAIL list had grown by nodes, and the first nodes were those of the polynomial. The time was units each time. For a polynomial that is , the list is the sentinel alone, and the code works as well, since then .
Remarks
The sequence of the exercise statement, LD1 Q, JMP ERASE, LD1 P, JMP COPY, ST2 Q, therefore sets in units, where the sum counts the three loads and stores of units each, the call of ERASE with , and the call of COPY with .
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.