我正在尝试复制一个从低到高的字符串程序,它将打开一个文件,运行代码并在屏幕上打印它。但我想首先尝试打开测试文件 - 没有尝试阅读用户输入内容的麻烦。
我不明白我做错了什么,第一次系统调用后%rax的值是3,我理解是错误的。
.data
filename:
.asciz "test.txt"
inputInFile:
.string ""
.text
.global _start
_start:
#TO-DO: ASK FOR FILENAME
#open file syscall
mov $2,%rax
mov $filename,%rdi
mov $0,%rsi
mov $0666,%rdx
syscall
#TO-DO: ERROR FOR FILE NOT FOUND
.Loop:
#reading from file syscall, into buffer
mov $0, %rax
mov $0, %rdi
mov $inputInFile, %rsi
mov $500,%rdx
syscall
#input is in rax
#in case of end of file, close file
cmp $0,%rax
je .exit
#append input into buffer
mov %rax,%rdx
mov $1,%rax
mov $1,%rdi
mov $inputInFile,%rsi
syscall
jmp .Loop
#close file syscall
mov $3,%rax
mov $1,%rdi
syscall
.exit:
#close file
mov $3,%rax
mov $1,%rdi
syscall
#quit
mov $60,%rax
mov $0,%rdi
syscall