Question
I have the following MIPS(MARS 4.5) code: .data fileName: .asciiz numbers.txt error1: .asciiz File failed to open FILE: .word buffer: .space 1000 zero: .asciiz 0
I have the following MIPS(MARS 4.5) code:
.data
fileName: .asciiz "numbers.txt"
error1: .asciiz "File failed to open"
FILE: .word
buffer: .space 1000
zero: .asciiz "0"
nine: .asciiz "9"
decimal: .asciiz "."
.text
la $a0 fileName #Call the file open procedure
jal openfile
sw $v0, FILE
#read the entire contents of the file to buffer
li $v0, 14
lw $a0, FILE
la $a1, buffer
li $a2, 999
syscall
#close file
li $v0, 16
lw $a0, FILE
syscall
la $t2, buffer #Initialize t2 to front of buffer
jal getInt
nextInt:
beqz $v1, endMain #test v1 to see if we could read a digit
move $a0, $v0
li $v0, 1 #print out Int
syscall
li $v0, 11 #prints out a space
li $a0, 32 #Ascii char 32
syscall
jal getInt
b nextInt
endMain:
li $v0, 10
syscall
#
# Get an integer from the input file buffer.
# This is the aToi procedure from lab 6.
#
getInt:
move $t9, $0 # $t9 is used as a flag if we can at least read 1 digit
#la $t2, buffer #pointer to base of someNum string
lb $t3, zero #Loads t3 with the character zero
move $t6, $0 #clear out register
lb $t1, ($t2) #get first char of string
lb $t7, nine
skipLead:
beqz $t1, theEnd #detects a char 0 and exits.
bgt $t1, $t7, nextChar #if char is not a digit
blt $t1, $t3, nextChar #skip an read next char
b endLead #we found a digit
nextChar:
add $t2,$t2,1 #inc pointer into i/p string
lb $t1, ($t2) #read the char
b skipLead #restart loop
endLead:
loop:
li $t9, 1 # ************** Here is the flag we set if we read at least 1 digit
sub $t4, $t1, $t3 #convert that char to a number by subtracting char zero from it.
add $t2, $t2, 1 #increment pointer into i/p string
mul $t6, $t6, 10 #convert to integer 10xvalue + last_digit
add $t6, $t6, $t4
lb $t1, ($t2) #get next char
bgt $t1, $t7, exit #only stay in the loop if next char
blt $t1, $t3, exit #is a digit
b loop #do it again
exit:
theEnd:
move $v0, $t6 #move integer to return register v0
move $v1, $t9 #move Flag to return register v1
jr $ra
#
# Procedure will open a file and return the file Handle
#
openfile:
#Open a file for read only
la $a0, fileName #name of file to open
li $a1, 0 #read only
li $a2, 0 #mode is ignored
li $v0, 13
syscall
move $s1, $v0
#Test if the file was open
bgez $v0, skiperror
la $a0, error1
li $v0, 4
syscall
skiperror:
move $v0,$s1
jr $ra
This is what needs to be done:
The issue im having is that it is not reading the values after the decimal, So if someone can help me with making it read the numbers after the decimals please
Part D Using Lab 7 as a starting point, create the function aTof which will parse a buffer. A parse will find a floating point number. Your program is to print these floats out to the screen. Copy the following between the> to a text file, and use this as input. 21.45 blah blah blah 43.0003 61 and 0.03 to a text file, and use this as input. 21.45 blah blah blah 43.0003 61 and 0.03Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started