So far you only know ,af, bc, de,
and hl
as
registers. Sometimes you probably run out of registers
to use. There are several others you can work with too
but they have their limits.
i, y,
or x
. The ix
register 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 ix
in 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 iy
is
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 iy
and ix
to make
your own tables and arrays.
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.
Shadow Registers
Shadow 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 shadows
Do the same thing when you're done using them to get the original
register values back.
Other Registers
Other Registers you can use are the i
and r
registers. The i
register is used with
interrupts.
It just holds the higher byte of the address
that should be jumped to when an
Interrupt occurs. The r
register 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.
random_number:
ld a,r
and %00001111 ;is now between 0 and 15
inc a ;is now between 1 and 16
ret