2

I am using 32-bit NASM assembly and was wondering if there is a way to pass a defined quad number (8bytes) as a parameter to a subprogram in Nasm 32-bit assembly. I know that the stack in 32bit assembly is organized to accept defined double words (4 bytes). So I am wondering if this is even possible to do.

Example code:

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

But when I run the code I get an error saying that (push QWORD[x]):

instruction not supported in 32-bit mode

zx485
  • 28,498
  • 28
  • 50
  • 59
John
  • 23
  • 3

1 Answers1

1

One way is to push each dword separately

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

Or you can do a 64-bit copy via an XMM register with movq load/store. x87 fild / fistp is probably not worth using, but movq is if SSE2 is available.

BTW, avoid the enter instruction. It's very slow. Use push ebp / mov ebp,esp like compilers do. (And for the record, you could have answered your own question by looking at compiler output for a function that calls another function, like void foo(int64_t *p) { bar(*p); }. https://godbolt.org/z/0rUx-M

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847