Question
This is using MARS (MIPS Simulator) I have to create a simulator that takes a random number and the user has to guess it. I
This is using MARS (MIPS Simulator)
I have to create a simulator that takes a random number and the user has to guess it. I have this code thus far but I don't know how to implicate a limited number of guesses (5 guesses limit) and display the prompt that the user was not able to guess the number. I am able to get the code to work for successes but not failures. HELP! This is my current code thus far and an example of what the output should be below the code.
.data strCold: .asciiz "You're cold. " strWarm: .asciiz "You're warm. " strEnter: .asciiz "Enter a number between 0 and 99: " strHigh: .asciiz "Your guess is too high. " strLow: .asciiz "Your guess is too low. " strLose: .asciiz "You lose. The number was: " strWin: .asciiz "Congratulations! You win!" .text .globl main main: li a1, 100 li v0, 42 #random syscall move t0,a0
loop: li v0, 4 la a0, strEnter #it will print prompt strEnter syscall
li v0, 5 syscall #ask user input move t1, v0 blt v0,t0, tooSmall bgt v0,t0,tooBig beq v0,t0,Found
tooSmall: li v0,4 la a0, strLow #it will print prompt strLow syscall j checkHowClose
tooBig: li v0,4 la a0, strHigh #it will print prompt strHigh syscall j checkHowClose
checkHowClose: sub t1, t1, t0 bgez t1, positive mul t1, t1, -1
positive: ble t1, 10, warm li v0, 4 la a0, strCold syscall j loop
warm: li v0, 4 la a0, strWarm syscall j loop
Found: li v0, 4 la a0, strWin #it will print prompt strWin syscall
Output:
Enter a number between 0 and 99: 50 Your guess is too high. You're cold. Enter a number between 0 and 99: 25 Your guess is too high. You're cold. Enter a number between 0 and 99: 12 Your guess is too high. You're warm! Enter a number between 0 and 99: 8 Your guess is too low. You're warm! Enter a number between 0 and 99: 10 Your guess is too low. You're warm! You lose. The number was: 11 -- program is finished running --
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started