[英]Null character is not acting as end of string in assembly (NASM)
在 c 语言中,我们可以使用 '\0' null 字符作为字符串的结尾。
#include <stdio.h>
int main() {
char msg[] = "hello\0world";
printf("msg = %s", msg);
}
此代码将只打印hello 。 不是世界。
但是在 linux x86 NASM 中,我正在使用以下代码,但它正在打印helloworld 。
section .data
msg db "hello", 0, "world"
section .text
global main
main:
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, 20
int 0x80
mov eax, 1
mov ebx, 0
int 0x80
ret
为什么 null 字符在这里不能用作字符串结尾? 我该怎么做才能在装配中得到它?
您使用write
系统调用以您指定的确切大小写入数据。 write
function 不知道它写入的数据,它只是一系列字节。
如果你想写一个以 null 结尾的字符串,你要么需要找到终止符的 position 并从那个 position 计算长度,要么使用一个知道 C 以 null 结尾的字符串的 function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.