What's the deal with EXX

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Post Reply
User avatar
GCHarder
Posts: 427
Joined: Sat Dec 14, 2013 7:46 pm

What's the deal with EXX

Post by GCHarder »

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;
olofsen
Posts: 189
Joined: Wed Jan 08, 2014 12:29 pm

Re: What's the deal with EXX

Post by olofsen »

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'...
User avatar
kmurta
Posts: 302
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: What's the deal with EXX

Post by kmurta »

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:

Code: Select all

	EXX
	PUSH HL

	... your code

	POP HL
	EXX 
2. or return to BASIC through the error restart:

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/
Post Reply