nasm windows hello world code example

Example 1: nasm hello world

; Print "Hello, world" in console
global  _main
extern  _printf

section .data
message: db  'Hello, World', 10, 0
    
section .text
_main:
    push message
    call _printf
    add esp, 4
    ret

Example 2: nasm hello world

; This code is for Microsoft Windows
; It does not work well in other OS

global _main
extern _MessageBoxA@16
extern _ExitProcess@4

section code use32 class=code
_main:
	push	dword 0 ; UINT uType = MB_OK
	push	dword title ; LPCSTR lpCaption
	push	dword banner ; LPCSTR lpText
	push	dword 0 ; HWND hWnd = NULL
	call	_MessageBoxA@16

	push	dword 0 ; UINT uExitCode
	call	_ExitProcess@4

section data use32 class=data
	banner:	db 'Hello, world!', 0
	title:	db 'Hello', 0

Tags:

Misc Example