########################################################################
# COMP1521 22T1 — Assignment 1 — Mipstermind!
# !!! IMPORTANT !!!
# Before starting work on the assignment, make sure you set your tab-width to 8!
Copyright By PowCoder代写 加微信 powcoder
# 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/22T1/resources/mips-editors.html
# !!! IMPORTANT !!!
# This program was written by YOUR-NAME-HERE (z5555555)
# on INSERT-DATE-HERE
# Version 1.0 (28-02-22): Team COMP1521
########################################################################
#![tabsize(8)]
# Constant definitions.
# DO NOT CHANGE THESE DEFINITIONS
TURN_NORMAL = 0
TURN_WIN = 1
NULL_GUESS = -1
########################################################################
# YOU DO NOT NEED TO CHANGE THE DATA SECTION
# int correct_solution[GUESS_LEN];
correct_solution: .space GUESS_LEN * 4
# int current_guess[GUESS_LEN];
current_guess: .space GUESS_LEN * 4
# int solution_temp[GUESS_LEN];
solution_temp: .space GUESS_LEN * 4
guess_length_str: .asciiz “Guess length:\t”
valid_guesses_str: .asciiz “Valid guesses:\t1-”
number_turns_str: .asciiz “How many turns:\t”
enter_seed_str: .asciiz “Enter a random seed: ”
you_lost_str: .asciiz “You lost! The secret codeword was: ”
turn_str_1: .asciiz “—[ Turn ”
turn_str_2: .asciiz ” ]—\n”
enter_guess_str: .asciiz “Enter your guess: ”
you_win_str: .asciiz “You win, congratulations!\n”
correct_place_str: .asciiz “Correct guesses in correct place: ”
incorrect_place_str: .asciiz “Correct guesses in incorrect place: ”
############################################################
#### ####
#### Your journey begins here, intrepid adventurer! ####
#### ####
############################################################
########################################################################
# Implement the following 8 functions,
# and check these boxes as you finish implementing each function
# – [ ] main
# – [ ] play_game
# – [ ] generate_solution
# – [ ] play_turn
# – [ ] read_guess
# – [ ] copy_solution_into_temp
# – [ ] calculate_correct_place
# – [ ] calculate_incorrect_place
# – [X] seed_rand (provided for you)
# – [X] rand (provided for you)
########################################################################
########################################################################
# .TEXT
# Args: void
# Returns:
# – $v0: int
# Frame: [$ra, …]
# Uses: [$v0, $a0, …]
# Clobbers: [$v0, $a0, …]
# – […]
# Structure:
# -> [prologue]
# -> body
# -> [epilogue]
main__prologue:
begin # begin a new stack frame
push $ra # | $ra
main__body:
# printf(“Guess length: %d\n”, GUESS_LEN);
li $v0, 4 # syscall 4: print_string
la $a0, guess_length_str
syscall # printf(“Guess length: “);
li $v0, 1 # syscall 1: print_int
li $a0, GUESS_LEN
syscall # printf(“%d”, GUESS_LEN);
li $v0, 11 # syscall 11: print_char
li $a0, ‘\n’
syscall # printf(“\n”);
# printf(“Valid guesses: 1-%d\n”, GUESS_CHOICES);
li $v0, 4 # syscall 4: print_string
la $a0, valid_guesses_str
syscall # printf(“Valid guesses: 1-“);
li $v0, 1 # syscall 1: print_int
li $a0, GUESS_CHOICES
syscall # printf(“%d”, GUESS_CHOICES);
li $v0, 11 # syscall 11: print_char
li $a0, ‘\n’
syscall # printf(“\n”);
# printf(“Number of turns: %d\n\n”, MAX_TURNS);
li $v0, 4 # syscall 4: print_string
la $a0, number_turns_str
syscall # printf(“Number of turns: “);
li $v0, 1 # syscall 1: print_int
li $a0, MAX_TURNS
syscall # printf(“%d”, MAX_TURNS);
li $v0, 11 # syscall 11: print_char
li $a0, ‘\n’
syscall # printf(“\n”);
syscall # printf(“\n”);
# TODO … complete this function
main__epilogue:
pop $ra # | $ra
end # ends the current stack frame
li $v0, 0
jr $ra # return 0;
######################################################################## play_game: play_game__prologue: # TODO … complete this function play_game__epilogue: ######################################################################## generate_solution: generate_solution__prologue: # TODO … complete this function generate_solution__epilogue: ######################################################################## play_turn: play_turn__prologue: # TODO … complete this function play_turn__epilogue: ######################################################################## read_guess: read_guess__prologue: # TODO … complete this function read_guess__epilogue: ######################################################################## copy_solution_into_temp: copy_solution_into_temp__prologue: copy_solution_into_temp__epilogue: ######################################################################## calculate_correct_place: calculate_correct_place__prologue: # TODO … complete this function calculate_correct_place__epilogue: ######################################################################## calculate_incorrect_place: calculate_incorrect_place__prologue: # TODO … complete this function calculate_incorrect_place__epilogue: ######################################################################## ## The following are two utility functions, provided for you. ######################################################################## # int random_seed; ######################################################################## # DO NOT CHANGE THIS FUNCTION seed_rand: li $t0, OFFLINE_SEED # const unsigned int offline_seed = OFFLINE_SEED; jr $ra # return; ######################################################################## # DO NOT CHANGE THIS FUNCTION # – $a0: unsigned int n lw $t0, random_seed # unsigned int rand = random_seed; remu $v0, $t0, $a0 # rand % n 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com
# .TEXT
# Args: void
# Returns: void
# Frame: […]
# Uses: […]
# Clobbers: […]
# – […]
# Structure:
# play_game
# -> [prologue]
# -> body
# -> [epilogue]
play_game__body:
jr $ra # return;
# .TEXT
# Args: void
# Returns: void
# Frame: […]
# Uses: […]
# Clobbers: […]
# – […]
# Structure:
# generate_solution
# -> [prologue]
# -> body
# -> [epilogue]
generate_solution__body:
jr $ra # return;
# .TEXT
# – $a0: int
# Returns:
# – $v0: int
# Frame: […]
# Uses: […]
# Clobbers: […]
# – […]
# Structure:
# play_turn
# -> [prologue]
# -> body
# -> [epilogue]
play_turn__body:
jr $ra # return;
# .TEXT
# Args: void
# Returns: void
# Frame: […]
# Uses: […]
# Clobbers: […]
# – […]
# Structure:
# read_guess
# -> [prologue]
# -> body
# -> [epilogue]
read_guess__body:
jr $ra # return;
# .TEXT
# Args: void
# Returns: void
# Frame: […]
# Uses: […]
# Clobbers: […]
# – […]
# Structure:
# copy_solution_into_temp
# -> [prologue]
# -> body
# -> [epilogue]
copy_solution_into_temp__body:
# TODO … complete this function
jr $ra # return;
# .TEXT
# Args: void
# Returns:
# – $v0: int
# Frame: […]
# Uses: […]
# Clobbers: […]
# – […]
# Structure:
# calculate_correct_place
# -> [prologue]
# -> body
# -> [epilogue]
calculate_correct_place__body:
# .TEXT
# Args: void
# Returns:
# – $v0: int
# Frame: […]
# Uses: […]
# Clobbers: […]
# – […]
# Structure:
# calculate_incorrect_place
# -> [prologue]
# -> body
# -> [epilogue]
calculate_incorrect_place__body:
#### ####
#### STOP HERE … YOU HAVE COMPLETED THE ASSIGNMENT! ####
#### ####
########################################################################
## You don’t need to modify any of the following.
## But you may find it useful to read through.
## You’ll be calling these functions from your code.
random_seed: .space 4
# .TEXT
# – $a0: unsigned int seed
# Returns: void
# Frame: []
# Uses: [$a0, $t0]
# Clobbers: [$t0]
# – $t0: offline_seed
# Structure:
# seed_rand
xor $t0, $a0 # random_seed = seed ^ offline_seed;
sw $t0, random_seed
# .TEXT
# Returns:
# – $v0: int
# Frame: []
# Uses: [$a0, $v0, $t0]
# Clobbers: [$v0, $t0]
# – $t0: random_seed
# Structure:
multu $t0, 0x5bd1e995 # rand *= 0x5bd1e995;
mflo $t0
addiu $t0, 12345 # rand += 12345;
sw $t0, random_seed # random_seed = rand;
jr $ra # return rand % n;