[英]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.