Напишите программу на языке ассемблера MIPS для чтения шестнадцатеричных значений (по одному на строку) из файла. Имя файла должно быть запрошено и считано с консоли. Как только число будет прочитано, преобразуйте его во внутреннее хранилище. Формат ввода может быть фиксированным, 32-битным, дополнением до двух значений или знаковой величиной переменной длины (на ваш выбор). После преобразования значение должно быть выведено на консоль.
Вот некоторый код, который я написал, чтобы получить файл, но файл является текстом, и я не могу понять, какая часть преобразования.
# File Name:
# Author:
# Modification History
# 9/12/2019 Code written.
# 9/13/2019 Code modification.
# Procedures:
# Main: Ask the user for input and store the values.
# loop: Changes the input
# end: Ends the loop
# openF: Open file location
# readF: Reads file
# print: Prints file
# End: Ends the program
.data # This portion of the code holds the values to be called by main.
fileName: .space 100 # Holds a space for a file
enterFile: .asciiz "Enter the file name: " # Question asked
space: .space 40966 # Space for the value to be stored
.text # The portion of the program that holds the instructions.
# Main:
# Author:
# Modification History.
# 9/12/2019 Code written.
# 9/13/2019 Code modification.
# Description: Ask and stores user input.
# Arguments:
# $a0 - Starting address of respective strings.
# $a0 - Move function to pass an argument.
# $a1 - Move function to pass an argument.
Main: # Start of main
# Prints out a question for the user to answer.
li $v0, 4 # Loads the immediate value of 4 (Print a string) into the system call registry $v0.
la $a0, enterFile # Loads the address 'Enter' and saves the string into argument registry $a0.
syscall # Executes the system call 4 already loaded and prints out the string located at $a0.
# Waits for user input.
li $v0, 8 # Loads the immediate value of 8 (Read a string) into the system call registry $v0.
la $a0, fileName # Reads the file
li $a1, 50 # Loads 50 value
syscall # Executes the system call 8
# Converts the string
la $s0, fileName # $s0 contains base address of str
add $s2, $0, $0 # $s2 = 0
addi $s3, $0, '\n' # $s3 = '\n'
# loop:
# Author:
# Modification History.
# 9/12/2019 Code written.
# 9/13/2019 Code modification.
# Description: Converts files location
# Arguments: None.
loop: # stat of loop
lb $s1, 0($s0) # Uses $s0 for loading values
beq $s1, $s3, end # puts values into bytes
addi $s2, $s2, 1 # +1 on the counter
addi $s0, $s0, 1 # New location for counter
j loop # Continue loop
# end:
# Author:
# Modification History.
# 9/12/2019 Code written.
# 9/13/2019 Code modification.
# Description: Ends the conversion
# Arguments: None.
end: # end of loop
sb $0, 0($s0)
# openF:
# Author:
# Modification History.
# 9/12/2019 Code written.
# 9/13/2019 Code modification.
# Description: Opens the location of file
# Arguments:
# $a0 - Starting address of respective strings.
# $a1 - Move function to pass an argument.
# $a2 - Move function to pass an argument.
openF: # Open file for reading
li $v0, 13 # Loads the immediate value of 13 into the system call registry $v0.
la $a0, fileName # Loads the address 'fileNAme' and saves the string into argument registry $a0.
li $a1, 0 # Used for flag purposes
li $a2, 0 # Used for the Mode
syscall # Executes the system call 13 already loaded and prints out the string located at $a0.
move $s0, $v0 # Saves the file
# readF:
# Author:
# Modification History.
# 9/12/2019 Code written.
# 9/13/2019 Code modification.
# Description: Reads the contents of the file
# Arguments:
# $a0 - Starting address of respective strings.
# $a1 - Move function to pass an argument.
# $a2 - Move function to pass an argument.
readF: # reading from file just opened
li $v0, 14 # Loads the immediate value of 14 into the system call registry $v0.
move $a0, $s0 # Used for perameters
la $a1, space # Address of the space made
li $a2, 100 # Number of spaces to read
syscall # Executes the system call 14 already loaded and prints out the string located at $a0.
# print:
# Author:
# Modification History.
# 9/12/2019 Code written.
# 9/13/2019 Code modification.
# Description: This portion of the code displays the information to the user.
# Arguments:
# $a0 - Starting address of respective strings.
print: # Start of print
li $v0, 4 # Loads the immediate value of 4 into the system call registry $v0.
la $a0, space # loads up address
syscall # Executes the system call 4 already loaded and prints out the string located at $a0.
# End:
# Author:
# Modification History.
# 9/12/2019 Code written.
# 9/13/2019 Code modification.
# Description: The official end to the program.
# Arguments: None.
End: # Where the program ends.
li $v0,10 # Loads the immediate value of 10 (End program) into the system call registry $v0.
syscall # Executes the system call 10, ending the program.