Write in MIPS, a program from an input file (asking the user for filename, and...
50.1K
Verified Solution
Question
Accounting
Write in MIPS, a program from an input file (asking the user for filename, and then reading the file and counting how many upper case letters, lower case letters, number symbols, other symbols, lines of text, and signed numbers?
Testing.txt is a file to upload in it, it have the following
It have to be able to read files that are large,
---------------------------------------------------------
and the garden diminishes: cucumber leaves rumpled
and rusty, zucchini felled by borers, tomatoes sparse
on the vines. But out in the perennial beds, theres one last
blast of color: ignitions of goldenrod, flamboyant
asters, spiraling mums, all those flashy spikes waving
in the wind, conducting summers final notes.
The ornamental grasses have gone to seed, haloed
in the last light. Nights grow chilly, but the days
are still warm; I wear the sun like a shawl on my neck
and arms. Hundreds of blackbirds ribbon in, settle
in the trees, so many black leaves, then, just as suddenly,
theyre gone. This is autumns great Departure Gate,
and everyone, boarding passes in hand, waits
patiently in a long, long line.
-251,+212,+80,129
-102,-173,207,+11,-115
-231,-125,-251,-99,+145
+57,198,-140,15,-45
+123,-185,-104,-236,-247
98,+174,-217,-218,+178
+113,-212,-135,-10
---------------------------------------------------------
Now the following MIPS code is what I have been working on. I have been having trouble implementing asking the user for filename, and having it read. Also having trouble separating upper case letters, and lower case letters, lines of text, and signed numbers (+ - * /) separated from symbols?
---------------------------------------------------------
.data
fin: .asciiz "testing.txt" # filename for input
buffer: .space 1024
line: .space 126
counts: .word 0:4 #an array of 4 counter values, 0th for letters , 1st for digits, 2nd for space and 3rd for special
spaceInfo: .asciiz " The number of spaces in the string is: "
letterInfo: .asciiz " The number of letters in the string is: "
digitInfo: .asciiz " The number of digits in the string is: "
specialInfo: .asciiz " The number of special chars in the string is: "
.text
#open a file for writing
li $v0, 13 # system call for open file
la $a0, fin # board file name
li $a1, 0 # Open for reading
li $a2, 0
syscall # open a file (file descriptor returned in $v0)
move $s6, $v0 # save the file descriptor
main:
#prompt the user
la $a0, prompt
li $v0, 4
syscall
#get user input
la $a0, line
li $a1, 126
li $v0, 8
syscall
la $t1, line
li $t3, 0 #counter for no. of chars
process:
lb $t0, ($t1)
add $t1, $t1, 1 #next location
beq $t0, '\0' end_process
beq $t0, ' ', end_process
add $t3, $t3, 1 #increment counter for total no. of chars
bge $t0, 'a', lower
bge $t0, 'A', upper
bge $t0, '0', digits
beq $t0, ' ', spacy
b process
lower:
bgt $t0, 'z', process
lw $t2, counts+0
addi $t2, $t2, 1
sw $t2, counts+0
b process
upper:
bgt $t0, 'Z', process
lw $t2, counts+0
addi $t2, $t2, 1
sw $t2, counts+0
b process
digits:
bgt $t0, '9', process
lw $t2, counts+4
addi $t2, $t2, 1
sw $t2, counts+4
b process
spacy:
lw $t2, counts+8
addi $t2, $t2, 1
sw $t2, counts+8
b process
end_process:
#calculate number of special chars as totalchars - (no. of letters + no. of digits + no. of spaces)
#first calculate (no. of letters + no. of digits + no. of spaces)
li $t4, 0
lw $t5, counts+0
add $t4, $t4, $t5
lw $t5, counts+4
add $t4, $t4, $t5
lw $t5, counts+8
add $t4, $t4, $t5
#now calculate no. of special chars
sub $t3, $t3, $t4
sw $t3, counts+12 #store as the 4th array element
#display the results
#display no. of letters
li $v0, 4
la $a0, letterInfo
syscall
li $v0, 1
lw $a0, counts+0
syscall
#display no. of digits
li $v0, 4
la $a0, digitInfo
syscall
li $v0, 1
lw $a0, counts+4
syscall
#display no. of spaces
li $v0, 4
la $a0, spaceInfo
syscall
li $v0, 1
lw $a0, counts+8
syscall
#display no. of special
li $v0, 4
la $a0, specialInfo
syscall
li $v0, 1
lw $a0, counts+12
syscall
#exit
li $v0, 10
syscall
#read from file
li $v0, 14 # system call for read from file
move $a0, $s6 # file descriptor
la $a1, buffer # address of buffer to which to read
li $a2, 1024 # hardcoded buffer length
syscall # read from file
# Close the file
li $v0, 16 # system call for close file
move $a0, $s6 # file descriptor to close
syscall # close file
---------------------------------------------------------
Get Answers to Unlimited Questions
Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!
Membership Benefits:
- Unlimited Question Access with detailed Answers
- Zin AI - 3 Million Words
- 10 Dall-E 3 Images
- 20 Plot Generations
- Conversation with Dialogue Memory
- No Ads, Ever!
- Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Other questions asked by students
StudyZin's Question Purchase
1 Answer
$0.99
(Save $1 )
One time Pay
- No Ads
- Answer to 1 Question
- Get free Zin AI - 50 Thousand Words per Month
Unlimited
$4.99*
(Save $5 )
Billed Monthly
- No Ads
- Answers to Unlimited Questions
- Get free Zin AI - 3 Million Words per Month
*First month only
Free
$0
- Get this answer for free!
- Sign up now to unlock the answer instantly
You can see the logs in the Dashboard.