Assembly language examples using NASM on Windows
Message Box - 64 bit
Description
Display a message in a standard Windows Message Box, 64 bit.
Assemble
- nasm -f win64 MessageBox64.asm -o MessageBox64.obj
Link
- golink /entry:Start kernel32.dll user32.dll MessageBox64.obj
- polink /ENTRY:Start /SUBSYSTEM:WINDOWS /LIBPATH:c:\lib64 kernel32.lib user32.lib MessageBox64.obj
Notes
Double click the icon to run the executable.
The Message Box exits when the Yes (to exit) button is clicked.
Code
MB_DEFBUTTON1 EQU 0
MB_DEFBUTTON2 EQU 100h
IDNO EQU 7
MB_YESNO EQU 4
extern MessageBoxA
extern ExitProcess
global Start
section .data
MessageBoxText db "Do you want to exit?", 0
MessageBoxCaption db "MessageBox 64", 0
section .text
Start:
sub RSP, 8
sub RSP, 32
.DisplayMessageBox:
xor ECX, ECX
lea RDX, [REL MessageBoxText]
lea R8, [REL MessageBoxCaption]
mov R9D, MB_YESNO | MB_DEFBUTTON2
call MessageBoxA
cmp RAX, IDNO
je .DisplayMessageBox
add RSP, 32
xor ECX, ECX
call ExitProcess