How to call "printf" directly without including stdio.h ?
I found a interesting tutorial here:
http://www.halcode.com/archives/2008/05/11/hello-world-c-and-gnu-as/
So, here's my attempt:
int main(){
char ss[] = "hello";
asm (
"pushl %ebp ;"
"movl %esp, %ebp ;"
"subl $4, %esp ;"
"movl $ss, (%esp) ;"
"call _printf ;"
"movl $0, %eax ;"
"leave ;"
"ret ;"
);
return 0;
}
I'm using MinGW 4.4, and here's how I compile it:
gcc -c hello.c -o hello.o
ld hello.o -o hello.exe C:/mingw/lib/crt2.o C:/mingw/lib/gcc/mingw32/4.4.0/crtbegin.o C:/mingw/lib/gcc/mingw32/4.4.0/crtend.o -LC:/mingw/lib/gcc/mingw32/4.4.0 -LC:/mingw/lib -lmingw32 -lgcc -lmsvcrt -lkernel32
Unfortunately, it fails:
hello.o:hello.c:(.text+0x26): undefined reference to `ss'
How to fix this?