I am trying to learn (or at least understand) assembly on windows. I found this Hello World example somewhere and I want to make an .exe out of it just to be sure I have everything set up correctly. For people that will post other Hello World examples I want to make clear I am looking for one with direct windows api calls.
global _start
extern _ExitProcess@4
extern _GetStdHandle@4
extern _WriteConsoleA@20
section .data
msg: db 'Hello, World', 10
handle: db 0
written:
db 0
section .text
_start:
; handle = GetStdHandle(-11)
push dword -11
call _GetStdHandle@4
mov [handle], eax
; WriteConsole(handle, &msg[0], 13, &written, 0)
push dword 0
push written
push dword 13
push msg
push dword [handle]
call _WriteConsoleA@20
; ExitProcess(0)
push dword 0
call _ExitProcess@4
I assemble it successfully like so
nasm -fwin32 hello.asm
Then when I try to link it with ld like so
ld hello.obj -lkernel32
It produces an executable but when I try to run it I get this
Program 'a.exe' failed to run: The specified executable is not a valid application for this OS platform.At line:1 char:1
+ .\a.exe
+ ~~~~~~~.
At line:1 char:1
+ .\a.exe
+ ~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException
+ FullyQualifiedErrorId : NativeCommandFailed
I even downloaded ALINK but whenever I try to link it like so
ALINK hello.obj C:\Windows\System32\kernel32.dll
I get this output
ALINK v1.6 (C) Copyright 1998-9 Anthony A.J. Williams.
All Rights Reserved
Loading file .\programs\hello.obj
Loading file C:\Windows\System32\kernel32.dll
Unsupported CPU type for module
what flags do I have to pass to the linkers, what am I doing wrong?