如何在64位下将nasm编译为exe文件

问题描述 投票:0回答:1

我使用的是 Windows 11。 我在将 asm 文件编译为 64 位时遇到问题。

汇编代码: asm code 1 种方法 makefile conf 2方法 makefile conf 我已经尝试了所有方法,但 Windows 仍然将 exe 文件视为 16 位

请帮忙 我想学习 asm lang ;)

编辑: chatgbt helps(windows sys calls) 编辑2:i dont even know whats going on here

assembly compiler-errors nasm
1个回答
0
投票

使用 Windows 系统调用进行编码

section .data
hello_msg db 'Hello, world!'
section .text
extern _MessageBoxA@16
extern _ExitProcess@4
global _WinMain@16
_WinMain@16:
push dword 0   
push dword hello_msg   
push dword hello_msg 
push dword 0  
call _MessageBoxA@16
push dword 0 
call _ExitProcess@4

更正的 makefile:

all:
nasm -f win32 hello.asm -o hello.obj
gcc -m32 hello.obj -o hello.exe -L"F:/mingw/lib" -luser32 -lkernel32
start:
hello.exe

一些问题出现如下:

ld -m32 hello.obj -o hello.exe -luser32 -lkernel32
ld: unrecognised emulation mode: 32
Supported emulations: i386pe

ld -mi386pe  hello.obj -o hello.exe -luser32 -lkernel32
ld: cannot find -luser32
ld: cannot find -lkernel32

但至少它有效

PS:在 Windows 上组装比较困难;/

© www.soinside.com 2019 - 2024. All rights reserved.