1
很简单的问题。如何在不写入空字节的情况下写入nasm?
这个nasm应该写一个用户编写的消息(即hello)给一个文件,这个文件又是由一个参数的用户输入决定的。它这样做很好,但问题是,它会写入所有之后未使用的空字节。例如,如果我为用户输入保留32个字节,并且用户仅使用四个字符输入,那么将打印字节数据以及28个空字节。
如何停止打印空字节?使用
代码:
global _start
section .text
_start:
mov rax, 0 ; get input to write to file
mov rdi, 0
mov rsi, msg
mov rdx, 32
syscall
mov rax, 2 ; open the file at the third part of the stack
pop rdi
pop rdi
pop rdi
mov rsi, 1
syscall
mov rdi, rax
mov rax, 1 ; write message to file
mov rsi, msg
mov rdx, 32
syscall
mov rax, 3 ; close file
syscall
mov rax, 1 ; print success message
mov rdi, 1
mov rsi, output
mov rdx, outputL
syscall
mov rax, 60 ; exit
mov rdi, 0
syscall
section .bss
msg: resb 32
section .data
output: db 'Success!', 0x0A
outputL: equ $-output