Z80 Registers

Posts about Z80 programming that do not relate to a particular computer
Post Reply
User avatar
Gee-k
Posts: 8
Joined: Sat May 04, 2019 9:35 am

Z80 Registers

Post by Gee-k » Fri Oct 11, 2019 2:23 pm

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.

You don't fail, You learn how it's not done.
https://www.gee-k.net : Where I blog about my random geeky goings on.

User avatar
akuyou
Posts: 250
Joined: Mon Apr 22, 2019 3:19 am

Re: Z80 Registers

Post by akuyou » Sun Oct 13, 2019 11:01 am

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)!
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

User avatar
Gee-k
Posts: 8
Joined: Sat May 04, 2019 9:35 am

Re: Z80 Registers

Post by Gee-k » Mon Oct 14, 2019 8:18 am

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.
You don't fail, You learn how it's not done.
https://www.gee-k.net : Where I blog about my random geeky goings on.

Post Reply

Return to “General Z80 Programming”