Question: . data # constants Multiplier: . word 1 0 7 3 8 0 7 3 5 9 # a sufficiently large prime # You probably

.data
# constants
Multiplier: .word 1073807359 # a sufficiently large prime
# You probably have enough registers that you won't need variables.
# However, if you do wish to have named variables, do it here.
# Word Variables First
# HalfWord Variables Next
# Byte Variables Last (Strings and characters are Byte data)
# common strings
minPrompt: .asciiz "Enter the smallest number acceptable (0<=n<=998): "
maxPrompt: .asciiz "Enter the biggest number acceptable ( n <=1000): "
qtyPrompt: .asciiz "How many randoms do you want (5-100)?"
rsdPrompt: .asciiz "Enter a seed number (1073741824-2147483646): "
smErr1: .asciiz "That number is too small, try again: "
smErr2: .asciiz "The max cannot be less than the min, try again: "
bgErr: .asciiz "That number is too large, try again: "
outStr: .asciiz "Here is the series of randoms:
"
newLine: .asciiz "
"
.text
.globl main
#-------------------------------------------------------------------------------
# The start: entry point from the MIPS file is encompassed in the kernel code
# of the QTSPIM simulator. This version starts with main: which does everything
# in this simple program.
#-------------------------------------------------------------------------------
main: # start of the main procedure
# prompt for the minimum result and get the value
# this is where you ask the user to tell you the beginning of the
# range of output numbers ("randoms from 15 to 25", for example).
# check that the input number is in the valid range for minimum,
# 0 to 998, and if it isn't, display an error and keep looping
# back until the user enters a good number.
# 1) prompt for the number
# 2) read the integer
# 3) if the integer is >=0 go to step 4
# else print error and return to step 2
# 4) if the number is <=998 go to next input
# else print error and return to step 2
# prompt for the maximum result and get the value
# just like the minimum result, you keep asking for the input
# until you get a good value. In addition to making sure it
# is in a valid range, you also have to make sure it is
# greater than the minimum entered before.
# 1) prompt for the number
# 2) read the integer
# 3) if the integer is >= minimum go to step 4
# else print error and return to step 2
# 4) if the number is <=1000 go to next input
# else print error and return to step 2
# now you ask for how many randoms the user wants
# I arbitrarily chose 5 to 100 as enough to show you are getting
# random numbers without overdoing it. Very similar to the last:
# 1) prompt for the number
# 2) read the integer
# 3) if the integer is >=5 go to step 4
# else print error and return to step 2
# 4) if the number is <=100 go to next input
# else print error and return to step 2
# This one is just as easy, though the boundary values are large. The
reason
# is buried in how the generation algorithm works but you can just
trust me
# that the numbers in this range SHOULD give good random values.
# 1) prompt for the number
# 2) read the integer
# 3) if the integer is >=1073741823 go to step 4
# else print error and return to step 2
# 4) if the number is <=2147483646 go to next input
# else print error and return to step 2
# Now would be a good time to compute the output range so you don't
have to
# do it each time you generate a new random.
# precalculate the range by subtracting the minimum from the maximum
# then add 1 to the result
# tell the user "here come the randoms" or something similar
# initialize the loop counter with the number of desired randoms
# top of random generator loop
# first generate a random
# 1) multiply the seed by the multiplier
# 2) lo replaces the old seed
# 3) hi is the raw random number
# next range fit the raw random for output
# 1) divide the raw random by the precalculated range
# 2) hi hold the ranged random after division
# 3) add minimum to the ranged random
# 4) print out the result
# 5) print out a newline or "" to separate the next
# decrement the loop counter
# if loop counter >0, jump back to start of loop
# exit program
li $v0,10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!