Personal Computer World magazine: an 8080 puzzle and "Z80 is dead"

From: Paul Williams <celigne_at_tinyworld.co.uk>
Date: Mon Aug 6 16:53:16 2001

Jim Battle wrote:
>

<snipped solution>

> PCHL is a one byte opcode that jumps back to 0000h. I guess RST 0
> would work too.

No, RST 0 will push the return address.

There are quite a few solutions to this. Here are some given in the June
1979 issue of PCW:

For the purists who think that the code should start at 0:

0000 21 06 00 LXI H,0006
0003 54 MOV D,H
0004 5C MOV E,H
0005 F9 SPHL
0006 D5 PUSH D
0007 E9 PCHL

The first instruction sets the HL registers to 0006 (00 in H, 06 in L)
and the next two set the D and E registers to zero using the data (00)
in H. The stack pointer SP is then loaded with 0006 from HL. 'Pushing'
the DE registers in the next instruction writes zeros into locations
0004 and 0005 and the stack pointer is reduced by two to 0004. The next
instruction, PCHL, means 'jump to the address stored in HL' which, since
HL contains 0006 means that the execution continues with the PUSH D
instruction. Successive Pushes write pairs of zero bytes _down_ through
memory, past location 0000 to FFFF and on until, after 32767 pushes, the
only two bytes in memory which are not zero are the PUSH D and PCHL
instructions themselves. The 32768th PUSH overwrites these last two and
the whole of memory is set to zero.

The most popular of the shortest possible solutions was this:

FFFA 31 FC FF LXI SP,FFFC
FFFD CD FD FF CALL FFFD

The first instruction sets the stack pointer to FFFC, the byte before
the next instruction. The CALL instruction which follows calls itself at
location FFFD pushing the return address, which happens to be 0000, onto
the stack. With successive CALLs the stack pointer works downwards
through memory writing pairs of zero bytes. After the 32767th CALL only
two bytes, FFFD and FFFE, remain unaffected so that the last CALL, which
overwrites these last two bytes, jumps to location 00FD.
Received on Mon Aug 06 2001 - 16:53:16 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:33:31 BST