winapi - Simple Hello World in x86 ASM - Windows console -
i'm trying run following hello word example in x86 assembly under windows:
global _main extern _getstdhandle@4 extern _writefile@20 extern _exitprocess@4 section.text _main : ; dword bytes; mov ebp, esp sub esp, 4 ; hstdout = getstdhandle(std_output_handle) push - 11 call _getstdhandle@4 mov ebx, eax ; writefile(hstdout, message, length(message), &bytes, 0); push 0 lea eax, [ebp - 4] push eax push(message_end - message) push message push ebx call _writefile@20 ; exitprocess(0) push 0 call _exitprocess@4 ; never here hlt message : db 'hello, world', 10 message_end :
following error when trying link assembled .obj file:
error lnk2001: unresolved external symbol _getstdhandle@4
error lnk2001: unresolved external symbol _writefile@20
error lnk2001: unresolved external symbol _exitprocess@4
fatal error lnk1120: 3 unresolved externals
source of example: how write hello world in assembler under windows?
how fix these? or also, why isn't example working me?
when using c compiler standard libraries typically linked code typically not done when calling linker separately.
the 3 functions located in "kernel32.dll" you'll have link against "kernel32.lib" (or "libkernel32.a" when using gnu tools).
your entry point "_main" assume want use startup object files, too.
however not neccessary in case may define "_main" linker entry point , not link against startup object files.
Comments
Post a Comment