homework3.asm - #homework 3#Madison Flowers#read the...

This preview shows page 1 - 3 out of 5 pages.

#homework 3 #Madison Flowers #read the file "input.txt" into a buffer in memory #extract the string "numbers" and convert them to integers #store these in an array and then print the integers to console #sort the integers in place using selection sort #print the sorted integers to console #calculate the mean, median, and the standard deviation, then print the results .data prompt: .asciiz "Enter input text filename: " inputfile : .asciiz "input.txt" beforearray: .asciiz "The array before: " arrayafter: .asciiz "The array after: " mean: .asciiz "the mean is: " median: .asciiz "The median is: " standarddev: .asciiz "The standard deviation is: " newline : .asciiz "\n" space : .asciiz " " buffer: .space 80 intarray: .word 20 .text main: # set file name and address to readfile (read file) la $a0,inputfile la $a1, buffer jal readfile # call procedure readfile beq $v0,$0,exit # extract the integers from text and store in array la $a0, intarray li $a1, 20 la $a2, buffer jal extract # call procedure extract move $t7,$v0 # $t7 is number of integers extracted li $v0,4 la $a0, beforearray syscall # print the original integer array la $a0,intarray move $a1,$t7 jal print # call procedure print # sort the integer array la $a0,intarray move $a1,$t7 jal sort # call procedure to sort # print the sorted integer array li $v0,4 la $a0,arrayafter syscall la $a0,intarray move $a1,$t7 jal print # call the procedure print # calculate and print mean la $a0, mean li $v0,4 syscall la $a0,intarray move $a1,$t7 jal calcmean li $v0,2 # print mean syscall la $a0,newline li $v0,4
syscall la $a0,median li $v0,4 syscall # calculate and print median la $a0,intarray move $a1,$t7 jal calcmedian

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture