Delphi中asm程序结束时要恢复哪些CPU寄存器
当用汇编代码编写Delphi程序或函数时,哪些寄存器必须被保存并在程序结束时恢复到原始值?
当从(内联)汇编代码调用另一个 Delphi 过程或函数时,我可以期望其他函数对寄存器做什么?哪些寄存器将恢复到其原始值,哪些可能不会?
(显然,相同的答案适用于两个问题)
我假设 默认调用约定德尔福的。我知道 EAX
用于 32 位返回值。并且查看SysUtils.pas中的asm代码,似乎EBX
、ESI
和EDI
被推送和恢复,但其他没有。不过,我找不到任何关于此的文档。
When writing a Delphi procedure or function in assembly code, which registers must be saved and restored to the original value at the end of the procedure?
When calling another Delphi procedure or function from (inline) assembly code, what can I expect that other function to do with the registers? Which registers will be restored to their original values and which may not?
(Obviously, the same answer would apply to both questions)
I am assuming the default calling convention of Delphi. I know that EAX
is used for 32-bit return values. And looking at the asm code in SysUtils.pas, it seems that EBX
, ESI
and EDI
are pushed and restored, but the others are not. I cannot find any documentation about this, though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
函数的前三个参数分别在
EAX
、EDX
和ECX
中给出。附加参数被压入堆栈。对于对象的方法,Self
指针始终是(不可见的)第一个参数。结果应该在EAX
中。对于返回长字符串的函数,函数的(不可见)last参数是指向结果字符串的指针(它本身就是指向字符串第一个字符的指针)。EBX
不得更改(除非您在过程/函数结束之前恢复它),因此不得ESP
、EBP
、<代码>ESI,或EDI
。< support>(1) 曾经在这里找到过关于 Delphi 内联 ASM 的精彩介绍:http://www.delphi3000.com/articles/article_3766.aspThe three first arguments of a function are given in
EAX
,EDX
, andECX
, respectively. Additional arguments are pushed on the stack. For a method of an object, theSelf
pointer is always the (invisible) first parameter. The result should be inEAX
. For functions returning long strings, the (invisible) last parameter of the function is the pointer to the resulting string (which by itself is a pointer to the first character of the string).EBX
must not be altered (unless you restore it before the end of the procedure/function), and so must notESP
,EBP
,ESI
, orEDI
either.(1) An excellent introduction to Delphi inline ASM used to be found here: http://www.delphi3000.com/articles/article_3766.asp我不知道文档是否是最新的,但您应该查看 使用内联汇编代码(仅限 Win32):
引用:
I don't know if the docs are up to date, but you should have a look at Using Inline Assembly Code (Win32 Only) at the Embarcardero Wiki:
Quote: