gpt4 book ai didi

assembly - 无法在 Windows 7 中运行由 nasm 制作的可执行文件

转载 作者:行者123 更新时间:2023-12-02 05:44:22 24 4
gpt4 key购买 nike

我正在使用 Windows 7 学习汇编语言。我正在使用 NASM 创建目标文件,使用 mingw 创建可执行文件。

我正在使用以下命令来编译和运行可执行文件

del hello.o
del hello.exe
nasm -f elf hello.asm
ld hello.o -o hello.exe
hello

运行hello.exe文件时,出现“hello.exe已停止工作”的错误信息

同时使用下面的命令

    nasm -f bin hello.asm -o program.exe

我收到如下所示的错误

enter image description here

我的程序代码

global _start            ; global entry point export for ld
section .text
_start:
; sys_write(stdout, message, length)
mov eax, 4 ; sys_write syscall
mov ebx, 1 ; stdout
mov ecx, message ; message address
mov edx, length ; message string length
int 80h
; sys_exit(return_code)
mov eax, 1 ; sys_exit syscall
mov ebx, 0 ; return 0 (success)
int 80h
section .data
message: db 'Hello, world!',0x0A ; message and newline
length: equ $-message ; NASM definition pseudo-instruction

最佳答案

您拥有的是 Linux 代码(int 0x80sys_writesys_exit 是内核系统调用相当低级的东西)。

我不认为在 Windows 操作系统上运行时尝试调用 Linux 内核是个好主意。这不太可能有好结果 :-)

MinGW 是 Windows 的极简 GNU, 一种使用 gcc 工具链编写 Windows 应用程序的方法。因此,您必须遵守 Windows 规则。

关于assembly - 无法在 Windows 7 中运行由 nasm 制作的可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10477818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com