我需要编写一个MIPS汇编语言程序来从文件中读取十六进制值(每行一个)。应该请求文件名并从控制台读取文件名。读取号码后,将其转换为内部存储器。输入格式可以是固定格式,32位,二进制补码值或可变长度的有符号幅度。转换后,该值应打印到控制台。
到目前为止我所拥有的:
.data
fileName: .space 100
prompt1: .asciiz "Enter the file name: "
buffer: .space 40966
.text
main:
# prompt user for file name
li $v0, 4 #system call for printing string
la $a0, prompt1 #load prompt1
syscall #print string
# when entering name of the file, add its entire directory path with double backslashes
li $v0, 8 #system call for reading string
la $a0, fileName #load user input into the address of fileName
li $a1, 50 # max number of characters the fileName can hold
syscall #store user input into fileName
# converting the string into a null-terminated string
# replacing last character of fileName with 0 instead of \n
la $s0, fileName # $s0 contains fileName
add $s2, $0, $0 # $s2 = 0 (null terminator)
addi $s3, $0, '\n' # $s3 = '\n' (newline escape sequence)
removeNL:
lb $s1, 0($s0) # load character into $s0
beq $s1, $s3, replaceNL # Break if byte is equal to newline *
addi $s2, $s2, 1 # increment counter otherwise
addi $s0, $s0, 1 # increment string address
j removeNL
replaceNL:
sb $0, 0($s0) #replace newline with null terminator
# Open file for reading now that input file name is converted to null-terminated string
li $v0, 13 # system call for open file
la $a0, fileName # address of null-terminated string containing filename
li $a1, 0 # flags
li $a2, 0 # mode
syscall # open a file
move $s0, $v0 # save the file descriptor
# reading from file just opened
li $v0, 14 # system call for reading from file
move $a0, $s0 # file descriptor
la $a1, buffer # address of input buffer
li $a2, 40966 # maximum number of char