In this project, we will implement the game rock paper scissors. Our implementation differs from the traditional two player game in the fact that the computer will play against itself. To do this, we will randomly generate moves for both players, compare their selections and announce the winner!
Our MIPS program’s behaviour will be determined by the program configuration, which is a sequence of values in memory. Starting from some address conf, the relevant values in memory are always at fixed locations relative to conf. The following table uses the offset(address) notation which specifies the memory address offset bytes after address.
Name | eca | tape | tape_len | rule | skip | column |
---|---|---|---|---|---|---|
Size | (4 bytes) | (4 bytes) | (1 byte) | (1 byte) | (1 byte) | (1 byte) |
Memory Address | conf | 4(conf) | 8(conf) | 9(conf) | 10(conf) | 11(conf) |
To generate pseudorandom numbers, the computer starts with an initial configuration, called the seed, algorithmically generating a chaotic sequence of numbers. Due to the deterministic nature of the random number generator, given the same seed twice, the algorithm will produce the same sequence of numbers twice. We will use known seed values to make our random programs reproducible.
The MARS simulator supports several syscalls related to random number generation. Each syscall related
to random number generators receives as first argument a number uniquely determining the random number
generator to use. Throughout this project, will always use the random number generator with i.d. 0. Figure 1
shows an excerpt of the MARS documentation (accessed by pressing F1 in the simulator).
Your task is to implement two functions gen_bit and gen_byte. Assume in both of these functions that the
random number generator’s seed has already been set, e.g. by the .main program.
random.s implements two functions gen_bit and gen_byte.
if (eca != 0)
, we use the ECA to generate a random bit. To do this, we read the values skip and column from the configuration struct, simulate the automatonskip times and return the bit in the columnth column of the tape.
When gen_bit is called, it queries the random number generator for the next number and return its least significant bit.
Service | Code in $v0 | Arguments | Result |
---|---|---|---|
set seed | 40 | $a0 = id. of pseudorandom number generator | No values are returned. Sets the seed of the corresponding underlying Java pseudorandom... |
random int | 41 | $a0 = id. of pseudorandom number generator (any int) | $a0 contains the next pseudorandom, uniformly distributed int value from this random... |