What's the deal with EXX, I'd love to use this instruction but every time I
do it crashes my program. Must be something to do with the display system,
similar, I suppose, to using the IX register.
Toni Baker kind of implies that it can be used "quite safe(ly)".
From MMC on the ZX81...
"EXX As well as AF' there are also BC', DE' and HL', which are just a set of six
new registers (or three new register pairs) which can only be accessed by this
one single instruction. EXX is an exchange instruction. It means exchange BC
with BC' (i.e. B with B' and C with C'), DE with DE', and HL with HL' - all in
the same go. This is quite safe and does not affect SLOW in the way that AF'
does. It is useful for preserving the values of the registers when calling a
ROM subroutine which relies upon A but wipes out the other registers, e.g.
EXX/CALL ROM-SUBROUTINE/EXX. The previous values of BC, DE, and HL are now un-
changed."
Is it only safe to use when calling a ROM routine? That doesn't make sense to
me.
However...
EXX
CALL 0A2A ;ROM CLS routine
EXX
Will crash.
Regards;
What's the deal with EXX
Re: What's the deal with EXX
HL' is used by the calculator as a return address. So using EXXs may cause a crash when using USR, which is a calculator function. With CLS, HL is probably changed, and therefore HL'...
Re: What's the deal with EXX
The EXX instruction can be used safely as long as there is no return to BASIC through the USR function, for the reason exposed by olofsen.
If you need to return to BASIC after using EXX, you can use one of the alternatives:
1- save the HL' contents:
2. or return to BASIC through the error restart:
If you need to return to BASIC after using EXX, you can use one of the alternatives:
1- save the HL' contents:
Code: Select all
EXX
PUSH HL
... your code
POP HL
EXX
Code: Select all
RST $08
DB $FF
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/