Date : Sat, 08 Dec 1990 19:00:02 GMT
From : swrinde!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!smurf!subnet.sub.net!mcshh!tilmann@ucsd.edu (Tilmann Reh)
Subject: System use of Z80 registers
In article <1990Dec4.131328.15594@ims.alaska.edu>
floyd@ims.alaska.edu (Floyd Davidson) writes:
> You're last statement does not follow from the first. For maximum
> portability both should assume the other did it wrong.
Of course, that is the safest way. But then, system behaviour is very
well specified (see below). So I especially wanted to emphasize the
responsibility of the application programmers (not to blame it all on
the system programmers!).
In article <1990Dec4.134833.17783@funet.fi>
pl@news.funet.fi.tut.fi (Lehtinen Pertti) writes:
> The point is, that CP/M is specified to 8080 and first Z80 versions
> didn't use Z80-specific registers, so it appeared, that applications
> were free to use those registers without saving/restoring.
Sorry, but that's not logical. If one uses Z80 opcodes in an application, he
must be aware that at least the BIOS also uses these instructions.
> System routine usually saves only those registers it really uses,
> so I don't really see, if it matters, who saves the registers,
> as long as it is clearly specified somewhere.
Of course, in fact it doesn't matter *who* saves. Just that the system may
save registers which aren't used by the application at all.
As for the spec's: see below.
> Yes, this is sure way to do that. But what is needed, is clear
> specification, which registers should be preserved and which not,
> just as in every subroutine calling standard.
> If system specification says which registers are to be preserved,
> it would be very easy.
I wonder if anyone of you ever read the CP/M Programmers Guide. In this
(original DRI) document there is the clear specification. The CP/M-Plus
Programmers Guide (as I use CP/M-Plus) tells me on page 27:
When a transient program makes a BDOS function call, the BDOS does
not restore registers to their entry values before returning to the
calling program. The responsiblity for saving and restoring any
critical register values rests with the calling program.
So everyone who writes (or wants to write) applications programs should
please read the specifications before doing so.
Of course, that quotation doesn't mention Z80 registers. But if you think
logically and carefully look at the sentence, it is absolutely clear that
*every* register may be changed after returning from a system call.
BTW, even commercial programs may have bugs: In Turbo-Pascal 3.0, the IX
and IY registers aren't saved before calling the Console Input routine, but
used afterwards. So be careful. (every other Char I/O is ok!)
Tilmann Reh tilmann@mcshh.uucp
tilmann@mcshh.hanse.de