Delphi XE2+ 调用NASM生成的obj

; 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以上调用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值