Delphi中asm程序结束时要恢复哪些CPU寄存器

发布于 2024-09-15 18:30:32 字数 418 浏览 5 评论 0原文

当用汇编代码编写Delphi程序或函数时,哪些寄存器必须被保存并在程序结束时恢复到原始值?

当从(内联)汇编代码调用另一个 Delphi 过程或函数时,我可以期望其他函数对寄存器做什么?哪些寄存器将恢复到其原始值,哪些可能不会?

(显然,相同的答案适用于两个问题)

我假设 默认调用约定德尔福的。我知道 EAX 用于 32 位返回值。并且查看SysUtils.pas中的asm代码,似乎EBXESIEDI被推送和恢复,但其他没有。不过,我找不到任何关于此的文档。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟雨凡馨 2024-09-22 18:30:32

函数的前三个参数分别在 EAXEDXECX 中给出。附加参数被压入堆栈。对于对象的方法,Self 指针始终是(不可见的)第一个参数。结果应该在 EAX 中。对于返回长字符串的函数,函数的(不可见)last参数是指向结果字符串的指针(它本身就是指向字符串第一个字符的指针)。

EBX 不得更改(除非您在过程/函数结束之前恢复它),因此不得 ESPEBP、<代码>ESI,或EDI< support>(1) 曾经在这里找到过关于 Delphi 内联 ASM 的精彩介绍:http://www.delphi3000.com/articles/article_3766.asp

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 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

蘸点软妹酱 2024-09-22 18:30:32

我不知道文档是否是最新的,但您应该查看 使用内联汇编代码(仅限 Win32)

引用:

一般来说,asm 语句中寄存器的使用规则与外部过程或函数的规则相同。 asm 语句必须保留 EDI、ESI、ESP、EBP 和 EBX 寄存器,但可以自由修改 EAX、ECX 和 EDX 寄存器。在进入 asm 语句时,EBP 指向当前堆栈帧,ESP 指向堆栈顶部。除了 ESP 和 EBP 之外,asm 语句不能对语句入口处的寄存器内容进行任何假设。

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:

In general, the rules of register use in an asm statement are the same as those of an external procedure or function. An asm statement must preserve the EDI, ESI, ESP, EBP, and EBX registers, but can freely modify the EAX, ECX, and EDX registers. On entry to an asm statement, EBP points to the current stack frame and ESP points to the top of the stack. Except for ESP and EBP, an asm statement can assume nothing about register contents on entry to the statement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文