Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete MIPS program to read from a text file (each number is on a sepa

ID: 3707872 • Letter: W

Question

Write a complete MIPS program to read from a text file (each number is on a separate line) with at least three positive integers to a maximum of twenty positive integers or until a zero is read in (and this zero is not part of the count of integers read-in) from the file (either you have the twenty integers or somewhere the zero occurs in the file). Now, find and output these items to this file "lastname.txt" from the read-in integers: 1) The maximum integer and its line in the file. 2) The minimum integer and its line in the file. 3) The mean or average of the integers read in. WITHOUT USING AN ARRAY....If you can at least get me started on this it would be much appreciated. Thanks

Explanation / Answer

PROGRAM:

#Define data

.data

#Define space

space: .asciiz " "

#Define array

X: .word 1,2,3,4,5

#Define size

N: .word 5  

#Define text

.text

#Define main

main:

     #Load address

     la $a0, X     

     #Assign count

     lw $a1, N     

     #Assign max

     li $t2, 0

     #Assign min

     li $t3, 100

     #Jump

     jal readArray

     #Exit

     li $v0, 10    

     #System call

     syscall

     #Define method

     readArray:

     #Define counter

     li $t0, 0   

     #Load      

     li $t1, 0             

#Define method

loop:  

     #Compare

     bge $t0, $a1, final   

     #Load value

     lw $a0, X($t1)        

     #Compare

     blt $a0, $t3, new_min

     #Jump

     j check_max

     #Define method

     new_min: move $t3, $a0     

     #Jump

     j update_counter

#Define method

check_max:

     #Compare

     bgt $a0, $t2, new_max

     #Jump

     j update_counter

#Define method

new_max: move $t2, $a0     

#Define method

update_counter:

     #Add values

     addi $t1, $t1, 4      

     #Add values

     addi $t0, $t0, 1      

     #Goto

     b loop           

#Define method

final:

     #Load value

     li $v0, 1

     #Move value

     move $a0, $t2    

     #System call

     syscall          

     #Load

     la $a0, space    

     #Display

     li $v0, 4        

     #System call

     syscall

     #Display

     li $v0, 1

     #Move value

     move $a0, $t3    

     #System call

     syscall          

     #Load space

     la $a0, space

     #Display

     li $v0, 4        

     #System call

     syscall

     #Compute sum

     add $t4, $t2, $t3

     #Compute average

     div $t5, $t4, 2       

     #Display

     li $v0, 1   

     #Move value

     move $a0, $t5    

     #System call

     syscall

     #Jump

     jr $ra           

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote