IX, IY and shadow registers

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
nollkolltroll
Posts: 325
Joined: Sat Sep 27, 2014 8:02 pm
Location: Stockholm, Sweden

IX, IY and shadow registers

Post by nollkolltroll »

A small survey:
How much better would your code be if IX and IY was generally available?
What about the shadow registers, if you couldn't use ANY of them, how bad would it be?
/Adam
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: IX, IY and shadow registers

Post by bobs »

Personally I use what is available to me, and adapt accordingly, but obviously the more registers that are available for use the better.

Is this just a random question?
nollkolltroll
Posts: 325
Joined: Sat Sep 27, 2014 8:02 pm
Location: Stockholm, Sweden

Re: IX, IY and shadow registers

Post by nollkolltroll »

Bobs: no, this is not a random question. My only hint to you is ZX81GS ;)
/Adam
User avatar
stefano
Posts: 568
Joined: Tue Dec 11, 2012 9:24 am
Contact:

Re: IX, IY and shadow registers

Post by stefano »

At least ONE index register is a good thing to have.
Personally I also miss AF' very much..
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: IX, IY and shadow registers

Post by bobs »

You can, with a bit of work, use one of the indexing registers on the Zeddy (Ant Attack 81 does), but with regards to games writing it's better to avoid them due to their relatively slow execution compared to the direct registers. AA'81 was the only game I needed to use them, and only then because I was working with the original Spectrum code.

As for the alternative/shadow registers, those are very useful, and so being without them would make things much more difficult for my game writing. Personally I don't miss not having access to A'F'.
User avatar
RetroTechie
Posts: 379
Joined: Tue Nov 01, 2011 12:16 am
Location: Hengelo, NL
Contact:

Re: IX, IY and shadow registers

Post by RetroTechie »

Well I prefer code that is -reasonably- efficient, and (at least somewhat) readable.

IX/IY can sometimes help to make code more readable. But they take more bytes & execution time, so they're hardly useful to produce faster code.
The alternate registers help to keep stuff in registers, vs. main memory / stack operations. And thus can make code faster. But they don't make code more readable (more likely, the opposite!). AF' - who cares. :lol:

So I can do without either for Z80 coding. Instead, I'd prefer a few more general purpose registers. But hey a Z80 is what it is, and a ZX81 uses it the way it does... So like bobs said: adapt, and (try to ;) ) make best use of what's available.
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: IX, IY and shadow registers

Post by Andy Rea »

BC' DE' HL' are incredibly useful i find i hardly ever use index registers although i am quite guilty of storing variables directly in the code as the operand to some instruction usually a LD register,xx but not always. The AF' pair unless you really must preserve the flags then a LD r,A is just as quick assuming you have a spare register.

Regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
nollkolltroll
Posts: 325
Joined: Sat Sep 27, 2014 8:02 pm
Location: Stockholm, Sweden

Re: IX, IY and shadow registers

Post by nollkolltroll »

So it seems Zilogs original intention of the shadow registers, to have fast interrupt context switch, is not what it is mainly used for? You do other tricks with BC', DE' & HL'. I guess that's understandable, since they ARE available on the zeddy.
Are IX/IY available on the speccy? Trying to get a feel for what gets used on the zeddy, and what WOULD get used if available.
/Adam
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: IX, IY and shadow registers

Post by bobs »

IX and IY are both available on the Spectrum, and can be used either as their intended indexing, or as four new registers (IXH / IXL and IYH / IYL) via undocumented instructions.

i tend to use the shadow registers as additional stores, instead of having to get the data via addressing. For example. The main registers could be used to combine data from DE and HL, in a loop counted by BC, with the result placed in A - which can easily be written to a new location in HL'. it's having the fast EXX instruction which make this most useful.
Moggy
Posts: 3267
Joined: Wed Jun 18, 2008 2:00 pm

Re: IX, IY and shadow registers

Post by Moggy »

Some interesting info concerning the register set, a full article found here...

http://www.righto.com/2014/10/how-z80s- ... -down.html

Not one for the gurus who know most if not all of this but for those of us still learning here are some snippets....

" Swapping registers through register renaming
The Z80 has several instructions to swap registers or register sets. The EX DE, HL instruction exchanges the DE and HL registers. The EX AF, AF' instruction exchanges the AF and AF' registers. The EXX instruction exchanges the BC, DE, and HL registers with the BC', DE', and HL' registers. These instructions complete very quickly, which raises the question of how multiple 16-bit register values can move around the chip at once.

It turns out that these instructions don't move anything. They just toggle a bit that renames the appropriate registers. For example, consider exchanging the DE and HL registers. If the DE/HL bit is set, an instruction acting on DE uses the first register and an instruction acting on HL uses the second register. If the bit is cleared, a DE instruction uses the second register and a HL instruction uses the first register. Thus, from the programmer's perspective, it looks like the values in the registers have been swapped, but in fact just the meanings/names/labels of the registers have been swapped. Likewise, a bit selects between AF and AF', and a bit selects between BC, DE, HL and the alternates. In all, there are four registers that can be used for DE or HL; physically there aren't separate DE and HL registers.

The hardware to implement register renaming is interesting, using four toggle flip flops.[7] These flip flops are toggled by the appropriate EX and EXX instructions. One flip flop handles AF/AF'. The second flip flop handles BC/DE/HL vs BC'/DE'/HL'. The last two flip flops handle DE vs HL and DE' vs HL'. Note that two flip flops are required since DE and HL can be swapped independently in either register bank. ..."

And..

" The toggle flip flops are unlike standard flip flops formed from gates. Instead they use pass transistors; this lets it hold the previous state while toggling to avoid oscillation. Because the pass transistor circuits depend on capacitance holding the values, you have to keep the clock running. This is one reason the clock in the Z80 can't stop for more than a couple microseconds. (The CMOS version is different and the clock can stop arbitrarily long.) From looking at the silicon, it appears that these flip flops required some modifications to work reliably, probably to ensure they toggled exactly once.

These flip flops have no reset logic, so it is unpredictable how the registers get assigned on power-up. Since there's no way to tell which register is which, this doesn't matter.

The active DE vs HL flip flop swaps the DE and HL register control lines using pass-gate multiplexers. The main vs alternate register set flip flops direct each AF/BC/DE/HL register control line to one of the two registers in the pair...."
Post Reply