Wanting to start sizecoding on a Z80 platform in this day and age can be tough.
So here is a bit of help to get you started:
The Z80 can be seen as the little 8-bit brother of X86 chipsets, with many similarities. If you are coming from a X86 background, this might help you get a bit more grip on the Z80. These are the register pairs of the Z80, as seen from a X86 programmers perspective.
- AF = AL + Flags
- HL = Can be seen as BX (H=BH,L=BL) or SI in a (HL) setting, like BX also used for addressing.
- BC = Can be seen as CX (B=CH,C=CL), often used for loops
- DE = Can be seen as DX (D=DH,E=DL) or DI in a (DE) setting
- IX = 16 bit Index Register X, can also be accessed with IXH,IXL
- IY = 16 bit Index Register Y, can also be accessed with IYH,IYL
For each of the main registers there also exists a shadow register. These cannot be accessed directly, but must be swapped in and out with the main register set. The shadow registers are usually denoted by the ' symbol. They can be swapped with the following commands:
- EX AF,AF' = Swaps AF with AF'
- EXX = Swaps BC, DE and HL with BC', DE' and HL'
There are no shadow registers for the index registers.
Note: For a lot of operations, you can only use the A(8bit) and HL(16bit) registers. The Sjasmplus assembler has extra syntax and fake-instructions support which may produce unexpected results when source contains other than official Zilog syntax (but the parser can be configured to work in more relaxed way allowing more variations in syntax).
Here is a rough translation for some of the Z80 instructions:
- BIT = TEST
- CP = CMP (although the Z80 has many other handy compare functionality)
- DJNZ = LOOP (decreases B and checks not zero)
- EXE = Exchange all registers with Shadow registers, can be used a bit like PUSHA/POPA
- EX = XCHG
- HALT = HLT
- JP = JMP
- JR = JMP NEAR (Jump Relative)
- LD = MOV
- LDI = MOVSB (tmp=(HL),(DE)=tmp, DE++, HL++)
- LDIR = REP MOVSB (tmp=(HL),(DE)=tmp, DE++, HL++, BC--)
Learning Z80 Assembler
There are many Z80 tutorials available online, but one i found very simple and clear is at this 1996 styled webpage ;-)
There is no proper index-page for this, which is why i linked all the lessons above, but you can continue to the next lesson by clicking at the next lesson at the bottom of the page.
Also, here is a compact 'cheat sheet' with some basics for various Z80 systems: https://www.chibiakumas.com/z80/CheatSheet.pdf