Page 1 of 1

Z80 Registers

Posted: Fri Oct 11, 2019 2:23 pm
by Gee-k
Hi hi,
I'm trying to understand what each register in the z80 does and how it can be used.
I made the following table and wondered if anyone could point out any errors/or updates that could be made to it.

Code: Select all

Label	Size (bit)	Note
A	8	Accumulator. Used for all the calculations. (can be used with F)
F	8	Flags register. Used to determine if result is positive, negative or zero. (can be used with A)
B	8	Bit counter	Used together as a 16bit counter
C	8	Used when you want to interface with hardware ports	
D	8	Used together to hold the address of a memory destination
E	8	
H	8	General 16 bit register used for most things. Usually holds the origin address.
L	8	
I	8	Interrupt register. 0,1 or 2 (normally set to 1)
IX	16	Index register. Used similar to HL but slower	Made up of IXH(High) and IXL(Low)
IY	16	Index register. Holds the location of the system flags.	Made up of IYH(High) and IYL(Low)
SP	16	Stack Pointer. 
PC	16	Program Counter. Points to the currently executed instruction.
R	8	Memory refresh. Best not to write to it. Can read from safely. Only goes up to 128

Shadow Registers A’, B’, C’, D’, E’, H’, L’ and F’ also exist. To change between AF and AF’ the EX AF,AF’ is used. To swap the other registers EXX is used.


Re: Z80 Registers

Posted: Sun Oct 13, 2019 11:01 am
by akuyou
Yes looks pretty good... BC are used as a pair for bytecount (not bit) with LDIR... and on it's own as a loop count with DJNZ

the OUT command uses BC (not just C) on some systems - namely the CPC, Spectrum, SAM and Camputers Lynx...
it just depends if the way the Z80 is wired... also certain ports cover ranges - so you may see cases on those systems where only C is set - because for certain ports any value for B is OK.

on systems like the MSX and Enterprise only C is used... I know this is weird and a pain, but it's in the official documentation that it's valid!... however the CPU works, the command will still be OUT (C),... even if it's actually using (BC)!

Re: Z80 Registers

Posted: Mon Oct 14, 2019 8:18 am
by Gee-k
Thanks for the correction on BC.
So BC is used for ByteCount when used with LDIR and B is used on it's own as a loop count with DJNZ.

Some really weird head scratchers whilst working with assembly.
This is my first time trying to work with it. It's nothing like the other languages i know (PHP, MYSQL etc etc).
Tempted to try and learn C instead and compile my programs haha.

Re: Z80 Registers

Posted: Wed Oct 16, 2019 9:24 pm
by akuyou
Yes, ASM is certainly rather different!

At the end of the day, you should use whatever language works best for you... if you think you can do what you want with C then go for it!.

I program in Assembly because I find the process interesting, not for the end result... it's like developing your own film... it's slower, and there's no real need anymore, but if you're doing it purely for the experience and sense of achievement, then maybe it's worth it!