如何将定义的四元数(8 字节)作为参数传递给 32 位 NASM 程序集中的子程序

How can I pass a Defined quad number (8 BYTES) as a parameters to a subprogram in 32 bit NASM assembly

我正在使用 32 位 NASM 汇编,想知道是否有办法将定义的四元数(8 字节)作为参数传递给 Nasm 32 位汇编中的子程序.我知道 32 位汇编中的堆栈被组织为接受定义的双字(4 个字节)。所以我想知道这是否有可能做到。

示例代码:

section .data 
x: dq 10 ;Defining x as a 8 byte number

section .bss 

section .text 
global asm_main

asm_main:
enter 0,0 ;Creating stack frame

push QWORD[x] ;pushing x as a parameter for the test subprogram
call test ;Calling the subprogram
add esp,8 ;Deallocating memory used by parameter 

leave
ret

但是当我 运行 代码时,我得到一个错误提示 (push QWORD[x]):

instruction not supported in 32-bit mode

一种方法是分别推送每个双字

push dword [x+4]    ; high half first
push dword [x]      ; then low half

或者您可以使用 movq load/store 通过 XMM 寄存器进行 64 位复制。 x87 fild / fistp 可能不值得使用,但 movq 如果 SSE2 可用。

顺便说一句,避免使用 enter 指令。它非常 慢。像编译器一样使用 push ebp / mov ebp,esp 。 (郑重声明,您可以通过查看调用另一个函数的函数的编译器输出来回答您自己的问题,例如 void foo(int64_t *p) { bar(*p); }https://godbolt.org/z/0rUx-M