Exercise · Volume 1 · 2.1-7
Exercise 2.1-7
not stated yet in Lean solution written
| Rating | 04 |
|---|---|
| Kind | K2, decide: say whether a claim holds from the written solution |
| Section | Section 2.1 of Volume 1 |
The task
Choose the MIX code that loads NEXT(TOP) into register A, and say why the other code fails.
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
In MIXAL a symbol stands for an address. Ask what the symbol TOP is in each sequence: the address of the word, or the value in the word.
Solution
Show the solution
In MIXAL the symbol TOP is the address of the word where the link variable is stored. The value of the link variable is the content of that word. The node that TOP points to is at the address that this content gives.
Sequence (a), LDA TOP(NEXT), loads the NEXT field (bytes 4 and 5) of the word at address TOP. This is the NEXT field of the word that holds the variable. By the convention of the section, the link is stored in bytes 4 and 5 of this word. So (a) loads the value of TOP, not NEXT(TOP). It is wrong.
Sequence (b) is right. LD1 TOP puts the value of the variable, the address of the top card, in index register 1. Then LDA 0,1(NEXT) loads the NEXT field of the word at address , which is the top card. This is NEXT(TOP).
Check
Use the pile of (3). Suppose TOP is the word at address and holds . Sequence (a) puts in the NEXT field of rA. Sequence (b) puts in rI1 and then loads the field of location , that is . The wanted value is NEXT(242) .
Remarks
The same difference exists for a numeric variable : LDA X loads its value, and ENTA X loads its address. The link value must go to an index register before a field of the node can be taken.
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.