;
; nasm/nasm -fwin32 hoge.asm
; alink/alink hoge.obj win32.lib -L /alink/lib -m -oPE -entry _start
;
  bits 32
extern MessageBoxA
extern ExitProcess

section .text
global _start
_start:
  push ebp
  mov ebp, esp

  mov eax, ds
  mov es, eax
  mov edi, msg
  mov eax, 000000deH
  push eax
  call bin2hex
  mov [edi], ah
  inc edi
  mov [edi], al

  push dword 30H ; MB_ICONEXCLAMATION
  push dword title
  push dword msg
  push dword 0
  call MessageBoxA
  push dword 0
  call ExitProcess
  mov eax, 0

  mov esp, ebp
  pop ebp
  ret

b2a:
  push ebp
  mov ebp, esp

  mov eax, [esp + 8]
  and al, 0FH
  or al, 30H
  cmp al, 39H
  jle skip
  add al, 7
skip:

  mov esp, ebp
  pop ebp
  ret

bin2hex:
  push ebp
  mov ebp, esp

  mov eax, [esp + 8]
  mov cl, 4
  shr al, cl
  push eax
  call b2a
  xor edx, edx
  mov dh, al
  mov eax, [esp + 12] ; shifted because first push eax
  push eax
  call b2a
  mov ah, dh

  mov esp, ebp
  pop ebp
  ret

section .data
title: db 'win32api', 0
msg: db '00', 0
