Friday, 9 August 2013

How to compile this program with inline asm?

How to compile this program with inline asm?

I cannot compile this program taken from a tutorial. It should print
"Hello World".
void main()
{
__asm__("jmp forward\n\t"
"backward:\n\t"
"popl %esi\n\t"
"movl $4, %eax\n\t"
"movl $2, %ebx\n\t"
"movl %esi, %ecx\n\t"
"movl $12, %edx\n\t"
"int $0x80\n\t"
"int3\n\t"
"forward:\n\t"
"call backward\n\t"
".string \"Hello World\\n\""
);
}
gcc 4.7 under Linux gives me the following error:
gcc hello.c -o hello
hello.c: Assembler messages:
hello.c:5: Error: invalid instruction suffix for `pop'
Is there also a way to avoid to specify double quotes for each line?
Also, I'd like to know how to modify the program to use libc call printf
instead of the kernel service.

No comments:

Post a Comment