我現在正在學習組裝。有人可以解釋我如何在 x86-64 NASM 程式集中使用標準輸入讀取紡織品,以及我在哪里存盤讀取的 ascii 符號?
uj5u.com熱心網友回復:
我假設您正在為此使用 linux。首先,您需要使用 open 系統呼叫打開檔案。這會將檔案描述符放入 %rax。然后,您可以將該檔案描述符與您想要讀取的位元組數一起用于讀取系統呼叫。最后,您需要使用檔案的檔案描述符通過 close 系統呼叫關閉檔案。一個示例可能如下所示:
;; reading from a file using syscalls
global _start
section .text
_start:
mov rax, 2 ;; using the open syscall
mov rdi, filename
mov rsi, 0 ;; using O_RDONLY
syscall
mov rbx, rax ;; storing the fd for later
mov rax, 0 ;; read syscall
mov rdi, rbx ;; the file descriptor
mov rsi, buffer
mov rdx, 13 ;; bytes to read
syscall
mov rax, 1 ;; write syscall
mov rdi, 1 ;; stdout
mov rsi, buffer
mov rdx, 13
syscall
mov rax, 3 ;; using the close syscall
mov rdi, rbx
syscall
mov rax, 60
mov rdi, 0
syscall
section .data
filename: db "file.txt", 0x0
section .bss
buffer: resb 13
檔案.txt:
hello world
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/412647.html
標籤:
上一篇:與其他寬度不同,為什么短(16位)變數將值移動到暫存器并將其存盤?
下一篇:POST內容在接待處為空
