Hey everyone,

I am trying to create a random number generator with MIPS assembly. I have most of the code written, I just need to change my set number for a guessing game to a random number. I also want to ask the user if they'd like to play again. The formula I am using is r=(r*3+1)%10. User must enter a seed. How do I write this?

Here is my code:

``````.data

guessString: .asciiz "\nGuess a number: "
tooHigh: .asciiz "Your guess is too high. Guess lower."
tooLow: .asciiz "Your guess is too low. Guess higher."
correctGuess: .asciiz "Your guess is correct!"
outOfGuesses: .asciiz "Out of guesses!"
guessesRemaining: .asciiz "\nNumber of guesses remaining: "
instructions: .asciiz "Welcome. You have 10 tries to guess\n the correct number between 1 - 1000."
quit: .asciiz "To quit enter 0."

.text
main:

la \$a0, instructions
li \$v0, 4
syscall

# Sets number, counter, low and high limit

li \$t9, 749
li \$t8, 10

li \$t6, 0
li \$t7, 1001

# Loopy Loop

loop:

# Guess counter

li \$v0, 4
la \$a0, guessesRemaining
syscall

# Moves guessesRemaining to a temporary folder

move \$a0, \$t8
li \$v0, 1
syscall

# Guess a number

li \$v0, 4
la \$a0, guessString
syscall

li \$v0, 5
syscall

move \$s0, \$v0

# Player chooses to exit

ble \$s0, \$t6, quitGame
bge \$s0, \$t7, quitGame

# Player won

beq \$s0, \$t9, win

# Counter if wrong or branch to zero

sub \$t8, \$t8, 1
beqz \$t8, loss

# Guess too high

bgt \$s0, \$t9, guessTooHigh

# Guess too low

blt \$s0, \$t9, guessTooLow

# Tags for win, loss if equal to 0, guess too high/too low

win:

li \$v0, 4
la \$a0, correctGuess
syscall

li \$v0, 10
syscall

loss:

li \$v0, 4
la \$a0, outOfGuesses
syscall

li \$v0, 10
syscall

guessTooHigh:

li \$v0, 4
la \$a0, tooHigh
syscall

b loop

guessTooLow:

li \$v0, 4
la \$a0, tooLow
syscall

b loop

quitGame:

li \$v0, 4
la \$a0, quit
syscall

li \$v0, 10
syscall``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.