Exercise · Volume 1 · 1.4.1-1
Exercise 1.4.1-1
not stated yet in Lean solution written
| Rating | 10 |
|---|---|
| Kind | K3, find a value: compute a number, a set or a closed form from the written solution |
| Section | Section 1.4.1 of Volume 1. Companion chapter: Subroutines |
The task
Write down the calling sequence, the entry conditions and the exit conditions of subroutine (5), which has two entrances, in the style of the specification of Program 1.3.2M.
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
Read what the two entrances do before they join: one of them loads itself, the other expects in a register.
Hint 2
The exit conditions are those of MAXIMUM, with one register change: look at which index register carries the parameter now, and which registers the code uses.
Solution
Show the solution
The subroutine has two entrances.
- Calling sequence:
JMP MAX100when , orJMP MAXNfor general . - Entry conditions: for the entrance
MAXN, rI3 , and is assumed. The entranceMAX100has no entry condition, since it sets rI3 itself. - Exit conditions: rA , rI3 , and rI2 holds the largest index at which the maximum occurs. The registers rI1 and rX are not changed. The registers rJ and the comparison indicator are changed (see Exercise 1.4.1-3 for their exact values). No memory cell outside the subroutine is changed.
Two details need care. First, the parameter is in rI3 on entry and not in rI1, so the caller can leave rI1 alone. Second, MAX100 is a real entrance and not a call of MAXN: the instruction ENT3 100 does not change rJ, so the following STJ EXIT still stores the return address of the original JMP MAX100.
Check
Put the values in and call MAXN with rI3 . Exit conditions: rA , rI2 (the last of the two nines) and rI3 . A run of the code on a MIX simulator, with random tables of length and , gave these values every time and left rI1 and rX alone.
Remarks
The characteristics of a subroutine are its contract with the caller. A caller may rely on every register that the list does not mention. See the C1 chapter on Section 1.4.1.
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.