#Application 14 .text 0x00400000 #Code section #Display the message "String:" li $v0,4 #Load the function number la $a0,read_string #Load the message starting address syscall #Function call #Read string (keyboard) li $v0,8 #Load the function number la $a0,string #Load the starting address #for storing the string li $a1,8 #Set string length syscall #Function call li $t1,0 #Counter for reading #the string from memory again: lb $t2,string($t1) #Load symbol (byte) #from address string+$t1 sub $t2,$t2,97 #Convert ASCII to deviation lb $t3,stats($t2) #Load current occurrence #frequency counter add $t3,$t3,1 #Update counter sb $t3,stats($t2) #Store counter in the same address add $t1,$t1,1 #Update loop counter ble $t1,7,again #While the whole string has not been #read, go to again #Display statistics (histogram) #New line li $v0,4 #Load the function number la $a0,line #Load the message starting address syscall #function call li $t1,0 #Counter for occurrence #frequency array again2: lb $t2,stats($t1) #Load counter in stats+$t1 beqz $t2,stats0 #If the counter is zero, go to #stats0 (display “-“) again3: #Display asterisks if the #counter is not zero li $v0,4 #Load the function number la $a0,star #Load the message starting address syscall #Function call add $t2,$t2,-1 #Update asterisks counter bgtz $t2,again3 #While the counter in not zero, #go to again3 syn: #New line li $v0,4 #Load the function number la $a0,line #Load the message starting address syscall #Function call add $t1,$t1,1 #Update counter ble $t1,7,again2 #While the array end is not reached #Program termination li $v0,10 #Load the function number syscall #Function call #Display “-“ for a non-existing #symbol in the string stats0: li $v0,4 #Load the function number la $a0,tip #Load the message starting address syscall #Function call j syn #Return to main loop .data #Data section read_string: .asciiz "String:" star: .asciiz "*" string: .space 8 #Reserve string area stats: .space 8 #Occurrence frequency array line: .asciiz "\n" msg: .asciiz "\nstats=" tip: .asciiz "\n-"