Question: Mips assembly language. I'm trying to read from a file and count how many lines there are in the file based on the next line

Mips assembly language. I'm trying to read from a file and count how many lines there are in the file based on the next line characters. Here is my MIPS code:

.data

testOutput: .word 0

fin: .asciiz "data.txt"

.align 2

fout: .asciiz "Billing.txt"

buffer: .space 20

line: .space 50

.text

#open input file

li $v0, 13

la $a0, fin

li $a1, 0

li $a2, 0

syscall

move $s6, $v0

#read from file

li $v0, 14

move $a0, $s6

la $a1, buffer

li $a2, 14

syscall

la $s0, buffer

addi $s2, $s0, 0

addi $s3, $s0, 0

jal loop

sw $v0, testOutput

#print output

li $v0,1

move $a0,$v0

syscall

li $v0, 10

syscall

loop:

la $s1, 0($0)

bnez $s1, exit

addi $s0, $s0, 1

addi $s2, $s2, 1

beq $s1, ' ', update

update:

addi $v0, $s3, 1

jr $ra

j loop

exit:

li $v0, 10

syscall

The sample for data.txt as follow:

B12345 16 04 R44212 00 03 B22314 12 05 R23341 00 02 B84772 08 01 B74682 05 02 R87864 00 04 R74621 00 11 B33123 10 07 B53622 07 04 R49124 00 08 B78747 15 05 R67232 00 14 R23427 00 04 B37834 07 12

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!