.data
input_string: .space 256 # Space to store input string
counts: .space 8 # Space to store counts for each letter
prompt: .asciiz “Enter a sentence: ”
output_format: .asciiz “%c: %dn”
.text
.globl main
main:
# Print prompt
li $v0, 4
la $a0, prompt
syscall
# Read input string
li $v0, 8
la $a0, input_string
li $a1, 256
syscall
# Initialize counts to 0
li $t0, 0 # ‘K’ count
li $t1, 0 # ‘N’ count
li $t2, 0 # ‘I’ count
li $t3, 0 # ‘G’ count
li $t4, 0 # ‘H’ count
li $t5, 0 # ‘T’ count
li $t6, 0 # ‘R’ count
li $t7, 0 # ‘O’ count
# Loop through the input string
la $t8, input_string # Pointer to input string
li $t9, 0 # Loop counter
loop:
lb $t8, ($t8) # Load byte from input string
beqz $t8, endloop # If end of string, exit loop
# Convert character to uppercase
li $t9, 32 # ‘a’ – ‘A’
addu $t8, $t8, $t9 # Convert to uppercase
# Check if it’s one of the specified letters
li $t9, ‘K’
beq $t8, $t9, update_K_count
li $t9, ‘N’
beq $t8, $t9, update_N_count
li $t9, ‘I’
beq $t8, $t9, update_I_count
li $t9, ‘G’
beq $t8, $t9, update_G_count
li $t9, ‘H’
beq $t8, $t9, update_H_count
li $t9, ‘T’
beq $t8, $t9, update_T_count
li $t9, ‘R’
beq $t8, $t9, update_R_count
li $t9, ‘O’
beq $t8, $t9, update_O_count
# Continue looping if not one of the specified letters
j next_iteration
update_K_count:
addi $t0, $t0, 1
j next_iteration
update_N_count:
addi $t1, $t1, 1
j next_iteration
update_I_count:
addi $t2, $t2, 1
j next_iteration
update_G_count:
addi $t3, $t3, 1
j next_iteration
update_H_count:
addi $t4, $t4, 1
j next_iteration
update_T_count:
addi $t5, $t5, 1
j next_iteration
update_R_count:
addi $t6, $t6, 1
j next_iteration
update_O_count:
addi $t7, $t7, 1
j next_iteration
next_iteration:
addi $t8, $t8, 1 # Move to next character in input string
j loop
endloop:
# Output the counts
li $t9, ‘K’
li $v0, 11
move $a0, $t9
syscall
li $v0, 1
move $a0, $t0
syscall
li $v0, 4
la $a0, output_format
syscall
# Repeat the same for other letters…
# Exit
li $v0, 10
syscall
Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount