BDOS calls and registers

78 views
Skip to first unread message

Robb Bates

unread,
Oct 31, 2025, 8:18:23 PM (6 days ago) Oct 31
to RC2014-Z80
Getting my hand dirty with some CP/M Z80 assembly programming...

My question is about register safety.

Per the CP/M programming manual, C and DE are usually filled when calling BDOS and A,B and HL are usually (always?) filled when returning from BDOS.

But what about IX, IY, SP and F?  Do I need to preserve those before calling and restore after calling?  And what about the alternate registers?  I'm going to assume that since the 8080 doesn't have those and that CP/M is designed for 8080s and the Z80 just could swap the register sets, set up the BDOS call, call it, capture any returned values somehow and then swap the register sets back.

But what about RomWBW?  How does its BIOS handle any registers differently?  Or is it also entirely written to be 8080 compliant?  Third party BIOS drivers? Are those checked?

Wayne, I expect you're the person who would truly know.

Thanks,
Robb

Wayne Warthen

unread,
Oct 31, 2025, 8:33:41 PM (6 days ago) Oct 31
to RC2014-Z80
On Friday, October 31, 2025 at 5:18:23 PM UTC-7 Robb Bates wrote:
Per the CP/M programming manual, C and DE are usually filled when calling BDOS and A,B and HL are usually (always?) filled when returning from BDOS.

Right.  Keep in mind that BDOS does not preserve registers.  All you can depend on are the documented results.

But what about IX, IY, SP and F?  Do I need to preserve those before calling and restore after calling?  And what about the alternate registers?  I'm going to assume that since the 8080 doesn't have those and that CP/M is designed for 8080s and the Z80 just could swap the register sets, set up the BDOS call, call it, capture any returned values somehow and then swap the register sets back.

SP is OK, no need to preserve it.  You will need to preserve F if you need it.

You are correct that DRI OSes do not touch IX, IY, or the alternate registers.  But, if you use a non-DRI OS, you need to consult the documentation for that OS.  It does vary.  Also, remember that every vendor wrote their own CBIOS (even when using the DRI OSes).  Some CBIOS implementations did muck with IX, IY, or alternates.  Again, you will need to check the documentation for the specific scenario.

If you are trying to create code that is going to work universally, I suggest you not depend on any registers being preserved.

But what about RomWBW?  How does its BIOS handle any registers differently?  Or is it also entirely written to be 8080 compliant?  Third party BIOS drivers? Are those checked?

RomWBW API calls and the RomWBW CBIOS implementations will not modify IX, IY, or the alternate registers.  All other registers are volatile and you can only depend on the documented output registers to have known values.

Thanks, Wayne 

Robb Bates

unread,
Oct 31, 2025, 9:00:17 PM (6 days ago) Oct 31
to RC2014-Z80
Sounds like the best bet is to preserve everything to be entirely safe.  Or just be aware that nothing is truly safe and act accordingly.  And of course, the BDOS documentation will say what goes in and what comes out, which I wouldn't want to restore until I've handled the results.

Thanks,
Robb



Ed Silky

unread,
Oct 31, 2025, 10:48:05 PM (6 days ago) Oct 31
to rc201...@googlegroups.com
If things are well documented, you only need to worry about registers that you currently have data in, and that the documentation says it 'messes with'. My experience is that most general-purpose software won't use the alternate register set or IX/IY, because, as you noted, they were written to be compatible with the 8080. However, as Wayne noted, board manufacturers did know if they had a Z80, so their hardware function code may very well use all the Z80 capabilities. Also, I found some applications that would detect that the CPU was a Z80 and use its features.

-Ed

--
You received this message because you are subscribed to the Google Groups "RC2014-Z80" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rc2014-z80+...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/rc2014-z80/e6e38111-4126-4668-ac3a-0be872198355n%40googlegroups.com.

Wayne Warthen

unread,
Nov 1, 2025, 2:24:40 PM (5 days ago) Nov 1
to RC2014-Z80
On Friday, October 31, 2025 at 6:00:17 PM UTC-7 Robb Bates wrote:
Sounds like the best bet is to preserve everything to be entirely safe.  Or just be aware that nothing is truly safe and act accordingly.  And of course, the BDOS documentation will say what goes in and what comes out, which I wouldn't want to restore until I've handled the results.

That's the approach I take.  Although I generally do pay attention to the specific registers that need to be saved/restored and only do those.  Just for performance.

-Wayne 
Reply all
Reply to author
Forward
0 new messages