Page 1 of 1

Alternate register set usage

Posted: Sun May 13, 2018 12:08 pm
by periata
I understand from reading other forum posts that the alternate register set is used for certain operations including longs and some floating point ops. I'm currently building a firmware that would benefit from being able to reserve at least a couple of registers from the alternate set for its own usage, or at least detect if they've been overwritten ... are there any options to control what registers are used? Is there documentation of what's used in what circumstances (so I could potentially just avoid using the parts of the system that would overwrite certain registers)?

Posted: Mon May 14, 2018 4:03 am
by alvin
periata wrote:I understand from reading other forum posts that the alternate register set is used for certain operations including longs and some floating point ops. I'm currently building a firmware that would benefit from being able to reserve at least a couple of registers from the alternate set for its own usage, or at least detect if they've been overwritten ... are there any options to control what registers are used? Is there documentation of what's used in what circumstances (so I could potentially just avoid using the parts of the system that would overwrite certain registers)?
No.. the compilers are not using the exx set** however the library is. So the only way to avoid having the exx set altered is to avoid using library functions that alter the exx set or provide alternatives that don't use those registers.

You will have to drill into the library source code to ensure that functions you're using do not change the exx set but generally it will be functions to do with 32-bit integer math, 64-bit integer math, float and stdio. Using the exx set increases performance a great deal so it's probably a good compromise for the firmware not to reserve the exx set and simply have it pick up stored values from memory instead.

Classic library source code is rooted in z88dk/libsrc
Newlib library soure code is rooted in z88dk/libsrc/_DEVELOPMENT

**In rare circumstances sccz80 will use the exx set to fix the stack pointer after a function call but IIRC this is also connected to floats.

Posted: Mon May 14, 2018 4:04 am
by alvin
It may be possible to use a disassembler on the code section generated by the compiler to perform a search for "exx" to verify that the exx set is used or not.

Posted: Mon Jun 04, 2018 8:50 pm
by stefano
af' is rarely used in graphics, but the intruction to look at is not exx, in that case. .