Q :
hello.c: Assembler messages: hello.c:5: Error: invalid instruction suffix for `pop'
A : popl is available on x86-32, but not on x86-64 (instead it has popq ). You either need to adapt your build code to work on x86-64, or you need to call GCC to generate x86-32 binary output.
Assuming you want to generate x86-32, use the -m32 command line -m32 .
Q :
Is there a way to avoid specifying double quotes for each line?
A : No. This is because __asm__() is a pseudo-function that takes string arguments, so the string follows the C syntax. The contents of the string are passed to the assembler with little or no processing.
Note that in C, when strings are matched, they are concatenated. For example, "a" "b" matches "ab" .
Note that in assembly language (GAS) syntax, you can separate statements using a newline or semicolon, for example: "movl xxx; call yyy" or "movl xxx \n call yyy" .
Q :
how to change the program to use the libc printf call
A. Follow the calling convention for C on x86 . Press the arguments from right to left, call the function, then clear the stack. Example:
pushl $5678 pushl $1234 pushl $fmtstr call printf addl $12, %esp fmtstr: .string "Hello %d %d\n"
source share