无法在Windows 7中运行nasm生成的可执行文件

时间:2012-05-07 06:45:33

标签: assembly nasm

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

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

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

2 个答案:

答案 0 :(得分:3)

你所拥有的是 Linux 代码(int 80sys_writesys_exit是内核系统调用的相当低级的东西。)

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

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

答案 1 :(得分:2)

除了你的代码调用linux内核之外,就像paxdiablo指出的那样,你已经将它组装成平面形式的二进制文件,它不会在windows下运行。您需要使用nasm -f win32