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 --

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education