#######################################################################################
##################### COMP1521 26T2 ASSIGNMENT 1: Geometry Dash #######################
##                                                                                   ##
## !!! IMPORTANT !!!                                                                 ##
## Before starting work on the assignment, make sure you set your tab-width to 8!    ##
## It is also suggested to indent with tabs only.                                    ##
## Instructions to configure your text editor can be found here:                     ##
##   https://cgi.cse.unsw.edu.au/~cs1521/current/resources/mips-editors.html         ##
## !!! IMPORTANT !!!                                                                 ##
##                                                                                   ##
## This program was written by YOUR-NAME-HERE (z55555555)                            ##
## on INSERT-DATE-HERE                                                               ##
##                                                                                   ##
## HEY! HEY YOU! Fill this header comment in RIGHT NOW!!! Don't miss out on that     ##
## precious style mark!!      >:O                                                    ##

#################################################
## CONSTANTS: PLEASE USE THESE FOR YOUR SANITY ##
#################################################
SIZE_OF_CHAR = 1
SIZE_OF_INT = 4

########################################
## CONSTANTS: REQIURED FOR GAME LOGIC ##
########################################
MIN_HEIGHT = 4
MAX_HEIGHT = 6

MIN_WIDTH = 10
MAX_WIDTH = 40

FORWARD_KEY = 'd'
JUMP_KEY = 'w'
PLAYER_CHAR = 'P'
EXIT_KEY = 'q'

EMPTY = 0
BLOCK = 1
SPIKE = 2
TOTAL_TILES = 3

FALSE = 0
TRUE = 1

EMPTY_WEIGHT = 45
BLOCK_WEIGHT = 4
SPIKE_WEIGHT = 2

PLAYER_X_OFFSET = 0
PLAYER_Y_OFFSET = 4
PLAYER_VY_OFFSET = 8
PLAYER_ON_BLOCK_OFFSET = 12
SIZE_OF_PLAYER = 16

CELL_POSSIBLE_OFFSET = 0
CELL_COLLAPSED_OFFSET = 4
CELL_TILE_OFFSET = 8
SIZE_OF_CELL = 12

###################
## END CONSTANTS ##
###################

########################################
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
########################################

######################
## GLOBAL VARIABLES ##
######################

    .data
#############################################
## struct Cell grid[MAX_HEIGHT][MAX_WIDTH] ##
#############################################
grid:
    .space MAX_HEIGHT * MAX_WIDTH * SIZE_OF_CELL

#########################################
## char tile_chars[] = {' ', '#', '^'} ##
#########################################
tile_chars:
    .byte ' ', '#', '^'
    
#####################################
## int weighted[TOTAL_TILES * 100] ##
#####################################
weighted:
    .align 2
    .space  100 * TOTAL_TILES * SIZE_OF_INT
    
########################
## int game_in_action ##
########################
game_in_action:
    .align 2
    .space 4
    
################
## int height ##
################
height:
    .align 2
    .space 4

###############
## int width ##
###############
width:
    .align 2
    .space 4
    
###################
## int rand_seed ##
###################
rand_seed:
    .align 2
    .space 4

################
## int best_x ##
################
best_x:
    .align 2
    .space 4

################
## int best_y ##
################
best_y:
    .align 2
    .space 4

########################
## struct Player      ##
## 	int x;        ##
## 	int y;        ##
## 	int vy;	      ##
## 	int on_block; ##
########################
player:
    .word 0
    .word 0
    .word 0
    .word 0

########################################
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
########################################

##########################
## END GLOBAL VARIABLES ##
##########################

####################
## STATIC STRINGS ##
####################

str_print_welcome_1:
    .asciiz "Welcome to 1521 geometry dash!\n"

str_print_welcome_2:
    .asciiz "To move forwards, press "

str_print_welcome_3:
    .asciiz "To jump, press "

str_print_welcome_4:
    .asciiz "To exit, press "

str_print_welcome_5:
    .asciiz "Jump onto platforms and around spikes to avoid them\n"

str_print_welcome_6:
    .asciiz "If you jump onto a spike you lose :(\n"

str_print_welcome_7:
    .asciiz "Try make it to the end of the map!\n"

str_get_input_width:
    .asciiz "Please select a width (10-40): "

str_get_input_invalid_width:
    .asciiz "Invalid width."

str_get_input_height:
    .asciiz "Please select a height (4-6): "

str_get_input_invalid_height:
    .asciiz "Invalid height."

str_get_input_random_seed:
    .asciiz "Please enter a random seed: "

str_game_loop_1:
    .asciiz "Action: "

str_calculate_player_move_1:
    .asciiz "You died!\n"

str_calculate_player_move_2:
    .asciiz "You win!\n"


########################################
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
## DO NOT MODIFY THE .DATA SECTION!!! ##
########################################

########################
## END STATIC STRINGS ##
########################

	.text

############################################################
####                                                    ####
####   Your journey begins here, intrepid adventurer!   ####
####                                                    ####
############################################################

##############
## SUBSET 0 ##
##############

###########################
## void print_welcome(); ##
###########################

################################################################################
# .TEXT <print_welcome>
	.text
print_welcome:
	# Subset:   0
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   print_welcome
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
print_welcome__prologue:

print_welcome__body:

print_welcome__epilogue:
	jr	$ra
	
#####################
## int main(void); ##
#####################

################################################################################
# .TEXT <main>
	.text
main:
	# Subset:   0
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   main
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
main__prologue:

main__body:

main__epilogue:
	jr	$ra

##############
## SUBSET 1 ##
##############

#######################
## void game_loop(); ##
#######################

################################################################################
# .TEXT <init_game>
	.text
game_loop:
	# Subset:   1
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   game_loop
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
game_loop__prologue:

game_loop__body:

game_loop__epilogue:
	jr	$ra
	
#######################
## void get_input(); ##
#######################

################################################################################
# .TEXT <get_input>
	.text
get_input:
	# Subset:   1
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   get_input
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
get_input_prologue:

get_input_body:								  

get_input_epilogue:
	jr	$ra
	
############################################
## void calculate_weighted_probability(); ##
############################################

################################################################################
# .TEXT <calculate_weighted_probability>
	.text
calculate_weighted_probability:
	# Subset:   1
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   calculate_weighted_probability
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
calculate_weighted_probability__prologue:

calculate_weighted_probability__body:

calculate_weighted_probability__epilogue:
	jr	$ra

##############################
## void test_above_cells(); ##
##############################

################################################################################
# .TEXT <test_above_cells>
	.text
test_above_cells:
	# Subset:   1
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   test_above_cells
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
test_above_cells__prologue:

test_above_cells__body:

test_above_cells__epilogue:
	jr	$ra

##############
## SUBSET 2 ##
##############

#######################
## void test_cell(); ##
#######################

################################################################################
# .TEXT <test_cell>
	.text
test_cell:
	# Subset:   2
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   test_cell
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
test_cell__prologue:

test_cell__body:
	
test_cell__epilogue:
	jr	$ra

#######################
## void init_game(); ##
#######################

################################################################################
# .TEXT <init_game>
	.text
init_game:
	# Subset:   2
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   init_game
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
init_game__prologue:

init_game__body:

init_game__epilogue:
	jr	$ra

############################
## void check_possible(); ##
############################

################################################################################
# .TEXT <check_possible>
	.text
check_possible:
	# Subset:   2
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   check_possible
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
check_possible__prologue:

check_possible__body:

check_possible__epilogue:
	jr	$ra

######################
## void collapse(); ##
######################

################################################################################
# .TEXT <collapse>
	.text
collapse:
	# Subset:   2
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   collapse
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
collapse__prologue:

collapse__body:

collapse__epilogue:
	jr	$ra

#######################
## void init_grid(); ##
#######################

################################################################################
# .TEXT <init_grid>
	.text
init_grid:
	# Subset:   3
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   init_grid
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
init_grid__prologue:

init_grid__body:

init_grid__epilogue:
	jr	$ra

##############
## SUBSET 3 ##
##############

#####################################
## void get_lowest_entropy_tile(); ##
#####################################

################################################################################
# .TEXT <get_lowest_entropy_tile>
	.text
get_lowest_entropy_tile:
	# Subset:   3
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   get_lowest_entropy_tile
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
get_lowest_entropy_tile__prologue:

get_lowest_entropy_tile__body:

get_lowest_entropy_tile__epilogue:
	jr	$ra

######################
## void is_valid(); ##
######################

################################################################################
# .TEXT <is_valid>
	.text
is_valid:
	# Subset:   3
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   is_valid
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
is_valid__prologue:

is_valid__body:

is_valid__epilogue:
	jr	$ra

###################################
## void calculate_player_move(); ##
###################################

################################################################################
# .TEXT <calculate_player_move>
	.text
calculate_player_move:
	# Subset:	3
	#
	# Frame:	[...]   <-- FILL THESE OUT!
	# Uses:		[...]
	# Clobbers: 	[...]
	#
	# Locals:		<-- FILL THIS OUT!
	#   - ...
	#
	# Structure:		<-- FILL THIS OUT!
	#   calculate_player_move
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
calculate_player_move__prologue:

calculate_player_move__body:

calculate_player_move__epilogue:
	jr	$ra

##############
## SUPPLIED ##
##############

#######################
## void propagate(); ##
#######################

################################################################################
# .TEXT <propagate>
    .text
propagate:
	# Subset:   supplied
	#
	# Frame:    [$ra, $s0, $s1, $s2, $s3, $s4, $s5]
	# Uses:     [$ra, $s0, $s1, $s2, $s3, $s4, $s5, $t0, $t1, $t2, $t3, $t5]
	# Clobbers: [$t0, $t1, $t3, $t2, $t5]
	#
	# Locals:
	#   - $t0: height
	#   - $t1: width
	#   - $t2: &grid
	#   - $t3: grid[y][x].collapsed
	#   - $t5: grid[y][x].possible[t]
	#   - $s0: y
	#   - $s1: x
	#   - $s2: t
	#   - $s3: changed
	#   - $s4, $s5: grid[y][x]
	#
	# Structure:
	#   propagate
	#   -> [prologue]
	#	-> body
	#       -> loop_init
	#		-> loop_body
	#		-> loop_body_y_loop_init
	#		-> loop_body_y_loop_cond
	#			-> loop_body_y_loop_body
	#			-> loop_body_x_loop_init
	#			-> loop_body_x_loop_cond
	#				-> loop_body_x_loop_body
	#				-> loop_body_t_loop_init
	#				-> loop_body_t_loop_cond
	#					-> loop_body_t_loop_body
	#				-> loop_body_t_loop_iter
	#				-> loop_body_t_loop_end
	#			-> loop_body_x_loop_iter
	#			-> loop_body_x_loop_end
	#		-> loop_body_y_loop_iter
	#		-> loop_body_y_loop_end
	#	-> loop_cond
	#	-> loop_end
	#   -> [epilogue]
propagate__prologue:
	push    $ra
	push    $s0
	push    $s1
	push    $s2
	push    $s3
	push    $s4
	push    $s5

propagate__body:

progagate__body_loop_init:
progagate__body_loop_body:
	li      $s3, 0							# changed = 0

progagate__body_loop_body_y_loop_init:
	li      $s0, 0							# int y = 0

progagate__body_loop_body_y_loop_cond:
	lw      $t0, height                
	bge     $s0, $t0, progagate__body_loop_body_y_loop_end		# if (y >= height) goto progagate__body_loop_body_y_loop_end

progagate__body_loop_body_y_loop_body:
progagate__body_loop_body_x_loop_init:
	li      $s1, 0							# int x = 0

progagate__body_loop_body_x_loop_cond:
	lw      $t1, width
	bge     $s1, $t1, progagate__body_loop_body_x_loop_end		# if (x >= width) goto progagate__body_loop_body_x_loop_end

progagate__body_loop_body_x_loop_body:
	la      $t2, grid
	mul     $t3, $s0, MAX_WIDTH
	add     $t3, $t3, $s1
	mul     $t3, $t3, SIZE_OF_CELL
	add     $s4, $t2, $t3              

	lw      $t3, CELL_COLLAPSED_OFFSET($s4)				# grid[y][x].collpased                            

	bnez    $t3, progagate__body_loop_body_x_loop_iter		# if (grid[x][x].collpased) goto progagate__body_loop_body_x_loop_iter

progagate__body_loop_body_t_loop_init:
	li      $s2, 0							# int t = 0

progagate__body_loop_body_t_loop_cond:
	bge     $s2, TOTAL_TILES, progagate__body_loop_body_t_loop_end  # if (t >= TOTAL_TILES) goto progagate__body_loop_body_t_loop_end

progagate__body_loop_body_t_loop_body:

	add     $s5, $s4, $s2						# grid[y][x].possible[t]
	lb      $t5, CELL_POSSIBLE_OFFSET($s5)

	beqz    $t5, progagate__body_loop_body_t_loop_iter		# if (grid[y][x].possible[t]) {    

	move    $a0, $s0
	move    $a1, $s1
	move    $a2, $s2

	jal     is_valid						# is_valid(y, x, t)

	bnez    $v0, progagate__body_loop_body_t_loop_iter		# if (!is_valid(y, x, t))

	li      $t5, 0
	sb      $t5, ($s5)						# grid[y][x].possible[t] = 0;

	li      $s3, 1							# changed = 1;

progagate__body_loop_body_t_loop_iter:
	addi    $s2, $s2, 1						# t++
	b       progagate__body_loop_body_t_loop_cond

progagate__body_loop_body_t_loop_end:

progagate__body_loop_body_x_loop_iter:
	addi    $s1, $s1, 1
	b       progagate__body_loop_body_x_loop_cond			# }

progagate__body_loop_body_x_loop_end:

progagate__body_loop_body_y_loop_iter:
	addi    $s0, $s0, 1
	b       progagate__body_loop_body_y_loop_cond			# }

progagate__body_loop_body_y_loop_end:

progagate__body_loop_cond:
	bnez    $s3, progagate__body_loop_body				# while(changed)

progagate__body_loop_end:

propagate__epilogue:
	pop     $s5
	pop     $s4
	pop     $s3
	pop     $s2
	pop     $s1
	pop     $s0
	pop     $ra
	jr      $ra

#####################################
## void print_board_with_player(); ##
#####################################

################################################################################
# .TEXT <print_board_with_player>
    .text
print_board_with_player:
	# Subset:   supplied
	#
	# Frame:    []
	# Uses:     [$t0, $t1, $t2, $t3, $t4, $t5, $t6, $t8]
	# Clobbers: [$t0, $t1, $t2, $t3, $t4, $t5, $t6, $t8]
	#
	# Locals:
	#   - $t0: y
	#   - $t1: x
	#   - $t2: height
	#   - $t3: width
	#   - $t4: player->x
	#   - $t5: player->y, grid
	#   - $t6: temporary calculations, grid[y][x].tile
	#   - $t8: struct Player *player
	#
	# Structure:
	#   print_board_with_player
	#   -> [prologue]
	#       -> body
	#	-> y_loop_init
	#	-> y_loop_cond
	#		-> y_loop_body
	#		-> x_loop_init
	#		-> x_loop_cond
	#			-> x_loop_body
	#				-> x_loop_if
	#				-> x_loop_else
	#		-> x_loop_iter
	#		-> x_loop_end
	#	-> y_loop_iter
	#	-> y_loop_end
	#   -> [epilogue]
print_board_with_player__prologue:

print_board_with_player__body:
	move    $t8, $a0
	lw      $t2, height
    
print_board_with_player__body_y_loop_init:
	li      $t0, 0							# int y = 0

print_board_with_player__body_y_loop_cond:
	bge     $t0, $t2, print_board_with_player__body_y_loop_end	# if (y >= eight) goto print_board_with_player__body_y_loop_end

print_board_with_player__body_y_loop_body:
print_board_with_player__body_x_loop_init:
	li      $t1, 0							# int x = 0

print_board_with_player__body_x_loop_cond:
	lw      $t3, width
	bge     $t1, $t3, print_board_with_player__body_x_loop_end	# if (x >= width) goto print_board_with_player__body_x_loop_end

print_board_with_player__body_x_loop_body:
	lw      $t3, PLAYER_X_OFFSET($t8)				# t3 = player->x
	lw      $t4, PLAYER_Y_OFFSET($t8)				# t4 = player->y

	bne     $t1, $t3, print_board_with_player__body_x_loop_else	# if (x != player->x) goto print_board_with_player__body_x_loop_else
	bne     $t0, $t4, print_board_with_player__body_x_loop_else	# if (y != player->y) goto print_board_with_player__body_x_loop_else

print_board_with_player__body_x_loop_if:
	li      $v0, 11
	li      $a0, PLAYER_CHAR
	syscall								# printf("%c", PLAYER_CHAR);

	b       print_board_with_player__body_x_loop_iter		# goto print_board_with_player__body_x_loop_iter

print_board_with_player__body_x_loop_else:
	la      $t5, grid				
	mul     $t6, $t0, MAX_WIDTH					# i * MAX_WIDTH
	add     $t6, $t6, $t1						# (i * MAX_WIDTH) + x
	mul     $t6, $t6, SIZE_OF_CELL					# (i * MAX_WIDTH + x) * SIZE_OF_CELL
	add     $t6, $t6, $t5						# ((i * MAX_WIDTH + x) * SIZE_OF_CELL) + &grid
	lw      $t6, CELL_TILE_OFFSET($t6)				# t6 = grid[y][x].tile		

	la      $t5, tile_chars
	add     $t5, $t5, $t6						# tile_chaars[grid[y][x].tile]

	lb      $a0, ($t5)
	li      $v0, 11
	syscall								# printf("%c", tile_chars[grid[y][x].tile]); 

print_board_with_player__body_x_loop_iter:
	addi    $t1, $t1, 1						# x++
	b       print_board_with_player__body_x_loop_cond		# goto print_board_with_player__body_x_loop_cond

print_board_with_player__body_x_loop_end:
	li      $v0, 11
	li      $a0, '\n'
	syscall								# printf("\n")

print_board_with_player__body_y_loop_iter:
	addi    $t0, $t0, 1						# y++
	b       print_board_with_player__body_y_loop_cond		# goto print_board_with_player__body_y_loop_cond

print_board_with_player__body_y_loop_end:

print_board_with_player__epilogue:
	jr      $ra							# return

###################################
## void rand_value(); ##
###################################

################################################################################
# .TEXT <rand_value>
	.text
rand_value:
	# Subset:   Supplied
	#
	# Frame:	None
	# Uses:	 	$v0, $a0, $t0, $t1
	# Clobbers: 	$v0, $t0, $t1
	#
	# Locals:
	#   - `unsigned int rand_seed` cached in $t0
	#
	# Structure:		<-- FILL THIS OUT!
	#   calculate_player_move
	#   -> [prologue]
	#	   -> body
	#   -> [epilogue]
rand_value__prologue:

rand_value__body:
	lw	$t0, rand_seed		#  rand_seed

	li	$t1, 1103515245
	mul	$t0, $t0, $t1		#  rand_seed * 1103515245

	addiu	$t0, $t0, 12345		#  rand_seed * 1103515245 + 12345

	li	$t1, 0x7FFFFFFF
	and	$t0, $t0, $t1		# (rand_seed * 1103515245 + 12345) & 0x7FFFFFFF

	sw	$t0, rand_seed		# rand_seed = (rand_seed * 1103515245 + 12345) & 0x7FFFFFFF;

	rem	$v0, $t0, $a0		# rand_seed % n;

rand_value__epilogue:
	jr	$ra			# return rand_seed % n
