根据我所能找到的,在Linux和Windows之间有两种常见的调用约定:函数调用的参数要么加载到寄存器中,要么放在堆栈中.
例如,对于printf
函数,据说Linux使用printf
所需的参数加载寄存器.对于Windows上的printf
,我看到这两种约定都使用了.在我的课上,他们让我们把参数放在堆栈上,但在在线代码示例中,参数放在寄存器中.
Basile Starynkevitch的This answer,让我认为Windows只使用堆栈作为参数,而Linux使用寄存器. Jester的This answer显示Windows使用printf
个参数的寄存器.
接下来,我为我的类编写的一小部分代码显示,在Windows上,我一直在使用堆栈作为参数:
section .data
msg: db "my message", 0ah, 0
section .text
_main:
push msg
call _printf
add esp, 4
- 那么,Windows是否能够同时使用这两种调用约定呢?
- 你怎么知道应该用哪种呢?
- 32位和64位x86程序有区别吗?
我还看到人们可以在Windows汇编中使用printf
而不使用下划线.我知道这对Linux汇编代码来说是正常的,但在Windows上,如果我不使用下划线,就会出错.Windows上的其他人似乎没有这个问题.
In the original question that Jester answers (link above), it doesn't seem as though the user asking the question uses any special NASM instruction that would allow for that, unless it is something in the linker command they're using.
C. K. Young only explains how you can use printf
without an underscore if you use a certain NASM option.
- 那么,为什么一些Windows汇编程序在不使用NASM选项的情况下可以使用
printf
而不使用下划线呢?
我找了很多,但没有找到任何对这些奇怪案件的解释.