Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE USE MIPS ASSEMBLY LANGUAGE (I USE MYPSIM) AS MY COMPILER In this problem

ID: 3663589 • Letter: P

Question

PLEASE USE MIPS ASSEMBLY LANGUAGE (I USE MYPSIM) AS MY COMPILER

In this problem you will write a simple guessing game for the user to guess a number between 1-100 instead without bias. Your program should flow as follows: Asks the user to enter a user name. Makes a call to "syscall $random" and sets the initial LFSR state. Calls state = LFSR(state) seven times to generate a random number between 0 and 127 using value B from each subsequent state. For up to seven guesses If the user guesses correctly, congratulate the user end the program. Tell the user whether the guesses was too high or too low. Tell the that all seven were used, and the random number. You must use the syscall convention presented in class. For instance to print a string: la $a0, stringaddr syscall $print string

Explanation / Answer

MIPS ASSEMBLY LANGUAGE: Guessing Game

  .data

message: .asciiz "Guess a number "

higher:   .asciiz "Higher! "

lower:   .asciiz "Lower! "

  correct:   .asciiz "Correct! "

  .text

# seed the random number generator

  # get the time

  li $v0, 30 # get time in milliseconds (as a 64-bit value)

syscall # Low order 32 bits of system time are now in $a0

move $t0, $a0   # save the lower 32-bits of time into $t0

# seed the random generator (just once)

li $a0, 1 # random generator id (will be used later)

move $a1, $t0   # seed from time

li $v0, 40   # seed random number generator syscall

syscall # Random Num takes 2 args, $a0 = id num $a1 = seed,

# which is now milliseconds of current time

# seeding done

  # get number from user

# note $v0 now contains integer that was read

# Generate a random number while it is unequal to guess

# generate 10 random integers in the range 100 from the

# seeded generator (whose id is 1)

#li $t2, 6 # max number of iterations

#li $t3, 0 # current iteration number

LOOP:

la $t0 message   # load the message's address

move $a0, $t0   # make the address an argument

li $v0, 4 # print string -> message

syscall

li $v0, 5   # get integer -> load it to $v0

syscall

move $t5, $v0 # move guessed int from $v0 to $t5

li $a0, 1   # as said, this id is the same as random generator id

li $a1, 10   # upper bound of the range

li $v0, 42   # System number for random int with range

syscall

addi $a0, $a0, 1    # $a0 now holds the random number, add one to it

move $t2, $a0   # move the generated number to $t2

# loop terminating condition

beq $t5, $t2, EXIT # branch to EXIT if iterations is 100 # This is saying, if t5 == t2 then exit

# Next iteration of loop

j LOOP

#Exit program

EXIT:

la $t0 correct   # load the message's address

move $a0, $t0 # make the address an argument

li $v0, 4 # print string -> message

syscall

li $v0, 10 # exit syscall

syscall

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote