View Single Post
Old 2nd Jun 2019, 9:00 pm   #6
julie_m
Dekatron
 
Join Date: May 2008
Location: Derby, UK.
Posts: 7,735
Default Re: Fun with Z80 Assembler

I started with a ZX81, but never managed to get my head around Z-80 machine code. When I moved on to a BBC model B, with its built-in 6502 assembler, I found that processor's instruction set easier to learn. Later I went back to the Z-80 with a ZX Spectrum, now having a bit more of a grasp of what assembly language could do. And I had fun, eventually even modifying a ZX-81 general-purpose I/O card to work with the Spectrum. I used that to control a disco light controller I had made earlier and had the foresight to include a "computer port" (the inputs of four of the drivers in a ULN2803, which turned on the LEDs in the opto-isolators). And when I picked up an Interface One, I wrote a Z-80 cross-assembler in BASIC on my Amiga 500 and transferred code and data over the serial port! It was still quicker than loading and saving with cassettes (no Microdrive, unfortunately).
Quote:
Originally Posted by JohnBHanson View Post
I much prefer Z80 over 6502 four things I hated about 6502.

1. Most programming in assembler required knowledge of what was free in page 0 -
different for each machine.
2. Stack space limited to 256 bytes - difficult to write multi-tasking as stacks for *all* task and interrupt service routines need to be here.
3. Needs to be an IO page splitting up the memory map - cannot go at the top which is where the reset vector is and cannot go at the bottom as that is where page0 is.
4. Lack of 16 bit registers
Taking your points one by one:
  1. This is true, but it should be mentioned in your system documentation. If not, that's a fault of the computer manufacturer, not the chip.
  2. How much stack space do you really need? With only three main registers and one byte of status, you need only store at most 6 bytes of context on the stack including the return address. If you want a parameter-passing stack, you can implement it easily enough in software.
  3. This criticism also applies to the 6800. It was less of a problem in the 1980s when many home computers had less than 64kB of memory (ROM and RAM) anyway.
  4. That's what zero page is for! The 6502 has instructions such as LDA(&70,X) and LDA(&70),Y. The former reads the contents of &70+X and &71+X, and then reads the contents of that address into A. The latter takes the 16-bit value in &70 and &71, adds Y and reads the contents of this address into A.
I could counter by saying that the Z-80 plods along, taking too many cycles to do anything (the shortest instructions take 4 clock cycles, as opposed to the shortest on the 6502 which take 2 cycles). The index registers appear awkward, if you are already used to how the 6502 handles indirect addresses using zero page locations as auxiliary registers.

Basically, they're two different but equally-valid means to the same end. And at least we can both agree that units-first is the proper way to write a multi-byte number

@Jon -- the Spectrum has a bit-mapped screen with the address lines effectively out-of-order. (I believe it is actually using the periodic reads of display memory to refresh the low 16K of RAM.) The scanlines end up being stored in order 0, 8, 16, 24, 32, 40, 48, 56, 1, 9, 17, 25 ..... 39, 47, 55, 63, 64, 72, 80, 88 ..... 168, 175, 183, 191.
__________________
If I have seen further than others, it is because I was standing on a pile of failed experiments.
julie_m is offline