在Delphi中的asm过程结束时要恢复哪些CPU寄存器 [英] What CPU registers are to be restored at the end of an asm procedure in Delphi
问题描述
在汇编代码中编写Delphi程序或函数时,在程序结束时必须保存哪些寄存器并恢复到原始值?
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?
当调用另一个Delphi程序或函数从(inline)汇编代码,我可以期待其他功能与寄存器有关?哪些寄存器将被恢复到原来的值,哪些不可以?
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)
我假设默认调用约定。我知道 EAX
用于32位返回值。看看SysUtils.pas中的asm代码,似乎 EBX
, ESI
和 EDI
被推送和恢复,但其他则不是。
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.
推荐答案
一个函数的三个第一个参数是在$ code中给出的> EAX , EDX
和 ECX
。额外的参数被推送到堆栈。对于一个对象的方法, Self
指针始终是(不可见)的第一个参数。结果应在 EAX
中。对于返回长字符串的函数,函数的(不可见)最后一个参数是指向结果字符串的指针(它本身是指向字符串的第一个字符的指针)。
The three first arguments of a function are given in EAX
, EDX
, and ECX
, respectively. Additional arguments are pushed on the stack. For a method of an object, the Self
pointer is always the (invisible) first parameter. The result should be in EAX
. 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
不能更改(除非在程序/函数结束之前还原它),所以不能 ESP
, EBP
, ESI
或 EDI
。 (1) 以前在这里找到的Delphi inline ASM的一个很好的介绍: http://www.delphi3000 .com / articles / article_3766.asp
EBX
must not be altered (unless you restore it before the end of the procedure/function), and so must not ESP
, EBP
, ESI
, or EDI
either.(1) An excellent introduction to Delphi inline ASM used to be found here: http://www.delphi3000.com/articles/article_3766.asp
这篇关于在Delphi中的asm过程结束时要恢复哪些CPU寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!