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

In MIPS code and should be able to run on MARS 4.5, create a program that finds

ID: 3911604 • Letter: I

Question

In MIPS code and should be able to run on MARS 4.5, create a program that finds the number of times the letters K, N, I, G, H, T, and S are used in a sentence that the user inputs.

Sample Input by user:

Hello, the cat jumped over the kitten and walked down the road to grab some food. The dog ran across the feild and fetched the ball. The Gardner mowed the lawn.

Sample Ouput should be in the following format:

K: # of times said

N:# of times said

I:# of times said

G: # of times

H: # of times

T: # of times

S: # of times

Explanation / Answer

.data

command1: .asciiz "Please enter a sentence "
sentence: .space 100
command2: .asciiz "k"
command3: .asciiz " times."

command4: .asciiz "N"

command5: .asciiz " times. "

command6: .asciiz "I"
command7: .asciiz " times. "

command8: .asciiz "G"
command9: .asciiz " times. "

command10: .asciiz "H"
command11: .asciiz " times. "

command12: .asciiz "T"
command13: .asciiz " times. "

command14: .asciiz "S"
command15: .asciiz " times. "
Sentence: .space 100
my_chars: .space 20
char1: .byte 'K'
char2: .byte 'N'
char3: .byte 'I'
char4: .byte 'G'
char5: .byte 'H'
char6: .byte 'T'
char7: .byte 'S'
.text

.globl main

main:
li $t0, 100 #end var for loop
li $t1, 0 #start var for loop
li $t2, 0 #number of occurences

la $a0, command1 #print 'please enter sentence'
li $v0, 4
syscall

la $s0, character
lb $s1, ($s0)
la $t3, sentence
lb $a2, ($t3) #gets first char of sentence


li $s0,0 #initilaze loop var1
li $t0,20 #initialize loop var2
li $s1,0 #initialize counter
la $t1, my_chars # base address of array
li $a1,20 #max input to be read
li $a0,8
syscall
loop:
beq $s0, $t0, exit
la $t2, str #sentence into t2
lb $v0, 0($t2) #access first index
lb $t9, char1
beq $v0, $t9, then #comparing to K
then:
addi $s1, $s1, 1

lb $t8, char2
beq $v0, $t8, then1 #comparing to N

then1:
addi $s1, $s1, 1
lb $t7, char3
beq $v0, $t7, then2 #comparing to I

then2:
addi $s1, $s1, 1
lb $t6, char4
beq $v0, $t6, then3 #comparing to G

then3:
addi $s1, $s1, 1
lb $t5, char5
beq $v0, $t5, then4 #comparing to H


then4:
addi $s1, $s1, 1
lb $t5, char6
beq $v0, $t5, then5 #comparing to T


then5:
addi $s1, $s1, 1
lb $t5, char7
beq $v0, $t5, then6 #comparing to S

then6:
addi $s1, $s1, 1

loop:
beq $a2, $zero, end #once reach end of char array, prints result
beq $a2, $s1, something #if the char within sentence == comparing char
addi $t3, $t3, 1
lb $a2,($t3)   
j loop

something:   
addi $t2, $t2, 1 #increments number of occurences of char
end:
la $a0, command3
li $v0, 4
syscall

la $a0, character
li $v0, 11
syscall

la $a0, command4
li $v0, 4
syscall

la $a0 sentence
li $v0, 4
syscall

#la $a0, $t2
li $v0, 1
move $a0, $t2
syscall

la $a0, command5
li $v0, 4
syscall

addi $t1, $t1,1 #increment base address
addi $s0, $s0,1 #increment loop variable
j L1
syscall
string

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