data # Guess the Number game in MIPS assembly # Constants STARTING_RANGE: .word 1 # Starting range for random number ENDING_RANGE: .word 100 # Ending range for random number MESSAGE_PROMPT: .asciiz "Guess a number between 1 and 100:" MESSAGE_TOO_HIGH: .asciiz "Too high! Guess again: " MESSAGE_TOO_LOW: .asciiz "Too low! Guess again: " MESSAGE_CORRECT: .asciiz "Congratulations! You guessed the number!" NEWLINE: .asciiz "\n" random_number_prompt: .asciiz "The random number was: " guess_prompt: .asciiz "Your guess was: " .text # Initialize random number generator li $v0, 40 syscall # Generate random number lw $t0, ENDING_RANGE lw $t1, STARTING_RANGE sub $t2, $t0, $t1 addi $t2, $t2, 1 li $v0, 42 move $a0, $t1 move $a1, $t2 syscall move $t0, $v0 # Loop until number is guessed guess_loop: # Prompt user for guess la $a0, MESSAGE_PROMPT li $v0, 4 syscall # Get user input li $v0, 5 syscall move $t1, $v0 # Check if guess is correct beq $t1, $t0, correct_guess # Check if guess is too high bgt $t1, $t0, guess_too_high # Guess must be too low j guess_too_low # Guess is too high guess_too_high: la $a0, MESSAGE_TOO_HIGH li $v0, 4 syscall j guess_loop # Guess is too low guess_too_low: la $a0, MESSAGE_TOO_LOW li $v0, 4 syscall j guess_loop # Correct guess correct_guess: la $a0, MESSAGE_CORRECT li $v0, 4 syscall j exit_program # Exit program exit_program: li $v0, 10 syscall this code is doing this in mips assembly creat a program which is a simple game of "Guess the Number". In this game, the computer generates a random number between 1 and 100, and the player has to guess what that number is. After each guess, the computer tells the player whether their guess was too high, too low, or correct. The game ends when the player correctly guesses the number. But my code is not generating random numbers. it is keep giving me fixed output which is 42. every time i play the game getting same number. please fix it. here is my output Too low! Guess again: Guess a number between 1 and 100:34 Too low! Guess again: Guess a number between 1 and 100:54 Too high! Guess again: Guess a number between 1 and 100:43 Too high! Guess again: Guess a number between 1 and 100:42 Congratulations! You guessed the number! -- program is finished running --

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 10PP
icon
Related questions
Question

data
# Guess the Number game in MIPS assembly

# Constants
STARTING_RANGE: .word 1 # Starting range for random number
ENDING_RANGE: .word 100 # Ending range for random number
MESSAGE_PROMPT: .asciiz "Guess a number between 1 and 100:"
MESSAGE_TOO_HIGH: .asciiz "Too high! Guess again: "
MESSAGE_TOO_LOW: .asciiz "Too low! Guess again: "
MESSAGE_CORRECT: .asciiz "Congratulations! You guessed the number!"
NEWLINE: .asciiz "\n"
random_number_prompt: .asciiz "The random number was: "
guess_prompt: .asciiz "Your guess was: "
.text
# Initialize random number generator
li $v0, 40
syscall

# Generate random number
lw $t0, ENDING_RANGE
lw $t1, STARTING_RANGE
sub $t2, $t0, $t1
addi $t2, $t2, 1
li $v0, 42
move $a0, $t1
move $a1, $t2
syscall
move $t0, $v0

# Loop until number is guessed
guess_loop:
# Prompt user for guess
la $a0, MESSAGE_PROMPT
li $v0, 4
syscall

# Get user input
li $v0, 5
syscall
move $t1, $v0

# Check if guess is correct
beq $t1, $t0, correct_guess

# Check if guess is too high
bgt $t1, $t0, guess_too_high

# Guess must be too low
j guess_too_low

# Guess is too high
guess_too_high:
la $a0, MESSAGE_TOO_HIGH
li $v0, 4
syscall
j guess_loop

# Guess is too low
guess_too_low:
la $a0, MESSAGE_TOO_LOW
li $v0, 4
syscall
j guess_loop

# Correct guess
correct_guess:
la $a0, MESSAGE_CORRECT
li $v0, 4
syscall
j exit_program

# Exit program
exit_program:
li $v0, 10
syscall
this code is doing this

in mips assembly creat a program which is a simple game of "Guess the Number". In this game, the computer generates a random number between 1 and 100, and the player has to guess what that number is. After each guess, the computer tells the player whether their guess was too high, too low, or correct. The game ends when the player correctly guesses the number.

But my code is not generating random numbers. it is keep giving me fixed output which is 42. every time i play the game getting same number. please fix it.

here is my output




Too low! Guess again: Guess a number between 1 and 100:34
Too low! Guess again: Guess a number between 1 and 100:54
Too high! Guess again: Guess a number between 1 and 100:43
Too high! Guess again: Guess a number between 1 and 100:42
Congratulations! You guessed the number!
-- program is finished running -- 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage