Menu

#795 EXX and EX AF.AF'

open
nobody
5
2022-06-04
2022-03-15
No

An important resource of the Z80 that seems not utilized by the SDCC compiler is the alternate register set accessed by EXX and by EX AF,AF'.
I see that it is difficult, due to the restrictions in the handling the exchange of values between the two register sets, to write a compiler using also this feature.
Nevertheless, the feature can double the number of registers that can be used, and values can be exchanged between the two sets using A, IX,IY and the stack
Optimal handwritten z80 code usually needs juggling data between alternate register sets.

Discussion

  • Maarten Brock

    Maarten Brock - 2022-03-16

    IMHO the best use for the alternate register set is for interrupt routines like the mcs51 does with the __using directive. This way you don't need to push/pop the registers, just start and end the ISR with EXX and EX AF,AF'. Only IX and IY still need to be pushed (if they are used).

     
  • Ragozini Arturo

    Ragozini Arturo - 2022-03-16

    Actually, the ISR is a very limited case of use, there are many situations where you can just double the number of register without side effects.
    Think e.g. to multiple nested loops: you can use as counter for the outer loops a registers set, and use the other set for the inner loop and for data processing.
    Moreover in many cases you cannot choose how to mange the ISR. In the MSX standard, e.g., the ISR is in the rom bios at 038h. The bios pushes all registers, calls your interrupt routine using a hook in ram, and then waits for the return to pop all registers. You cannot change this unless you swap away the rom bios but the resulting program will be out of the standard and you cannot be sure your code will work on all MSX configurations.

     
    👍
    2

    Last edit: Ragozini Arturo 2022-03-17
  • Ragozini Arturo

    Ragozini Arturo - 2022-05-05

    I have found very efficient math routines using exx for 32 bit operations
    the trick is that hl and hl' are used as an unique 32 bit register and that the F register doesn't swap with exx

     
    👍
    1

Log in to post a comment.

MongoDB Logo MongoDB