I think there was a little error in Frank's Code
; ----------------------------------------------------------------------------
; hello.asm
;
; This is a Win32 console program that writes "Hello, World" on one line and
; then exits. It uses only plain Win32 system calls from kernel32.dll, so it
; is very instructive to study since it does not make use of a C library.
; Because system calls from kernel32.dll are used, you need to link with
; an import library. You also have to specify the starting address yourself.
;
; Assembler: NASM
; OS: Any Win32-based OS
; Other libraries: Use gcc's import library libkernel32.a
; Assemble with "nasm -fwin32 hello.asm"
; Link with "ld -e go hello.obj -lkernel32"
; ----------------------------------------------------------------------------
global go
extern _ExitProcess@4
extern _GetStdHandle@4
extern _WriteConsoleA@20
extern _ReadConsole@20
section .data
msg: db 'Hello, World', 10
handle: dd 0
read_handle dd 0
written: db 0
section .text
go:
; handle = GetStdHandle(-11)
push dword -11
call _GetStdHandle@4
mov [handle], eax
push -10 ; stdin
call _GetStdHandle@4
mov [read_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
push eax
mov eax, esp ; buffer for char?
push 0
push written ; reuse this?
push 1 ; characters to read?
push eax
push dword [read_handle]
call ReadConsole
pop eax ; character read in al?
; ExitProcess(0)
push dword 0
call _ExitProcess@4
The error fixed Code
%include "io.inc"
section .text
global CMAIN
CMAIN:
mov ebp, esp; for correct debugging
; ----------------------------------------------------------------------------
; hello.asm
;
; This is a Win32 console program that writes "Hello, World" on one line and
; then exits. It uses only plain Win32 system calls from kernel32.dll, so it
; is very instructive to study since it does not make use of a C library.
; Because system calls from kernel32.dll are used, you need to link with
; an import library. You also have to specify the starting address yourself.
;
; Assembler: NASM
; OS: Any Win32-based OS
; Other libraries: Use gcc's import library libkernel32.a
; Assemble with "nasm -fwin32 hello.asm"
; Link with "ld -e go hello.obj -lkernel32"
; ----------------------------------------------------------------------------
global go
extern _ExitProcess@4
extern _GetStdHandle@4
extern _WriteConsoleA@20
extern _ReadConsoleA@20
section .data
msg: db 'Hello, World', 10
handle: dd 0
read_handle dd 0
written: db 0
section .text
go:
; handle = GetStdHandle(-11)
push dword -11
call _GetStdHandle@4
mov [handle], eax
push -10 ; stdin
call _GetStdHandle@4
mov [read_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
push eax
mov eax, esp ; buffer for char?
push 0
push written ; reuse this?
push 1 ; characters to read?
push eax
push dword [read_handle]
call _ReadConsoleA@20
pop eax ; character read in al?
; ExitProcess(0)
push dword 0
call _ExitProcess@4
xor eax, eax
ret
Now. it is possible to Assemble the program . But same issues , the output windows exits fast .