; Message Box, 64 bit. V1.02
MB_DEFBUTTON1 EQU 0 ; Constants
MB_DEFBUTTON2 EQU 100h
IDNO EQU 7
MB_YESNO EQU 4
extern MessageBoxA ; Import external symbols
extern ExitProcess ; Windows API functions, not decorated
global Start ; Export symbols. The entry point
section .data ; Initialized data segment
MessageBoxText db "Do you want to exit?", 0
MessageBoxCaption db "MessageBox 64", 0
section .text ; Code segment
Start:
sub RSP, 8 ; Align the stack to a multiple of 16 bytes
sub RSP, 32 ; 32 bytes of shadow space
.DisplayMessageBox:
xor ECX, ECX ; 1st parameter
lea RDX, [REL MessageBoxText] ; 2nd parameter
lea R8, [REL MessageBoxCaption] ; 3rd parameter
mov R9D, MB_YESNO | MB_DEFBUTTON2 ; 4th parameter. 2 constants ORed together
call MessageBoxA
cmp RAX, IDNO ; Check the return value for "No"
je .DisplayMessageBox
add RSP, 32 ; Remove the 32 bytes
xor ECX, ECX
call ExitProcess
- nasm -f win64 MessageBox64.asm -o MessageBox64.obj
- golink /entry:Start kernel32.dll user32.dll MessageBox64.obj
program Test_ASMOBJ; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, Winapi.Windows; {$LINK MessageBox64.obj} {$IFDEF CPUX64} procedure Start();external; {$ENDIF} type Test = record a : byte; b : int16; c : byte; d : integer; end; Test2 = record case Integer of 0: (p : Pointer); 1: (s : byte); 2: (l: Integer); end; begin try Writeln(SizeOf(test)); Writeln(SizeOf(test2)); Start(); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.
从Delphi XE2开始,已能够支持C语言编译而成的coff格式文件。NASM有着更广泛的用户群,其编译的obj能够非常顺畅的被XE2以上调用。