我必须创建一个反汇编程序,读取file.dump
并将其转换为程序集
我先测试读取txt文件。这是我的代码:
.data
INPUT_FILE: .asciiz "C:\\Users\\myPath\\teste.txt"
BUFFER: .space 1024
ERROR_MSG: .asciiz "ERROR OPENING FILE :( "
.text
# Open File
li $v0, 13 # Syscall for Open a File
la $a0, INPUT_FILE # Specify which file to open
li $a1, 0 # 0 = Read
li $a2, 0
syscall # Open the file (File Descriptor -> V0)
blt $v0, $zero, Error_Opening_File #Check if File was correctly opened
move $s6, $v0 # Save the descriptor into s6
read_file:
# Read File
li $v0, 14 # Syscal for Read from file
move $a0, $s6 # Pass the file descriptor to argument a0
la $a1, BUFFER # Address of Buffer to read
la $a2, 4 # Hardcoded Buffer size
syscall
blt $v0, $zero, Error_Opening_File
# Write
li $v0, 4 # Syscall for Print String
la $a0, BUFFER
syscall
j read_file
li $v0, 10
syscall
Error_Opening_File:
li $v0, 4
la $a0, ERROR_MSG
syscall
它正确阅读"正确"但它永远不会停止......当它到达文本的最后一部分时,它只是不断重复最后一部分。
阅读Syscall 14 (read from file)
$ v0包含读取的字符数(如果文件结束则为0,如果错误则为负)。见表格下面的注释
我怎样才能确定它什么时候到达? 如何让我的代码逐个阅读,直到没有别的东西可读?
认为将来我需要阅读转储到text-binary中的汇编代码。