CS计算机代考程序代写 Excel ELEC2350: Computer Organization

ELEC2350: Computer Organization
Project 2: Branching and Procedure – “Find Me If You Can”
Objective
1. To get familiar with branching implementation
2. To understand structure programming and function
3. To get familiar with stack structure & stack operation
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 displays 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**)
# ELEC2350 2021 Spring
# Project 2 – Find Me if You Can .eqv c_range_xy 10
.data
seed: .word 13207
msg:
msg0:
msg1:
msg2:
msg3:
msg4:
msg5:
msg6:
msg7:
msg8:
msg9:
msg10:.asciiz “Wrong message! Please enter either (0) or (1)!!!!\n” msg11:.asciiz “Play with me next time. See YOU!!\n” msg12:.asciiz “Out of Range!!\n”
.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. (”
.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 continue?? (0:No, stop the game. 1:Yes, play again.) ”
c_bkt: .asciiz “)\n ” comma:.asciiz “,” space: .asciiz””
Last Revised 3/4/2021 Page 1 of 4

newline:.asciiz “\n”
.text main:
# Print “Please enter a number: \n”
la $a0, msg addi $v0, $0, 4 syscall
# Get the seed from the user and store in seed
addi $v0, $0, 5 syscall
sw $v0, seed
#————————————————————————– #
# Write your code here
# #————————————————————————–
# Terminate the program
addi $v0, $0, 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 jr $ra
# 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 #-------------------------------------------------------------------------- - #-------------------------------------------------------------------------- # # Write function(s) here (if any) # #-------------------------------------------------------------------------- #-------------------------------------------------------------------------- - # function for generating random number (0 – 9), return in $v0 randnum:addi $sp, $sp, -8 # adjust the stack pointer Last Revised 3/4/2021 Page 2 of 4 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 # 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 #------------------------------------------------------------------------------ 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, stop the game. 1:Yes, play again.) 2 Wrong message! Please enter either (0) or (1)!!!! Do you want to EXIT?? (0:No, stop the game. 1:Yes, play again.) 1 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!!! (6,2) Do you want to EXIT?? (0:No, stop the game. 1:Yes, play again.) 0 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. Last Revised 3/4/2021 Page 3 of 4 Project submission 1. Program submission. (file extension: “.s”)  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 on or before the deadline. 2. Make sure your program can be assembled before submission or NO marks will be given. Rubric Correctness (60 pts) Readability (5 pts) Documentation (5 pts) Code Efficiency (30 pts) Excellent Works correctly for all inputs Extremely easy to follow and well formatted with consistent use of indentation and whitespace. Precisely documented to show the usages of registers, the control flow, purposes of sections of codes, etc. Small size and extremely efficient without using pseudo instructions except la. No unnecessary use of registers and instructions. Good Works for most of the inputs. Easy to read. Only minor issues with consistent use of indentation and whitespace. Documented to show the usages registers and purposes of instructions, but the flow of control is not explicitly mentioned. Mostly efficient without using pseudo instructions except la. Some improvements could be made by better use of registers and instructions. Satisfactory Works for some inputs only. Readable only with effort. Limited indentation and whitespace. Documented but comments are either a bit too simple or too long even they are correct. Flow control is not mentioned at all. Marginally efficient and significant improvements could be made through efficient use of registers and better choices of instructions. Unsatisfactory Only functions correctly in limited cases or not at all. Poorly organized and difficult to read. Poorly documented and comments are either minimal or too long. Some comments are incorrect. Poor implementation and unnecessarily long. Use instructions and registers redundantly. Last Revised 3/4/2021 Page 4 of 4