我学习组件使用以下的Hello World程序如何打印字符串的长度在装配
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 ;our string
len equ $ - msg ;length of our string
原来的问题我是什么是字符串的长度的意思。这是否意味着字符数或内存中的长度(字节数)? 检查这个我想打印变量len。我怎样才能做到这一点?我天真地试图定义新的变量
len2 equ $ - len
,然后改为运行
mov edx,len2 ;message length
mov ecx,len ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
尝试打印LEN,但这种印刷什么。如何打印由len代表的号码?
您可能需要检查[**如何在汇编NASM中打印数字**](https://stackoverflow.com/questions/8194141/how-to-print-a-number-in-assembly- nasm)简短的回答是你写*字符*到'stdout'。数字是一个十进制值,而不是可以立即写入的字符串,您必须将整数或无符号值转换为其字符表示形式,然后将其写入'stdout'。 –
出于好奇,你编程的操作系统是什么?视窗? Unix的?苹果系统?我在问,因为在这样的问题之上,经常有人问这个问题是否使用了错误平台的教程。 –
谢谢。我正在使用Ubuntu。出于好奇,当我尝试直接使用stdout打印数字时,我什么也没有得到。为什么它不打印什么,而不是打印一些废话? –