.data sentence: .ascii "Become a Programmer\0" # The string to search in match: .ascii "bpera\0" # The string containing characters to search for in sentence out: .space 4, 0 # Space to store the match count .text .align 2 .globl _start _start: la t0, sentence # Load the address of the sentence string into t0 la a0, match # Load the address of the match string into a0 la s2, out # Load the address of the out variable (match counter) into s2 lbu s3, 0(s2) # Load the current match counter from out into s3 check_match: lbu t1, 0(a0) # Load the current character from match into t1 beq t1, zero, done # If we reach the end of match (t1 == 0), finish the program # Search for the current character from match in sentence la t0, sentence # Reload the address of the sentence string j find_in_sentence # Jump to search for the current character in sentence find_in_sentence: lbu t2, 0(t0) # Load the current character from sentence into t2 beq t2, zero, next_match # If we reach the end of sentence (t2 == 0), move to next character in match # If the characters match, increment the match counter bne t1, t2, not_found # If characters do not match, continue searching addi s3, s3, 1 # If characters match, increment the match counter sb s3, 0(s2) # Store the updated match counter back to out not_found: addi t0, t0, 1 # Move to the next character in sentence j find_in_sentence # Repeat the search next_match: addi a0, a0, 1 # Move to the next character in match j check_match # Continue checking for the next character in match done: ebreak # End the program