有为Windows API编写的汇编代码,以及如何在Linux上编译并与Wine一起运行的代码 [英] There is an assembly code written for Windows API, how to compile it on Linux and run with Wine
问题描述
此介绍,如下所示:
; Sample x64 Assembly Program
; Chris Lomont 2009 www.lomont.org
extrn ExitProcess: PROC ; external functions in system libraries
extrn MessageBoxA: PROC
.data
caption db '64-bit hello!', 0
message db 'Hello World!', 0
.code
Start PROC
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
Start ENDP
End
上面的代码在hello.asm
内部,并且在Windows上,可以使用以下代码进行编译:
The above code is inside hello.asm
and on Windows, it can be compiled with:
ml64 hello.asm /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Start
我无法使用Windows和MASM,因为我使用Linux并与NASM合作.我认为,如果我在Linux上编译代码,则可以使用Wine
来运行它.但是,我无法确定如何在Linux上使用NASM进行编译,也无法确定与MASM等效的NASM选项是什么.有人可以帮我吗?
I don't have access to Windows and MASM, since I'm on Linux and work with NASM. I think if I compile the code on Linux, I would be able to run it with Wine
. But yet, I couldn't figure out how to compile it with NASM on Linux and also I couln't figure out what are the NASM options which are equivalent to the MASM ones. Can anybody help me?
推荐答案
您应该已经能够找到nasm语法的hello世界.无论如何,这是一个简短的抄写:
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
使用nasm -f win64 hello.asm
进行组装.您还将需要一个链接器,我将mingw端口用作ld hello.obj -lkernel32 -luser32
(让我强调这不是本地的ld
)
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
)
这篇关于有为Windows API编写的汇编代码,以及如何在Linux上编译并与Wine一起运行的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!