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