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.
int mainfor one, asm is pretty system dependent so it could definitely crash depending on which computer your using - aaronmanls and change%e*to%r*, which gets somewhere. Don’t trust my opinion on it, however. - Ry-callinstructions from within GCC inline assembly is a simple thing to do. Unless you're very very careful, there's a lot of cornercases (especially in 64bit) where doing so will break things. Not always ... just sometimes ... and if so not usually right at the place where your inline asm ends up. A clobber list is mandatory if you do this. - FrankH.