Index, Shadow, and Other Registers
z80 » Advanced
So far you only know
af, bc, de, and
registers. Sometimes you probably run out of registers
to use. There are several others you can work with too
but they have their limits.
Index RegistersIndex Registers are register pairs and cannot be broken up to use as
ixregister is free to use at any time. It is used synonymously with
hl. The assembler just puts an extra byte in to tell the z80 that it is going to use
ixin the next instruction instead of
hl. This slows down the speed a little and adds an extra byte so don't use it unless you have to. The
iyis usually holding the value for the beginning of a table for the System Flags for TI-OS. Say you wanted to write inverse video. You would type the following:
set textflags,(IY+textInverse) res textflags,(IY+textInverse)
The first command sets the text to white on black and
the second line resets it to the normal black on
white. You can use
ix to make
your own tables and arrays.
Shadow RegistersShadow Registers are a whole other set of all the registers. It's like pushing and popping all the registers. This is useful and faster when you have a routine that destroys all the registers and you want to get them back later. Instead of pushing and popping them all, you just switch them with the shadow registers. You must disable interrupts by 'di' before using these. Type this to switch out the registers:
ex af,af' ;switch af with it's shadow exx ;switch bc,de, and hl with their shadowsDo the same thing when you're done using them to get the original register values back.
Other RegistersOther Registers you can use are the
iregister is used with interrupts. It just holds the higher byte of the address that should be jumped to when an Interrupt occurs. The
rregister is called the Memory Refresh Register. It is incremented after each instruction (sometimes twice) executed by the processor. Bit 7 is never set though, so it has a maximum value of 127, I don't know why.
It is useful for low-quality random number routines but if you use it a lot in a row, your numbers won't be so random because they will use, for example, 1 and then use 2 and then use 3 and so on. Here's an OK random number generator you can use that will have the above problem if used several times in a row. It will return a number between 1 and 16.
random_number: ld a,r and %00001111 ;is now between 0 and 15 inc a ;is now between 1 and 16 ret
More from z80 » Advanced
All The Ports // APD // Assembler Directives // Entry Stack // User Fonts // IM 1 // IM 2 // Index, Shadow, and Other Registers // User Interrupt // Morphic Code // On-Off // Reading Keypresses from Port // Shift and Rotate // Simulating Key Presses // Sound // Square-Root Programs // System Flags of TI-OS