Assembly language examples using NASM on Windows
Console Message - 32 bit
Description
Output a message to the console window, 32 bit.
Assemble
- nasm -f win32 ConsoleMessage32.asm -o ConsoleMessage32.obj
Link
- golink /entry:Start /console kernel32.dll user32.dll ConsoleMessage32.obj
- polink /ENTRY:Start /SUBSYSTEM:CONSOLE /LIBPATH:c:\lib32 kernel32.lib user32.lib ConsoleMessage32.obj
Notes
Open a console window, and run the executable.
The message length is calculated by subtracting the starting address of Message from the starting address of the line containing the
$.
_WriteFile@20 was chosen Instead of _WriteConsoleA@20, as the output can be redirected to a file using
> filename
Code
NULL EQU 0
STD_OUTPUT_HANDLE EQU -11
extern _GetStdHandle@4
extern _WriteFile@20
extern _ExitProcess@4
global Start
section .data
Message db "Console Message 32", 0Dh, 0Ah
MessageLength EQU $-Message
section .bss
StandardHandle resd 1
Written resd 1
section .text
Start:
push STD_OUTPUT_HANDLE
call _GetStdHandle@4
mov dword [StandardHandle], EAX
push NULL
push Written
push MessageLength
push Message
push dword [StandardHandle]
call _WriteFile@20
push NULL
call _ExitProcess@4