CS计算机代考程序代写 scheme mips assembly 7/22/2021 COMP1521 21T2 ¡ª Assignment 1: snake, Snake!

7/22/2021 COMP1521 21T2 ¡ª Assignment 1: snake, Snake!
$ mkdir snake
$ cd snake
$ 1521 fetch snake
Assignment 1: snake, Snake!
Aims
to give you experience writing MIPS assembly code
to give you experience with data and control structures in MIPS
Getting Started
Create a new directory for this assignment called snake, change to this directory, and fetch the provided code by running these commands:
If you’re not working at CSE, you can download the provided files as a zip file or a tar file. This will add the following files into the directory:
snake.c: an implementation of Snake in C, and snake.s: a stub assembly file to complete.
snake.c: Snake!
snake.c is an implementation of the classic video game Snake!
The starting state of a game to the right, where you can see all the key parts of the game. Snake is played on a 15¡Á15 grid. The snake is made up of a head (#), and a number of body segments (o), and can move around the grid.
When the user enters one of w , a , s , or d , the snake will move one step on the grid either north, west, south, or east, respectively. The snake won’t move if the requested direction is where the first non-head segment is.
Also on the grid: apples! Snakes like apples[citation needed] so, if the snake’s head moves over an apple (denoted @), the snake consumes it, and gains three segments over the next three moves. If there’s no apple on the grid, a new one is added in a random empty cell.
The game ends only when either the snake falls off one of the edges of the board, or the snake runs into its own body ¡ª as the snake’s length increases, not falling off the board or running into itself become increasingly tricky!
To get a feel for this game, try it out in a terminal:
After you type your move, you will need to press enter. This is a rather curious quirk of the way terminals work. You could also try something like this incantation (although it may also badly upset your terminal) if you would like to try something more interactive:
You should read through snake.c. There are comments throughout it which should help you understand what the program is doing ¡ª which you’ll need for the next part of the assignment.
snake.s: The Assignment
Your task in this assignment is to implement snake.s in MIPS assembly.
You have been provided with some assembly and some helpful information in snake.s. Read through the provided code carefully, then
add MIPS assembly so it executes exactly the same as snake.c.
A handful of utility functions have already been translated to MIPS assembly for you. You only have to implement the following
unfinished functions in MIPS assembly:
main,
init_snake, update_apple, update_snake, move_snake_in_grid, and move snake in array
version: 1.0.1 last updated: 2021-07-09 17:30:00
.@…………. …………… …………… …………… …………… …………… …………… ….ooo#……. …………… …………… …………… …………… …………… …………… ……………
$ dcc snake.c -o snake $ ./snake
$ stty -echo -icanon min 1; ./snake; stty sane
https://cgi.cse.unsw.edu.au/~cs1521/21T2/assignments/ass1/index.html
1/4

7/22/2021 _ _ _ y COMP1521 21T2 ¡ª Assignment 1: snake, Snake!
To test your implementation, you can compile the provided C implementation, run it to collect the expected output, run your assembly implementation to collect observed output, and then compare them ¡ª for example:
Try this for different sequences of input moves.
You may find that relying on Autotest is not as helpful in this assignment, although there are some checks to ensure your code is OK. Prefer running your code in SPIM or in QtSPIM.
Hints
You may find it easier to implement the smaller functions before moving onto the larger ones. SPIM supports defining constants somewhat like #define in C. The syntax is a bit different:
Take careful note of the types of each global variable. For int8_t types, you will need to use the LB and SB instructions. For int types, you will need to use the LW and SW instructions.
Assumptions and Clarifications
Like all good programmers, you should make as few assumptions as possible.
Your submitted code must be hand-written MIPS assembly, which you yourself have written. You may not submit code in other languages. You may not submit compiled output.
You may not copy a solution from an online source (e.g., Github).
There will be a correctness penalty for assignments that do not use the stack to save and restore $ra.
There will be a correctness penalty for assignments that do not follow these important MIPS calling conventions:
that function arguments shall be passed in registers $a0…$a3;
that values in registers $s0…$s9 shall be preserved across function calls: if a function changes these registers, it must restore the original value before returning.
If you need clarification on what you can and cannot use or do for this assignment, ask in the class forum. You are required to submit intermediate versions of your assignment. See below for details.
Testing
When you think your program is working, you can use autotest to run some simple automated tests: 1521 autotest will not test everything.
Always do your own testing.
Automarking will be run by the lecturer after the submission deadline, using a superset of tests to those autotest runs for you.
Submission
When you are finished working on the assignment, you must submit your work by running give:
You must run give before Week 7 Thursday 21:00:00 to obtain the marks for this assignment. Note that this is an individual exercise,
the work you submit with give must be entirely your own. You can run give multiple times.
Only your last submission will be marked.
If you are working at home, you may find it more convenient to upload your work via give’s web interface. You cannot obtain marks by e-mailing your code to tutors or lecturers.
You can check your latest submission on CSE servers with:
$ dcc snake.c -o snake
$ echo “wwwwwwwaaaaaa” > input
$ cat input | ./snake | tee c.out
$ cat input | 1521 spim -f snake.s | tee mips.out $ diff -s c.out mips.out
Files c.out and mips.out are identical
N_COLS
N_ROWS
MAX_SNAKE_LEN
= 15
= 15
= N_COLS * N_ROWS
Assessment
$ 1521 autotest snake snake.s
$ give cs1521 ass1_snake snake.s
https://cgi.cse.unsw.edu.au/~cs1521/21T2/assignments/ass1/index.html
2/4

7/22/2021 COMP1521 21T2 ¡ª Assignment 1: snake, Snake!
You can check your latest submission on CSE servers with:
$ 1521 classrun check ass1_snake
You can check the files you have submitted here.
Manual marking will be done by your tutor, who will mark for style and readability, as described in the Assessment section below. After
your tutor has assessed your work, you can view your results here; The resulting mark will also be available via give’s web interface.
Due Date
This assignment is due Week 7 Thursday 21:00:00.
If your assignment is submitted after this date, each hour it is late reduces the maximum mark it can achieve by 2%. For example, if an assignment worth 74% was submitted 10 hours late, the late submission would have no effect. If the same assignment was submitted 15 hours late, it would be awarded 70%, the maximum mark it can achieve at that time.
Assessment Scheme
This assignment will contribute 15 marks to your final COMP1521 mark.
80% of the marks for assignment 1 will come from the performance of your code on a large series of tests.
20% of the marks for assignment 1 will come from hand marking. These marks will be awarded on the basis of clarity, commenting, elegance and style. In other words, you will be assessed on how easy it is for a human to read and understand your program.
An indicative assessment scheme follows. The lecturer may vary the assessment scheme after inspecting the assignment submissions, but it is likely to be broadly similar to the following:
HD (85+) DN (75+) CR (65+) PS (50-60) 0%
0 FL for COMP1521
academic misconduct
beautiful, clearly-documented code; implements all behaviour perfectly very readable code; implements most behaviour perfectly
readable code; some correctly-implemented behaviours
good progress, but not passing autotests
knowingly providing your work to anyone and it is subsequently submitted (by anyone).
submitting any other person’s work; this includes joint work.
submitting another person’s work without their consent; paying another person to do work for you.
Intermediate Versions of Work
You are required to submit intermediate versions of your assignment.
Every time you work on the assignment and make some progress you should copy your work to your CSE account and submit it using the give command below. It is fine if intermediate versions do not compile or otherwise fail submission tests. Only the final submitted version of your assignment will be marked.
Attribution of Work
This is an individual assignment.
The work you submit must be entirely your own work, apart from any exceptions explicitly included in the assignment specification above. Submission of work partially or completely derived from any other person or jointly written with any other person is not permitted.
You are only permitted to request help with the assignment in the course forum, help sessions, or from the teaching staff (the lecturer(s) and tutors) of COMP1521.
Do not provide or show your assignment work to any other person (including by posting it on the forum), apart from the teaching staff of COMP1521. If you knowingly provide or show your assignment work to another person for any reason, and work derived from it is submitted, you may be penalized, even if that work was submitted without your knowledge or consent; this may apply even if your work is submitted by a third party unknown to you. You will not be penalized if your work is taken without your consent or knowledge.
Do not place your assignment work in online repositories such as github or any where else that is publically accessible. You may use a private repository.
Submissions that violate these conditions will be penalised. Penalties may include negative marks, automatic failure of the course, and possibly other academic discipline. We are also required to report acts of plagiarism or other student misconduct: if students involved hold scholarships, this may result in a loss of the scholarship. This may also result in the loss of a student visa.
Assignment submissions will be examined, both automatically and manually, for such submissions.
https://cgi.cse.unsw.edu.au/~cs1521/21T2/assignments/ass1/index.html
3/4

7/22/2021 COMP1521 21T2 ¡ª Assignment 1: snake, Snake!
Change Log
Version 1.0
(2021-06-28 11:00:00)
Version 1.0.1
(2021-07-09 17:30:00)
Initial release onto unsuspecting students.
No functional change.
Git repositories are not created for this assignment.
COMP1521 21T2: Computer Systems Fundamentals is brought to you by the School of Computer Science and Engineering
at the University of New South Wales, Sydney.
For all enquiries, please email the class account at cs1521@cse.unsw.edu.au CRICOS Provider 00098G
https://cgi.cse.unsw.edu.au/~cs1521/21T2/assignments/ass1/index.html
4/4