Friday, August 03, 2001
The following came through on a mailing list I'm on:
The Letters page of these magazines are as interesting as some of the articles. Of course, when we're talking about over 20 years ago in a hobbyist magazine, the letter-writers of one issue were quite likely to write articles in the next.
From David C. Broughton of Northwood, Middlesex, in the November 1978 issue:
Here is a little puzzle to test your readers' 8080 machine ingenuity:
“Imagine you possess an 8080 with 64K bytes of read/write memory which you want to clear. Write a program that sets all 65536 bytes to zero.”
It seemed like a fun little puzzle so I tried my hand at it.
The 8080 can address 65,536 bytes of memory, so the implication behind this is to clear all of memory, including the running program! Which means that the last instruction to execute has to clear out the last instruction! Since it's a byte addressed machine, that means that the last instruction has to pretty much be a single byte in size.
Not that big a deal. There are a few one byte instructions that write a byte to memory through an index register. Unfortunately, there are no “write-byte-increment-pointer” type instructions. So you need to increment (or decrement) the pointer. No big deal; there are one byte instructions to do that as well.
So, to write a byte and increment a pointer takes two bytes. So that's two cycles I have to go through, but depending on which direction I clear memory with (it doesn't really matter which way you go, as the address will wrap around anyway) I may wipe out the instruction with which I'm clearing out memory. At one point I had:
That didn't dawn on me until after an hour and a half of writing 8080 code (which I'm not terribly familiar with and all the references I have are for the Z80, which is a superset of the 8080.