【发布时间】:2021-02-24 13:21:16
【问题描述】:
虽然我有很多 c 和 c++ 经验,但我对汇编还是很陌生。 我的汇编代码应该像使用新语言的所有第一个程序一样打印 hello world。 它会打印出 hello world,但也会打印出一些额外的文本:
hello world!
.shstrtab.text.data
这是我的汇编程序:
section .text
global _start ;for the linker
_start:
mov edx, length ; message length
mov ecx, message ; message to write
mov ebx, 1 ; file descriptor stdout
mov eax, 4 ; system call number
int 0x80 ; call kernel
mov eax, 1 ;system call number for sys_exit to exit program
int 0x80 ; call kernel
section .data
message db "hello world!"
length DD 10
如果您知道如何解决此问题,请解释为什么会发生这种情况。 谢谢。
额外信息:我正在使用带有 ld 链接器的 nasm 汇编器
【问题讨论】:
-
您希望
mov edx,[length]加载该值。您正在加载可能是一个大数字的地址,因此您正在打印额外的东西。你也可以做length equ 10或类似的,那么你不需要括号。 PS:通过strace运行你的代码。
标签: linux assembly x86 nasm ld