
   ; fasm example of writing 32-bit PE program using Win32 API

format PE GUI
entry start

; MessageBox type flags

MB_OK                = 0000h
MB_OKCANCEL          = 0001h
MB_ABORTRETRYIGNORE  = 0002h
MB_YESNOCANCEL       = 0003h
MB_YESNO             = 0004h
MB_RETRYCANCEL       = 0005h
MB_ICONHAND          = 0010h
MB_ICONQUESTION      = 0020h
MB_ICONEXCLAMATION   = 0030h
MB_ICONASTERISK      = 0040h
MB_DEFBUTTON1        = 0000h
MB_DEFBUTTON2        = 0100h
MB_DEFBUTTON3        = 0200h
MB_APPLMODAL         = 0000h
MB_SYSTEMMODAL       = 1000h
MB_TASKMODAL         = 2000h
MB_NOFOCUS           = 8000h

; Conventional dialog box and message box command IDs

IDOK      = 1
IDCANCEL  = 2
IDABORT   = 3
IDRETRY   = 4
IDIGNORE  = 5
IDYES     = 6
IDNO      = 7

section '.code' code readable executable

CodeSectionOrigin:

  start:
        push    MB_OK + MB_ICONEXCLAMATION
        push    _caption

        push    _message
        push    0
        call    [MessageBox]
  .local1:
        push    0
  .local2:
        call    [ExitProcess]

        jmp     .local1

section '.data' data readable writeable

DataSectionOrigin:

  _caption db 'Win32 assembly program',0
  _message db 'Hello World!',0

section '.idata' import data readable writeable

ImportSectionOrigin:

  dd 0,0,0,RVA kernel_name,RVA kernel_table
  dd 0,0,0,RVA user_name,RVA user_table
  dd 0,0,0,0,0

  kernel_table:
    ExitProcess dd RVA _ExitProcess
    dd 0
  user_table:
    MessageBox dd RVA _MessageBoxA
    dd 0

  kernel_name db 'KERNEL32.DLL',0
  user_name db 'USER32.DLL',0

  _ExitProcess dw 0
    db 'ExitProcess',0
  _MessageBoxA dw 0
    db 'MessageBoxA',0
