我正在用汇编语言编写一个 hello world 程序NASM在 32 位上Windows 7的。我的代码是:
section .text
global main ;must be declared for linker (ld)
main: ;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 ;our dear string
len equ $ - msg ;length of our dear string
我将此程序另存为你好.asm。接下来,我创建了hello.o with:
nasm -f elf hello.asm
现在我正在尝试创建exe使用此命令创建文件:
ld -s -o hello hello.o
但现在我收到这个错误:
ld 不被识别为内部或外部命令、可操作程序或批处理
为什么我会收到此错误,如何修复它?
下载并安装Mingw。然后放nasm在明格bin
文件夹。
在中创建一个文件夹bin
文件夹名为Hello
。在此文件夹中,
创建一个名为main.asm
使用以下代码:
extern _printf
global _main
section .data
msg: db "Hello, world!",10,0
section .text
_main:
push msg
call _printf
add esp,4
ret
从文件夹内打开终端并编译,
首先,使用 nasm 对象代码:
D:\MinGW\bin\Hello> ..\nasm -fwin32 main.asm
二、打电话gcc链接:
D:\MinGW\bin\Hello> ..\gcc main.obj -o main.exe
最后测试一下:
D:\MinGW\bin\Hello> main.exe
Hello, world!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)