Write a MIPS program in MARS to \"guess a number\". Specification Create a varia
ID: 3668018 • Letter: W
Question
Write a MIPS program in MARS to "guess a number".
Specification
Create a variable called numToGuess and set it equal to your number to guess.
Pass a number entered from the keyboard to a procedure that prints one of the following messages:
If the number from the keyboard equals the number to guess, print a "good guess" message.
If the number from the keyboard is smaller than the number to guess, print a "too low" message.
If the number from the keyboard is greater than the number to guess, print a "too hi" message.
and returns 1 for a "good guess" or 0 for a "too low" or "too hi" guess.Allow no more than 5 guesses.
If the number is guessed correctly before the 5th guess, print a congratulatory message and exit the program.
If the number is not guessed correctly in five guesses, print a "you had your five guesses" message and exit the program.
Explanation / Answer
data
numToGuess: .word 575
int_value: .word 1
guessesAllowed: .word 5
guessString: .asciiz "Guess a number: "
.text
main:
# Print question text
li $v0, 4
la $a0, guessString
syscall
# Read guess
li $v0, 5
syscall
sw $v0, int_value
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.