在读取字节后的文件时,我无法退出循环。在循环中,我将读取字节与EOF(= -1)进行比较。以前我把读取字节放入寄存器,所以我可以在dbg中看到它,结果是程序挂起来自文件的最后一个字节。
SYS_READ equ 0
SYS_OPEN equ 2
SYS_EXIT equ 60
O_RDONLY equ 0
EOF equ -1
section .data
filename db "test3.txt",0
section .bss
number resb 1
fd resb 8
section .text
global _start
_start:
call _read_file
call _sys_exit_0
_read_file:
call _sys_open
mov [fd], rax
_read_file_loop:
call _sys_read
cmp byte [number], EOF
jne _read_file_loop
ret
_sys_open:
mov rax, SYS_OPEN
mov rdi, filename
mov rsi, O_RDONLY
mov rdx, 0644o
syscall
ret
_sys_read:
mov rax, SYS_READ
mov rdi, [fd]
mov rsi, number
mov rdx, 1
syscall
ret
_sys_exit_0:
mov rax, SYS_EXIT
mov rdi, 0
syscall