z80 Development Kit
You are not logged in.
Hi all,
I've just made some changes to my ALIAC-2 single board computer's ROM,
putting the sensor monitoring routines into an interrupt service routine
(triggered by the Z80 CTC) - some of the sensors need to be waited on, and
doing a periodic poll for data ready is much better than just blocking
until data is ready.
However, on reviewing the code I had written earlier for the sensors, some
of this code does an ex af, af' or two. Since this is now getting called
during an interrupt - I'm wondering if the z88dk makes use of the shadow
registers. It would obviously be courting disaster for my interrupt
service routine to use them too if the z88dk is making use of them!
cheers.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Well tey are used in some libraries.
Somewhere we provided several version of routines, with different level of optimization to save some register, but it is always better to save as much as you can in your interrupt code.
Offline
As Stef says some libraries do use the alternate set -- an effort has been made to identify subroutines that use IX/IY/EXX in documented functions in the wiki. As for core library code (as in stuff that you don't have to link to explicitly in the compile) I don't think any non-8080 registers are used with the exception of long arithmetic operations. If there is any question you can always have a quick peak at the z80 source ![]()
The approach taken with the im2 library is to supply two wrappers for C functions that offer the option of saving 8080 registers only ('LIGHT') or all z80 registers (the other one), with the suggestion that the latter be used. It also supplies a generic isr routine that can have a list of C functions to run on interrupt on a specific vector; the generic isr saves all the z80 registers only once, then runs all C functions and restores all z80 registers so that the overhead is paid only once no matter how long the list is.
Anyway I say unless time is ultra precious you just go ahead and save all registers used in the isr.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Offline
Processors with Shadow registers use these to save their current state ,
rather than pushing their register bank on to the stack. This saves
considerable memory accesses (time) when processing an interrupt.
However, if only one set of shadow registers are available, then the
processor servicing multiple interrupts must 'manually' preserver the state
of the registers before servicing the higher interrupts. If that is not
done, then the important information will be lost.
Karthik Balaguru
--
View this message in context: http://www.nabble.com/Use-of-shadow-reg … #a13336446
Sent from the z88dk-users mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Processors with Shadow registers use these to save their current state ,
rather than pushing their register bank on to the stack. This saves
considerable memory accesses (time) when processing an interrupt.
This was very likely Zilog's motivation in providing them for the z80 especially given they added a powerful new interrupt mode to the 8080 design the z80 improved on. However the value of having shadow registers used in this way is very much debatable given that the z80 has so few registers and saving them to the stack isn't such a big deal in terms of processor time. I can conceive that there *may* be an application out there that requires interrupt response within 20-50 cycles rather than 100-130 but such applications' interrupt service routines would have to be necessarily short and use few registers anyway so the difference between a "EX AF,AF; EXX" pair and a few pushes of used registers shouldn't break the bank in most circumstances I don't think.
While the value of a shadow register set as a means to achieve a quick interrupt response on the z80 is debatable, there is no question that the extra register bank speeds up general code considerably. The long arithmetic operators for example are at least twice as fast (and perhaps up to 5 times as fast!) as versions that don't use the shadow registers. If you dig back into old z88dk library code you will see that many routines were originally implemented for the 8080 and were therefore restricted to the core set of registers and they were just horrible, making use of storage in memory for temporary variables; with the z80 such routines can use the extra on-chip registers to hold temporary data and this improves code size and execution speed considerably.
I have seen it mentioned a few times that z80 code is not much better than 8080 code. Whoever said that was not familiar with the z80 at all as I see the z80-specific opcodes and architecture making a huge difference in quality, speed and compactness of most code I write.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Offline
Hi all,
I've been using __FASTCALL__ for all my C-compatible ROM routines (which
are written in assembler, using sjasmplus). When I write a ROM routine
that's a __FASTCALL__, I do it something like this:
some_function
ld a, (hl)
.... do something ...
ret
I had occasion to use __FASTCALL__ within an assembly language routine
within a C project, and this is essentially what I did:
void __FASTCALL__ foobar(char something)
{
#asm
ld a, l
.... do something ....
ret
#endasm
}
... and found that unlike the ROM routines which seem to work perfectly
well (and have been doing so for ages), enough calls would end up with a
serious memory corruption and crash, a sure sign of the stack being
buggered up by not enough/too many pushes and pops. So I had a look at the
asm output that got created, and to my surprise found the above turned
into something that looked like:
_foobar
push hl
ld a, l
.... do stuff ...
ret
pop bc
ret
Which at least makes it obvious why it crashed, the 'ret' that I had put
in was superflous to start with, and also meant that the stack was growing
with each call until it caused a crash. So, I just removed my 'ret' and
everything lived happily ever after.
Which brings me to this question: what is the purpose of the push hl on
entry and pop bc on exit (which essentially simply preserves and copies
the contents of hl to bc)? My rom calls don't do this, and I've not
noticed any bad effects: should they also have the push hl/pop bc pair?
--
Dylan Smith, Port St Mary, Isle of Man | Code fast, crash young and
Flying: http://www.dylansmith.net | leave a beautiful core.
FFE/Elite Universe: http://www.alioth.net | -- JK (#afe)
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
I don't know the answer to the last question (I thought the stack was left clean), but I'd like to give hints I'm aware of related to this topic.
First, if your target device is able to give a text output, you can rely on the "debug" library to inspect the stack status or to disassemble the code in the function actually being run.
Second, I've put in the CVS tree slow and dirty replacement routines for EX AF,AF and EXX.
In my tests they worked when I tried to put them in the gen_math library; maybe someone finds them useful.
http://z88dk.cvs.sourceforge.net/z88dk/ … s/z80_emu/
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Offline