I'm working my way through Ralph Gorin's "Intorduction to DECSYSTEM-20 Assembly Language Programming". For one of the exercises I wanted to initialize an accumulator to a negative integer value. My first try was an assembly instruction like:
MOVEI 10,-6 ;Move -6 to accumulator 10
However, when the program runs, the contents of the accumulator are not treated like a negative number, and DDT shows the contents of accumulator 10 to be 777772.
Next I tried:
MOVNI 10,6 ;Negate 6 and move result to accumulator 10
Which gets treated like a negative number as expected. DDT shows the contents of the accumulator after the above instruction to be -6 (777777,,777772).
I couldn't find an explanation for this in the Gorin text, but think I have figured out what is going on with the MOVEI instruction:
1. The assembler sees "-6" in the program source and interprets it as a 36-bit (one word) twos-complement integer value, 777777,,777772.
2. Based on where the "-6" appears in the instruction syntax, the value is assigned to the instruction's address field Y.
3. Since the Y field is only 18-bits long, the value's upper half-word is truncated, and the value actually assigned to the Y field is 777772.
4. MOVEI takes the Y value and assigns it to the accumulator.
5. Since the accumulator is a 36-bit word and the value of Y is only 18-bits, the upper half-word of the accumulator is set to 0, making the contents of the accumulator 0,,777772, which is not the same as -6 (777777,,777772).
On the other hand, MOVNI takes positive 6, negates it (777777,,777772), then puts that value in the accumulator like I wanted.
Have I got it figured out, or is something else going on? (I'm working on
twenex.org TOPS-20.)