Exercise · Volume 1 · 1.3.1-7
Exercise 1.3.1-7
not stated yet in Lean solution written
| Rating | M15 |
|---|---|
| Markers | M (mathematical) |
| 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
Define the result of DIV in the no-overflow case by the functions and .
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 registers hold signs and magnitudes, not two's complement numbers. Treat magnitudes first.
Hint 2
Then look at what the signs do: the sign of rX and the sign of rA after the instruction.
Solution
Show the solution
Let be the magnitude of the ten-byte number rAX and the magnitude of . Assume and (otherwise overflow occurs and the machine sets the toggle). After DIV:
The sign of rX is the old sign of rA. The sign of rA is if the old signs of rA and of were equal, and otherwise.
In terms of signed numbers, let with the sign of rA. If (sign ), then . In particular, for and this is the floor division of by , and for it is the ceiling of . The remainder has the sign of the dividend, not of the divisor.
Check
python3 with signed values, , : the pairs give . In each case .
Remarks
The rule differs from the floor rule of Section 1.2.4, because the magnitude is divided and the sign is attached afterwards.
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.