I am trying to study passing arguments into a function via stack in assembly. I am using fedora 20, a 64-bit system.
when I try the following code,
pushl %ebp
popl %ebp
I get the error,
Error: invalid instruction suffix for `push'
how will I overcome this error!
i compiled it by, as -ggstabs -o Function_Stack.o Function_Stack.c
The error you're getting comes out from a very simple fact : the push
instruction in 32-bit mode accepts 16-bit and 32-bit immediates as arguments. However, the push
instruction used in 64-bit mode accepts only 16-bit and 64-bit immediates. Since you're clearly compiling your code as 64-bit, the assembler throws an error, since it cannot possibly encode such an instruction. Also, do keep in mind that you force the operand size yourself by adding the l
suffix to the push
instruction. Everything I just wrote here is exactly the same for pop
, except that it accepts registers/memory, not immediates.
However, you also need to keep in mind the differences in the ABI between 32-bit and 64-bit Linux systems. The ABI specifies, among other things, how parameters are passed to functions, and how to call the kernel from user-mode applications. Your code is clearly written for 32-bit mode, seeing how it uses the stack for passing arguments and the (very) obsolete int $0x80
way of invoking syscalls. In order to learn about the 64-bit ABI, see this document.
Alternatively, you have the option of compiling 32-bit code on a 64-bit system. Such an executable will work if you have the necessary 32-bit runtime libraries installed on your 64-bit system. Most distributions allow you to do that in different ways. Your compiler, as
, has the --32
switch for emitting 32-bit code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With