zototosonososonsonatoeosorsosaeogstntontsosoisetaeh _ooooosseeooosooin_ee_。seoe_onsoisooosnsonsotonn_ooosnsoonnoo.seeos.ensoseenssn
ELEC2350: Computer Organization
Project 2: Branching and Procedure – “Find Me If You Can”
Objective
1. Togetfamiliarwithbranchingimplementation
2. Tounderstandstructureprogrammingandfunction 3. Togetfamiliarwithstackstructure&stackoperation
Introduction
In this project, you are required to write a game called “Find Me If You Can”. In this game, we have a 10 x 10 treasure field with coordinate shown in the following figure.
y axis
(5, 4)
(0, 0)
x axis
T
The coordinate of the treasure (tx, ty) is randomly generated by a Random Number Generator with a seed entered by user, which should be the last 5 digits of your student ID.
After the player inputs the x coordinate and then the y coordinate, the program display messages showing whether the x coordinate is larger than, smaller than or equal to tx and whether the y coordinate is larger than, smaller than or equal to ty. The game will not end until the player guesses (tx, ty) correctly. If the player makes a correct guess, the program will ask the player to exit or not. If the player would like to play again, the program will generate a new coordinate for the treasure.
Program Skeleton (**You MUST follow this Skeleton**)
# NAME: ELEC2350 2020 Spring – Computer Organization # Project 2
# Find Me if You Can
.eqv
c_range_xy 10
.data
.word 13207
.asciiz “Please enter a number: ”
.asciiz “What is the x coordinate of the treasure (0-9)? ”
.asciiz “What is the y coordinate of the treasure (0-9)? ”
.asciiz “The x coordinate of the treasure is larger than your guess. (” .asciiz “The x coordinate of the treasure is smaller than your guess. (” .asciiz “The x coordinate of the treasure is correct. (”
seed:
msg:
msg0:
msg1:
msg2:
msg3:
msg4:
msg5:
msg6:
msg7:
msg8:
msg9:
msg10:.asciiz “Wrong message! Only (1) or (0)!!!!\n” msg11:.asciiz “Play with me next time. See YOU!!\n” msg12:.asciiz “Out of Range!!\n”
.asciiz “The y coordinate of the treasure is larger than your guess. (” .asciiz “The y coordinate of the treasure is smaller than your guess. (” .asciiz “The y coordinate of the treasure is correct. (”
.asciiz “You get the treasure!!! (”
.asciiz “Do you want to EXIT??(0:No, play again. 1:Yes, stop the game.) ”
Last Revised 4/28/2020 Page 1 of 3
c_bkt: .asciiz “)\n ” comma:.asciiz “,” space: .asciiz ” ” newline:.asciiz “\n”
.text main:
# Print “Please enter a number: \n”
la $a0, msg li $v0, 4 syscall
# Get the seed from the user and store in seed
li $v0, 5 syscall
sw $v0, seed
#————————————————————————– #
# Write your code here
# #————————————————————————–
# Terminate the program
li $v0, 10 syscall
#————————————————————————–
#
#
#
#
#
#
#
# Check_coordinate:
function for determine the correctness of the coordinate Assume:
rand:
addi $sp, $sp, -8
sw $t0, 4($sp)
sw $ra, 0($sp)
addu $t0, $t0, $ra
jal randnum
addi $t0, $0, c_range_xy remu $v0, $v0, $t0
lw $ra, 0($sp) lw $t0, 4($sp) addi $sp, $sp, 8
# adjust the stack pointer
# store registers’ value to stack
# get the reminder of division
# load the values from the stack to registers
1. Guess x and y are stored in $a0, $a1 respectively
2. Treasure x and y are stored in $a2, $a3 respectively Outputs:
1. v0 (2: when correct x = input x, 1: correct x > input x, 0: correct x < input x) 2. v1 (2: when correct y = input y, 1: correct y > input y, 0: correct y < input y)
#-------------------------------------------------------------------------- #
# Write your code here
# #--------------------------------------------------------------------------
jr $ra
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
# function for generating random number (0 – 9), return in $v0
Last Revised 4/28/2020 Page 2 of 3
jr $ra
randnum:addi
sw $t0, 4($sp)
sw $t1, 0($sp) lw $v0, seed addu $v0, $v0, $t0 addiu $t0, $0, 13 addiu $t1, $0, 3147 multu $v0, $t0
mflo $v0
addiu $v0, $v0, 14689 remu $v0, $v0, $t1 sw $v0, seed
lw $t1, 0($sp)
lw $t0, 4($sp)
addi $sp, $sp, 8
jr $ra
# adjust the stack pointer
# store registers' value to stack
# Load in first prime
# Load in the first mod value
# seed = seed * 13
# Get the LO result of the multiply
# seed = seed + 14689
# seed = seed % 3147
# Save the new seed
# load the values from the stack to registers
$sp, $sp, -8
#------------------------------------------------------------------------------
Sample Output [e.g. Student ID = xxx25167]
Please enter a number: 25167
What is the x coordinate of the treasure (0-9)? 9
What is the y coordinate of the treasure (0-9)? 5
The x coordinate of the treasure is smaller than your guess. (9) The y coordinate of the treasure is larger than your guess. (5) What is the x coordinate of the treasure (0-9)? -1
Out of range!!
What is the x coordinate of the treasure (0-9)? 10
Out of range!!
What is the x coordinate of the treasure (0-9)? 5
What is the y coordinate of the treasure (0-9)? 8
The x coordinate of the treasure is correct. (5)
The y coordinate of the treasure is larger than your guess. (8) What is the x coordinate of the treasure (0-9)? 5
What is the y coordinate of the treasure (0-9)? 9
You get the treasure!!! (5,9)
Do you want to EXIT??(0:No, play again. 1:Yes, stop the game.) 2 Wrong message! Only (1) or (0)!!!!
Do you want to EXIT??(0:No, play again. 1:Yes, stop the game.) 1 Play with me next time. See YOU!!
** Note: Your output might not be the same as above.
i.e. Entering 25167 might not have the co-ordinate of (5,9), as it depends on when you generate the random number in your program code.
Demonstration
1. Program submission. (.s or .asm file)
Name your file as Project_2_name_sid.s, where “name” is your full name and “sid” is
your student ID number. (e.g. Project_2_ChanTaiManPeter_98765432.s)
Submit your code to the Canvas/Assignments/Project on or before the deadline.
2. Demonstrate the program with correct result to the course TA during the demo session.
Last Revised 4/28/2020 Page 3 of 3