Which registers are callee-save in routines called via USR function in MSX BASIC?

72 Views Asked by At

In machine-language routines to be called via USR function in MSX BASIC, values of which registers should be preserved and which registers can be used without saving their original values?

I tried Google and Perplexity AI, but they didn't work well for me.

1

There are 1 best solutions below

0
Ruud Helderman On

After studying a disassembly listing of MSX 1 ROM Basic I found here, I strongly suspect your machine language routine does not need to save any registers. Just make sure not to mess up the stack and the stack pointer. Also leave registers I and R alone, unless you know exactly what you are doing.

HL must not be clobbered as it keeps track of the token stream, but you do not need to save it yourself. It is pushed before jumping to the machine language routine:

L4FD5:
  CALL L4FF4
  PUSH DE
  CALL OPRND_6
  EX (SP),HL

and popped immediately upon return from the machine language routine:

L3297:
  POP HL
  RET

I also see no need to save any of the other registers:

  • AF, BC and DE are almost certainly holding temporary values; I see them being clobbered shortly after the machine language routine has been called.
  • IX and IY appear to be used now and then as input parameters for system routines.
  • The alternate registers (AF', BC', DE', HL') are used temporarily when making inter-slot calls.