MSX BASIC中通过USR函数调用的例程中哪些寄存器是被调用者保存的?

huangapple go评论51阅读模式
英文:

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

问题

在MSX BASIC中通过USR函数调用的机器语言例程中,应保留哪些寄存器的值,哪些寄存器的原始值可以不保存?我尝试了Google和Perplexity AI,但效果不佳。

英文:

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

得分: 2

在研究了 MSX 1 ROM Basic 的反汇编清单后,我强烈怀疑你的机器语言程序不需要保存任何寄存器。只需确保不破坏堆栈和堆栈指针。还要保持 I 和 R 寄存器不变,除非你确切知道你在做什么。

HL 不能被破坏,因为它跟踪记号流,但你不需要自己保存它。在跳转到机器语言程序之前,它被推送:

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

并在从机器语言程序返回时立即弹出:

  POP HL
  RET

我还看不出需要保存其他任何寄存器的必要性:

  • AF、BC 和 DE 几乎肯定保存临时值;我看到它们在调用机器语言程序后不久被破坏。
  • IX 和 IY 似乎偶尔用作系统例程的输入参数。
  • 备用寄存器(AF', BC', DE', HL')在进行插槽间调用时暂时使用。
英文:

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.

huangapple
  • 本文由 发表于 2023年4月16日 23:44:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76028742.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定