Correct the stack pointer when i80 shrinks an integer.

The code used `sphl` to set the stack pointer, but the correct value
was in de, not hl.  Fix by swapping the values of de and hl, so `sphl`
is now correct.  When we shrink an integer from 4 to 2 bytes, both
registers de and hl point to copies of the result, but only one
register preserves the stack below the result.

This fixes writehex() in tests/plat/lib/test.c, when I compile it with
ack -mcpm, so it preserves the pointer to "0123456789abcdef", so it
writes hexadecimal digits and not garbage.

This bug goes back to commit 157b243 of Mar 18, 1985, so the bug is
32 years old, and probably the oldest bug that I ever fixed.
This commit is contained in:
George Koehler 2017-12-07 15:39:41 -05:00
parent 34cf0c8b63
commit c95bcac91d

View file

@ -65,19 +65,19 @@
jmp 3f ! done
!if destination size < source size only:
shrink: mov l,c ! load source size in hl
shrink: mov l,b ! load destination size in hl
mvi h,0
dad sp
mov d,h
mov e,l ! de points just above source
mov l,b ! load destination size in hl
mov e,l ! de points just above lowest bytes of source
mov l,c ! load source size in hl
mvi h,0
dad sp ! hl points just above "destination"
1: dcx d ! move upwards
dcx h
mov a,m
stax d
ldax d
mov m,a
dcr b
jnz 1b
sphl