Hung up on missing parentheses...

in #z807 years ago

Back in 1980 when I had just graduated, while I was waiting to start work, I took a small (!) project from the owner of the local computer store - who also happened to own the car accessories store next door.

What he wanted (and I was dumb enough to offer to implement) was a database of parts running on a first generation TRS 80, powered only by cassette tapes. The only available language was a Z80 assembler, but heck, I was a whiz with 8080 and Z80 coding so how hard could it be?

Armed with a bottle of the best Bells Whisky I started coding in my living room, working into the night, and, to my best recollection the code was pretty good considering the constraints. I built, from first principles a rudimentary database that could be loaded from cassette and changes saved. Nothing fancy like indexing, trees or anything but it worked.

The one night that I was almost defeated was by a quirk in the assembler.

In Z80 code, general purpose registers are known by letters, A, B, C, D, E, H and L.

The D & E registers can be combined to form a pair used for indexing memory as can the H & L registers.

So I had a loop that used the DE register pair to index the memory and I was looking for the end of line character.

loop:   ld a,de
        cp 0d
        jr z,found
        inc de
found:  ...

Having only the most primitive of debuggers it took me about half the bottle to realise that the first line was not (as I had intended) using the DE register pair as an index, but rather was loading the hexadecimal value DE into the A register, hence the next line - comparing the A register to the value 0d (end of line) could never be satisfied and an eternal loop had been created.

Four hours later I finally had the corrected code

loop:   ld a,(de)
        cp 0d
        jr z,found
        inc de
found:  ...

But oh how much easier it would have been if modern coding conventions had dictated that hex numbers should start with 0x.

loop:   ld a,0xde

Or used the convention then in use, following hex numbers with the letter H

loop:   ld a,deh

Coin Marketplace

STEEM 0.20
TRX 0.13
JST 0.030
BTC 64741.88
ETH 3457.21
USDT 1.00
SBD 2.55