TAOCP 1.3.1 Exercise 18

Assume that all registers, toggles, and memory locations initially contain zero.

Section 1.3.1: Description of MIX

Exercise 18. [22] After the following "number one" program has been executed, what changes to registers, toggles, and memory have taken place? (For example, what is the final setting of rI1? of rX? of the overflow and comparison indicators?)

STZ 1
ENNX 1
STX 1(0:1)
SLAX 1
ENNA 1
INCX 1
ENT1 1
SRC 1
ADD 1
DEC1 -1
STZ 1
CMPA 1
MOVE -1,1(1)
NUM 1
CHAR 1
HLT 1

Verified: yes
Solve time: 1m39s


Solution

Assume that all registers, toggles, and memory locations initially contain zero. In particular,

$$ rA=rX=rI_1=\cdots=rI_6=0, $$

the overflow toggle is off, the comparison indicator is undefined but irrelevant, and every memory word is

$$ +,0,0,0,0,0. $$

Only location $1$ is ever referenced, so we trace its contents together with the affected registers.

The instruction

$$ \texttt{STZ 1} $$

stores zero in location $1$:

$$ \text{CONTENTS}(1)=+,0,0,0,0,0. $$

The instruction

$$ \texttt{ENNX 1} $$

enters the negative of address $1$ into $rX$:

$$ rX=-,0,0,0,0,1. $$

The instruction

$$ \texttt{STX 1(0:1)} $$

stores the sign and first byte of $rX$ into field $(0:1)$ of location $1$. The sign becomes negative; the first byte stored is $0$. Hence

$$ \text{CONTENTS}(1)=-,0,0,0,0,0. $$

The instruction

$$ \texttt{SLAX 1} $$

shifts the combined register $(rA,rX)$ left by one byte. Since $rA=0$ and $rX=-1$,

$$ rA=+,0,0,0,0,1,\qquad rX=-,0,0,0,0,0. $$

The instruction

$$ \texttt{ENNA 1} $$

enters the negative of address $1$ into $rA$:

$$ rA=-,0,0,0,0,1. $$

The instruction

$$ \texttt{INCX 1} $$

adds $1$ to the numerical value of $rX$. Since $rX$ represents $0$ with negative sign, its numerical value is $0$, and therefore

$$ rX=+,0,0,0,0,1. $$

The instruction

$$ \texttt{ENT1 1} $$

places $+1$ into index register $rI_1$:

$$ rI_1=+,0,1. $$

The instruction

$$ \texttt{SRC 1} $$

shifts the ten-byte quantity $(rA,rX)$ right circularly by one byte. Before the shift,

$$ (rA,rX)=(-,0,0,0,0,1,;+,0,0,0,0,1). $$

The rightmost byte $1$ moves to the leftmost byte position. The resulting registers are

$$ rA=-,1,0,0,0,0, \qquad rX=+,1,0,0,0,0. $$

The instruction

$$ \texttt{ADD 1} $$

adds the contents of location $1$, namely negative zero, to $rA$. Negative zero has numerical value $0$, hence

$$ rA=-,1,0,0,0,0. $$

No overflow occurs.

The instruction

$$ \texttt{DEC1 -1} $$

subtracts $-1$ from $rI_1$, equivalently adds $1$:

$$ rI_1=+,0,2. $$

The instruction

$$ \texttt{STZ 1} $$

replaces location $1$ by

$$ \text{CONTENTS}(1)=+,0,0,0,0,0. $$

The instruction

$$ \texttt{CMPA 1} $$

compares $rA$ with zero. The value in $rA$ is positive in magnitude, therefore

$$ \text{comparison indicator}=\texttt{GREATER}. $$

The instruction

$$ \texttt{MOVE -1,1(1)} $$

moves one word from location

$$ M=-1+rI_1=-1+2=1 $$

to the destination beginning at the address contained in $rI_1$, namely location $2$. Thus the single word at location $1$ is copied to location $2$:

$$ \text{CONTENTS}(2)=+,0,0,0,0,0. $$

After a MOVE operation, $rI_1$ is increased by the number of words moved, namely $1$, so

$$ rI_1=+,0,3. $$

The instruction

$$ \texttt{NUM 1} $$

converts the ten bytes of $(rA,rX)$, interpreted as decimal digits, into a number in $rA$. The bytes are

$$ 1,0,0,0,0,1,0,0,0,0, $$

which represent the decimal number

$$ 1000010000. $$

Hence

$$ rA=+1000010000. $$

Since

$$ 1000010000 < 1,073,741,823, $$

the value fits in a MIX word, so the overflow toggle remains off.

The instruction

$$ \texttt{CHAR 1} $$

replaces $(rA,rX)$ by the character-code representation of the decimal number in $rA$. The number is

$$ 1000010000, $$

whose ten decimal digits are

$$ 1,0,0,0,0,1,0,0,0,0. $$

Thus the ten bytes of $(rA,rX)$ become exactly those ten digit codes. In MIX notation,

$$ rA=+,1,0,0,0,0, \qquad rX=+,1,0,0,0,0. $$

The instruction

$$ \texttt{HLT 1} $$

halts execution.

Therefore the final state is

$$ rA=+,1,0,0,0,0, $$

$$ rX=+,1,0,0,0,0, $$

$$ rI_1=+,0,3, $$

$$ rI_2=rI_3=rI_4=rI_5=rI_6=+,0,0, $$

$$ \text{CONTENTS}(1)=+,0,0,0,0,0, $$

$$ \text{CONTENTS}(2)=+,0,0,0,0,0, $$

all other memory locations unchanged,

$$ \text{overflow toggle}=\text{off}, $$

and

$$ \text{comparison indicator}=\texttt{GREATER}. $$

Hence the final answer is

$$ \boxed{ \begin{aligned} &rA=+,1,0,0,0,0,\qquad rX=+,1,0,0,0,0,\ &rI_1=+,0,3,\qquad rI_2=\cdots=rI_6=+,0,0,\ &\text{CONTENTS}(1)=\text{CONTENTS}(2)=+,0,0,0,0,0,\ &\text{overflow off},\qquad \text{comparison indicator}=\texttt{GREATER}. \end{aligned} } $$