There is an assembly code written for Windows API, how to compile it on Linux and run with Wine

后端 未结 2 452
误落风尘
误落风尘 2021-01-27 02:30

There is an example code in this introduction, like below:

; Sample x64 Assembly Program
; Chris Lomont 2009 www.lomont.org
extrn ExitProcess: PROC   ; external          


        
2条回答
  •  无人共我
    2021-01-27 03:01

    You should have been able to find a nasm syntax hello world. Anyway, here is a quick transcription:

    extern ExitProcess
    extern MessageBoxA
    section .data
    caption db '64-bit hello!', 0
    message db 'Hello World!', 0
    section .text
      sub    rsp,28h        ; shadow space, aligns stack
      mov    rcx, 0         ; hWnd = HWND_DESKTOP
      lea    rdx, [message] ; LPCSTR lpText
      lea    r8,  [caption] ; LPCSTR lpCaption
      mov    r9d, 0         ; uType = MB_OK
      call   MessageBoxA    ; call MessageBox API function
      mov    ecx, eax       ; uExitCode = MessageBox(...)
      call ExitProcess
    

    Assemble using nasm -f win64 hello.asm. You will also need a linker, I used the mingw port as ld hello.obj -lkernel32 -luser32 (let me emphasize this is not the native ld)

提交回复
热议问题