assemblyknuthtaocp

Why does the ADD command in Donald Knuths number one program written on MIX set the overflow to ON?


Here is the program:

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

What I know so far:

Memory 1 is set to zero with the first command - the ADD function should simply add zero to Register A.

If Mem1 is set to zero how does this set the overflow toggle to on?

REF: The Art of Computer Programming Volume 1 Page 142 Question 18


Solution

  • The program appears to use location 1 as data, and so the code itself should be located somewhere past that, as a stab in the dark, say starting from 0x10.  If the code is located starting at 0 (or 1) then it will overwrite itself, with undesired results.

    Older computers, like PDP-8, would start the program counter at 0, but also use data down low like that (on the zero page), so you would see programs contain a first instruction at 0 being a JUMP to the actual code start, then data after that, then the actual code.