TAOCP 4.1 Exercise 4
In MIX fixed-point arithmetic, the radix point is understood to be fixed relative to the register positions.
Section 4.1: Positional Number Systems
Exercise 4. [**] [15] Assume that we have a MIX program in which location A contains a number for which the radix point lies between bytes 2 and 3, while location B contains a number whose radix point lies between bytes 2 and 3. (The leftmost byte is number 1.) Where will the radix point be, in registers A and X, after the following instructions?
(a) LDA A; MUL B $\qquad$ (b) LDA A; SRAX 5; DIV B
Verified: no
Solve time: 3m49s
Solution
In MIX fixed-point arithmetic, the radix point is understood to be fixed relative to the register positions. Shift instructions move the digits, not the radix point.
Each 5-byte quantity here has its radix point between bytes $2$ and $3$. Thus a number has the form
$$ d_1d_2.d_3d_4d_5, $$
with two bytes to the left of the radix point and three bytes to the right.
(a) LDA A; MUL B
After LDA A, register $A$ contains the number from location $A$, with radix point between bytes $2$ and $3$.
The instruction MUL B multiplies the 5-byte quantity in register $A$ by the 5-byte quantity in location $B$. The 10-byte product is placed in the register pair $A:X$.
If each operand has two integer bytes, then the product has
$$ 2+2=4 $$
integer bytes. Therefore the radix point in the 10-byte product lies between bytes $4$ and $5$ of the combined $A:X$ register pair.
Since bytes $1$ through $5$ belong to register $A$, this means that the radix point lies between bytes $4$ and $5$ of register $A$.
Hence after MUL B, the radix point in $A:X$ is between bytes $4$ and $5$.
(b) LDA A; SRAX 5; DIV B
After LDA A, the quantity in $A:X$ is
$$ d_1d_2.d_3d_4d_5,00000, $$
where the radix point is fixed between bytes $2$ and $3$ of the 10-byte pair.
Now apply SRAX 5. This shifts the digits of the 10-byte quantity five byte positions to the right. The radix point remains fixed relative to the register positions. Therefore the quantity becomes
$$ 0.00000,d_1d_2d_3d_4d_5. $$
Thus the shifted quantity has five leading fractional bytes before the original digits begin. Relative to the original number, the value has been divided by $64^5$.
Originally the number had two integer bytes. After shifting right by five bytes, it has
$$ 2-5=-3 $$
integer bytes. Equivalently, the radix point lies three byte positions to the left of the left edge of the significant digits.
Now divide by $B$, whose radix point lies between bytes $2$ and $3$. Since the divisor has two integer bytes, the quotient has
$$ -3-2=-5 $$
integer bytes.
The quotient produced by DIV is placed in register $A$. Therefore the radix point of the quotient lies five byte positions to the left of register $A$. Equivalently, register $A$ contains only fractional bytes.
Hence after DIV B, the quotient in register $A$ has its radix point five byte positions to the left of the left edge of $A$.