The guess loop keeping displaying "Wrong guess" message when the user guesses the correct letter. This is a code for Hangman game
.data RAND1: .asciiz "love" RAND2: .asciiz "hate" RAND3: .asciiz "kiss" RAND4: .asciiz "nah" RAND5: .asciiz "however" RAND6: .asciiz "never" RAND7: .asciiz "live" RAND8: .asciiz "hummingbird" RAND9: .asciiz "hahaha" RAND10: .asciiz "bootleg" RAND11: .asciiz "waiting" RAND12: .asciiz "yellow" STORE: .space 12 WIN: .asciiz "Congratulations!" LOSE: .asciiz "You lost. =(" WRONG: .asciiz "Nope. Guesses remaining: " GOOD: .asciiz "Good! \n" GUESS: .asciiz "Guess! \n" NEWLINE: .asciiz "\n"

.text

main:
jal rand # returns the address of the word in $v0 and the length in $v1

move $a0, $v0
jal print

li $v0, 10  # code for exit
syscall 
rand:
li $a1, 11 # max random number is 11 li $v0, 42 # random number syscall

add $a0, $a0, 1 # adds 1 to random number (to get ride of zero case)
twelve: bne $a0, 12, eleven la $a0, RAND12 # loads address of RAND12 into $a0 j end eleven: bne $a0, 11, ten la $a0, RAND11 # loads address of RAND11 into $a0 j end ten: bne $a0, 10, nine la $a0, RAND10 # loads address of RAND10 into $a0 j end nine: bne $a0, 9, eight la $a0, RAND9 # loads address of RAND9 into $a0 j end eight: bne $a0, 8, seven la $a0, RAND8 # loads address of RAND8 into $a0 j end seven: bne $a0, 7, six la $a0, RAND7 # loads address of RAND7 into $a0 j end six: bne $a0, 6, five la $a0, RAND6 # loads address of RAND6 into $a0 j end five: bne $a0, 5, four la $a0, RAND5 # loads address of RAND5 into $a0 j end four: bne $a0, 4, three la $a0, RAND4 # loads address of RAND4 into $a0 j end three: bne $a0, 3, two la $a0, RAND3 # loads address of RAND3 into $a0 j end two: bne $a0, 2, one la $a0, RAND2 # loads address of RAND1 into $a0 j end one:
la $a0, RAND1 # loads address of RAND1 into $a0 j end

end:
sub $sp, $sp, 4 sw $ra, ($sp) jal counter lw $ra, ($sp) add $sp, $sp, 4 add $v1, $v0, $0 # length of string in $v1

la $v0, ($a0)       # loads string address into $v0 for returning
jr $ra          # returns to main
counter: la $t0, ($a0) # loads the address of word into $t0 add $t1, $0, $0 # initializes $t1 to zero

count_loop: lb $t2, 0($t0) # loads next letter into $t2 beq $t2, $zero, end_loop # checks if the letter is zero (null identifier at the end of the string) addiu $t0, $t0, 1 # if there is a letter there, adds one to the count addiu $t1, $t1, 1 # moves the temporary adress forward one byte b count_loop # branches back to check next byte end_loop: add $v0, $t1, 0 # moves count into $v0 jr $ra # returns to caller

print: la $a3, ($a0) # $a1 stores address of word la $a2, ($a0) # $a2 will be the word of blanks move $t6, $v1 # $t6 will now be the number of characters in the word move $t0, $t6 # copies numChars in preparation for blanker add $t0, $t0, -1 li $t9, 5 # $t9 = number of guesses remaining li $t7, 10 # new line character li $t4, 0 # boolean for checking li $t3, 95 # loads an underscore character for use in blanker la $t2, STORE

blanker: lb $t8, 0($a2) # copies the word sb $t8, 0($t2) # stores it sb $t3, 0($a2) # replaces the character with a blank addi $t2, $t2, 1 addi $a2, $a2, 1 addi $t0, $t0, -1 bltz $t0, reset1 # once done blanking, reset $a2 designation to the start, then start guess loop j blanker

guess: la $a0, ($a2) # print blanked word li $v0, 4 syscall la $a0, NEWLINE li $v0, 4 syscall la $a0, GUESS # print guess prompt syscall li $v0, 8 # get guess from player syscall move $t5, $a0 # $t5 = guess lb $t0, 1($t5) bne $t0, $t7, guess_word # if the input is more than a single character, it's a word guess li $t2, 0 # setup a counter for the guess_check j guess_check

guess_check: la $t8, STORE lb $t0, 0($t8) # $t0 = checked character of the word addi $t2, $t2, 1 # counter++ addi $a3, $a3, 1 addi $t8, $t8, 1 beq $t5, $t0, unblank bge $t2, $t6, checkdone # guess is done j guess_check

checkdone: mul $t6, $t6, -1 add $a3, $a3, $t6 # reset the address designation mul $t6, $t6, -1 bnez $t4, guess_good j guess_bad

unblank: sb $t0, 0($a2) # store in the same position in $a2 (unblanks the character slot) li $t4, 1 # boolean $t4, if $t4 = 1, then guess_good in checkdone bge $t2, $t6, checkdone # guess is done j guess_check

guess_word: beq $a0, $a1, win # if the two words are the same, then win j guess_bad

guess_good: la $a0, GOOD # print good guess statement li $t4, 0 li $v0, 4 syscall # now check to see if there are blanks remaining move $t0, $t6 # copy counter again j win_check

win_check: lb $t1, 0($a2) add $a2, $a2, 1 beq $t3, $t1, blank_found # found a blank, not won yet addi $t0, $t0, -1 bltz $t0, win # no blanks found, win

blank_found: add $a2, $a2, 1 # finish the loop to reset the address addi $t0, $t0, -1 bltz $t0, reset2 # go back to guessing j blank_found

guess_bad: addi $t9, $t9, -1 blez $t9, lose # if guesses are gone, lose game la $a0, WRONG li $v0, 4 syscall # print WRONG statement move $a0, $t9 li $v0, 1 syscall # print number of guesses remaining la $a0, NEWLINE li $v0, 4 syscall j guess

reset1: li $t0, 0 sb $t0, 0($a2) mul $t6, $t6, -1 add $a2, $a2, $t6 # reset the address designation mul $t6, $t6, -1 j guess # return to guessing

reset2: mul $t6, $t6, -1 add $a2, $a2, $t6 # reset the address designation mul $t6, $t6, -1 j guess # return to guessing

win: la $a0, WIN li $v0, 4 syscall li $v0, 10 syscall

lose: la $a0, LOSE li $v0, 4 syscall li $v0, 10 syscall
The guess loop keeping displaying "Wrong guess" message when the user guesses the correct letter. This is a code for Hangman game
===

.data RAND1: .asciiz "love" RAND2: .asciiz "hate" RAND3: .asciiz "kiss" RAND4: .asciiz "nah" RAND5: .asciiz "however" RAND6: .asciiz "never" RAND7: .asciiz "live" RAND8: .asciiz "hummingbird" RAND9: .asciiz "hahaha" RAND10: .asciiz "bootleg" RAND11: .asciiz "waiting" RAND12: .asciiz "yellow" STORE: .space 12 WIN: .asciiz "Congratulations!" LOSE: .asciiz "You lost. =(" WRONG: .asciiz "Nope. Guesses remaining: " GOOD: .asciiz "Good! \n" GUESS: .asciiz "Guess! \n" NEWLINE: .asciiz "\n"

.text

main:
jal rand # returns the address of the word in $v0 and the length in $v1

move $a0, $v0
jal print

li $v0, 10  # code for exit
syscall 
rand:
li $a1, 11 # max random number is 11 li $v0, 42 # random number syscall

add $a0, $a0, 1 # adds 1 to random number (to get ride of zero case)
twelve: bne $a0, 12, eleven la $a0, RAND12 # loads address of RAND12 into $a0 j end eleven: bne $a0, 11, ten la $a0, RAND11 # loads address of RAND11 into $a0 j end ten: bne $a0, 10, nine la $a0, RAND10 # loads address of RAND10 into $a0 j end nine: bne $a0, 9, eight la $a0, RAND9 # loads address of RAND9 into $a0 j end eight: bne $a0, 8, seven la $a0, RAND8 # loads address of RAND8 into $a0 j end seven: bne $a0, 7, six la $a0, RAND7 # loads address of RAND7 into $a0 j end six: bne $a0, 6, five la $a0, RAND6 # loads address of RAND6 into $a0 j end five: bne $a0, 5, four la $a0, RAND5 # loads address of RAND5 into $a0 j end four: bne $a0, 4, three la $a0, RAND4 # loads address of RAND4 into $a0 j end three: bne $a0, 3, two la $a0, RAND3 # loads address of RAND3 into $a0 j end two: bne $a0, 2, one la $a0, RAND2 # loads address of RAND1 into $a0 j end one:
la $a0, RAND1 # loads address of RAND1 into $a0 j end

end:
sub $sp, $sp, 4 sw $ra, ($sp) jal counter lw $ra, ($sp) add $sp, $sp, 4 add $v1, $v0, $0 # length of string in $v1

la $v0, ($a0)       # loads string address into $v0 for returning
jr $ra          # returns to main
counter: la $t0, ($a0) # loads the address of word into $t0 add $t1, $0, $0 # initializes $t1 to zero

count_loop: lb $t2, 0($t0) # loads next letter into $t2 beq $t2, $zero, end_loop # checks if the letter is zero (null identifier at the end of the string) addiu $t0, $t0, 1 # if there is a letter there, adds one to the count addiu $t1, $t1, 1 # moves the temporary adress forward one byte b count_loop # branches back to check next byte end_loop: add $v0, $t1, 0 # moves count into $v0 jr $ra # returns to caller

print: la $a3, ($a0) # $a1 stores address of word la $a2, ($a0) # $a2 will be the word of blanks move $t6, $v1 # $t6 will now be the number of characters in the word move $t0, $t6 # copies numChars in preparation for blanker add $t0, $t0, -1 li $t9, 5 # $t9 = number of guesses remaining li $t7, 10 # new line character li $t4, 0 # boolean for checking li $t3, 95 # loads an underscore character for use in blanker la $t2, STORE

blanker: lb $t8, 0($a2) # copies the word sb $t8, 0($t2) # stores it sb $t3, 0($a2) # replaces the character with a blank addi $t2, $t2, 1 addi $a2, $a2, 1 addi $t0, $t0, -1 bltz $t0, reset1 # once done blanking, reset $a2 designation to the start, then start guess loop j blanker

guess: la $a0, ($a2) # print blanked word li $v0, 4 syscall la $a0, NEWLINE li $v0, 4 syscall la $a0, GUESS # print guess prompt syscall li $v0, 8 # get guess from player syscall move $t5, $a0 # $t5 = guess lb $t0, 1($t5) bne $t0, $t7, guess_word # if the input is more than a single character, it's a word guess li $t2, 0 # setup a counter for the guess_check j guess_check

guess_check: la $t8, STORE lb $t0, 0($t8) # $t0 = checked character of the word addi $t2, $t2, 1 # counter++ addi $a3, $a3, 1 addi $t8, $t8, 1 beq $t5, $t0, unblank bge $t2, $t6, checkdone # guess is done j guess_check

checkdone: mul $t6, $t6, -1 add $a3, $a3, $t6 # reset the address designation mul $t6, $t6, -1 bnez $t4, guess_good j guess_bad

unblank: sb $t0, 0($a2) # store in the same position in $a2 (unblanks the character slot) li $t4, 1 # boolean $t4, if $t4 = 1, then guess_good in checkdone bge $t2, $t6, checkdone # guess is done j guess_check

guess_word: beq $a0, $a1, win # if the two words are the same, then win j guess_bad

guess_good: la $a0, GOOD # print good guess statement li $t4, 0 li $v0, 4 syscall # now check to see if there are blanks remaining move $t0, $t6 # copy counter again j win_check

win_check: lb $t1, 0($a2) add $a2, $a2, 1 beq $t3, $t1, blank_found # found a blank, not won yet addi $t0, $t0, -1 bltz $t0, win # no blanks found, win

blank_found: add $a2, $a2, 1 # finish the loop to reset the address addi $t0, $t0, -1 bltz $t0, reset2 # go back to guessing j blank_found

guess_bad: addi $t9, $t9, -1 blez $t9, lose # if guesses are gone, lose game la $a0, WRONG li $v0, 4 syscall # print WRONG statement move $a0, $t9 li $v0, 1 syscall # print number of guesses remaining la $a0, NEWLINE li $v0, 4 syscall j guess

reset1: li $t0, 0 sb $t0, 0($a2) mul $t6, $t6, -1 add $a2, $a2, $t6 # reset the address designation mul $t6, $t6, -1 j guess # return to guessing

reset2: mul $t6, $t6, -1 add $a2, $a2, $t6 # reset the address designation mul $t6, $t6, -1 j guess # return to guessing

win: la $a0, WIN li $v0, 4 syscall li $v0, 10 syscall

lose: la $a0, LOSE li $v0, 4 syscall li $v0, 10 syscall