无法执行汇编程序
can't execute assembly program
我今天决定学习汇编,因为它看起来是一个非常强大的工具,但我不知道从哪里开始学习它,所以我搜索了一下,发现了这个:
https://www.tutorialspoint.com/assembly_programming
它告诉我安装NASM和MinGW来编译和链接,所以我下载并安装了它并确保它们都正常工作。
我复制了给定的代码
section .text
global _start ;must be declared for linker (ld)
_start: ;tells linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Hello, world!', 0xa ;string to be printed
len equ $ - msg ;length of the string
并将其粘贴到一个名为"hello.asm"的空文档中并通过编写
进行编译
nasm -f elf hello.asm
(later nasm -f win32 hello.asm)
之后
ld hello.o -o hello.exe
(later ld hello.obj -o hello.exe)
它两次都成功地创建了一个 .exe 文件,但是当我尝试执行它时,它只打开了 windows 命令提示符,并且打开了一个新的 window,上面写着 "hello.exe doesn't work anymore".
我知道这不会输出任何东西,但至少不应该 运行 吗?
我做错了什么?
使用:
- Windows7专业64位
- AMD FX 4350
- nasm-2.12.02
- MinGW
您将需要不同的教程,因为用户 tkausl 指出本教程适用于 Linux x86_64 位。
对于 windows,如果您愿意,您仍然可以使用 NASM 汇编程序和 MinGW,但是由于调用不同,您的代码看起来会有所不同,并且还需要您使用外部图书馆。
不过,我建议为 Windows 使用 MASM,因为它是由 Microsoft 设计的,并且还包含在具有其他工具的 MASM32v8 包中。您可以从这里获取 MASM:http://www.masm32.com/
还有Windows组装教程:
https://www-s.acm.illinois.edu/sigwin/old/workshops/winasmtut.pdf
不过,如果你打算使用NASM汇编器,那么你可以参考这里caffiend发布的答案:
How to write hello world in assembler under Windows?
我今天决定学习汇编,因为它看起来是一个非常强大的工具,但我不知道从哪里开始学习它,所以我搜索了一下,发现了这个: https://www.tutorialspoint.com/assembly_programming
它告诉我安装NASM和MinGW来编译和链接,所以我下载并安装了它并确保它们都正常工作。
我复制了给定的代码
section .text
global _start ;must be declared for linker (ld)
_start: ;tells linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Hello, world!', 0xa ;string to be printed
len equ $ - msg ;length of the string
并将其粘贴到一个名为"hello.asm"的空文档中并通过编写
进行编译nasm -f elf hello.asm
(later nasm -f win32 hello.asm)
之后
ld hello.o -o hello.exe
(later ld hello.obj -o hello.exe)
它两次都成功地创建了一个 .exe 文件,但是当我尝试执行它时,它只打开了 windows 命令提示符,并且打开了一个新的 window,上面写着 "hello.exe doesn't work anymore".
我知道这不会输出任何东西,但至少不应该 运行 吗?
我做错了什么?
使用:
- Windows7专业64位
- AMD FX 4350
- nasm-2.12.02
- MinGW
您将需要不同的教程,因为用户 tkausl 指出本教程适用于 Linux x86_64 位。
对于 windows,如果您愿意,您仍然可以使用 NASM 汇编程序和 MinGW,但是由于调用不同,您的代码看起来会有所不同,并且还需要您使用外部图书馆。
不过,我建议为 Windows 使用 MASM,因为它是由 Microsoft 设计的,并且还包含在具有其他工具的 MASM32v8 包中。您可以从这里获取 MASM:http://www.masm32.com/
还有Windows组装教程: https://www-s.acm.illinois.edu/sigwin/old/workshops/winasmtut.pdf
不过,如果你打算使用NASM汇编器,那么你可以参考这里caffiend发布的答案: How to write hello world in assembler under Windows?