Assembly language examples using NASM on Windows

Message Box - 32 bit




Message Box 32

Description
Display a message in a standard Windows Message Box, 32 bit.

Assemble

Link

Notes
Double click the icon to run the executable.

The Message Box exits when the Yes (to exit) button is clicked.

Code

                                                ; Message Box, 32 bit. V1.01
NULL          EQU 0                             ; Constants
MB_DEFBUTTON1 EQU 0
MB_DEFBUTTON2 EQU 100h
IDNO          EQU 7
MB_YESNO      EQU 4

extern _MessageBoxA@16                          ; Import external symbols
extern _ExitProcess@4                           ; Windows API functions, decorated

global Start                                    ; Export symbols. The entry point

section .data                                   ; Initialized data segment
 MessageBoxText    db "Do you want to exit?", 0
 MessageBoxCaption db "MessageBox 32", 0

section .text                                   ; Code segment
Start:
 push  MB_YESNO | MB_DEFBUTTON2                 ; 4th parameter. 2 constants ORed together
 push  MessageBoxCaption                        ; 3rd parameter
 push  MessageBoxText                           ; 2nd parameter
 push  NULL                                     ; 1st parameter
 call  _MessageBoxA@16

 cmp   EAX, IDNO                                ; Check the return value for "No"
 je    Start

 push  NULL
 call  _ExitProcess@4