1. Homepage
  2. Programming
  3. COMP1521 Computer Systems Fundamentals - Assignment 1: Tetris in MIPS

COMP1521 Computer Systems Fundamentals - Assignment 1: Tetris in MIPS

Engage in a Conversation
UNSWCOMP1521CS1521Computer Systems FundamentalsTetris in MIPSMIPSC

Assignment 1: Tetris in MIPS


CourseNana.COM

Aims

  • to give you experience writing MIPS assembly code
  • to give you experience translating C to MIPS
  • to give you experience with data and control structures in MIPS

Getting Started

Create a new directory for this assignment called tetris, change to this directory, and fetch the provided code by running these commands: CourseNana.COM

mkdir -m 700 tetris
cd tetris
1521 fetch tetris

If you're not working at CSE, you can download the provided files as a zip file or a tar file. CourseNana.COM

This will add the following files into the directory: CourseNana.COM

  • tetris.s: a stub MIPS assembly file to complete.
  • tetris.c: a reference implementation of Tetris in C.
  • tetris.simple.c: a copy of the reference implementation of Tetris, for you to simplify.
  • input.txt: example input file.
  • tetris.mk: a make fragment for compiling tetris.c.

Tetris: The Game

1521 mipsy tetris.s
Welcome to 1521 tetris!

/= Field =\    SCORE: 0
|   IIII  |
|         |     NEXT: J
|         |
|         |
  -- CUT --
|         |
|         |
\=========/
  > S
A new piece has appeared: J

/= Field =\    SCORE: 0
|   J     |
|   JJJ   |     NEXT: L
|         |
|         |
  -- CUT --
|         |
|   IIII  |
\=========/
  > q
Quitting...

Goodbye!

tetris.c is an implementation of Tetris, a widespread and popular video game. CourseNana.COM

An example game of Tetris can be seen to the right. CourseNana.COM

A game of Tetris takes place on a 2D field, where the player must fit together descending shapes to make lines. CourseNana.COM

You can move a piece left (a) and right (d), drop it down (one step with s or all the way with S), and rotate it (r and R). CourseNana.COM

Once a piece hits the bottom, another piece will appear at the top of the field. CourseNana.COM

Any horizontal lines in the field that become completely filled will be cleared, and points will be awarded to the player's score based on how many lines are cleared at the same time. CourseNana.COM

To get a feel for this game, try it out in a terminal: CourseNana.COM

dcc tetris.c -o tetris
./tetris

You should read through tetris.c. There are comments throughout it that should help you understand what the program is doing [citation needed] — which you'll need for the next part of the assignment. CourseNana.COM

tetris.s: The Assignment

Your task in this assignment is to implement tetris.s in MIPS assembly. CourseNana.COM

You have been provided with some assembly and some helpful information in tetris.s. Read through the provided code carefully, then add MIPS assembly so it executes exactly the same as tetris.c. CourseNana.COM

The functions show_debug_infogame_loop and read_char have already been translated to MIPS assembly for you. CourseNana.COM

You have to implement the following functions in MIPS assembly: CourseNana.COM

  • main
  • rotate_left
  • move_piece
  • compute_points_for_line
  • setup_field
  • choose_next_shape
  • print_field
  • piece_hit_test
  • piece_intersects_field
  • rotate_right
  • place_piece
  • new_piece
  • consume_lines

CourseNana.COM

You must translate each function separately to MIPS assembler, following the standard calling conventions used in lectures. When translating a function, you must not make any assumptions about the behaviour or side effects of any other function which is called. CourseNana.COM

Subsets

This assignment is split into four subsets. Later subsets will involve more complex translation. CourseNana.COM

SubsetFunctionsPerformance Weight
Subset 0
  • main
  • rotate_left
  • move_piece
35%
Subset 1
  • compute_points_for_line
  • setup_field
  • choose_next_shape
25%
Subset 2
  • print_field
  • piece_hit_test
  • piece_intersects_field
  • rotate_right
25%
Subset 3
  • place_piece
  • new_piece
  • consume_lines
15%

Commands

The game_loop calls various other functions by handling commands from the player. When translating you should follow the exact behaviour of the C code, however when testing you may find it useful to consult the following table of commands. CourseNana.COM


CommandDescriptionFunction(s) called
rRotate the current piece clockwise
  • rotate_right
  • piece_intersects_field
  • rotate_left
RRotate the current piece counter-clockwise
  • rotate_right
  • piece_intersects_field
  • rotate_left
nRemove the current piece and add a new one at the top of the field
  • new_piece
sMove the current piece down one row.
  • move_piece
  • place_piece
SDrop the current piece to the bottom of the field
  • move_piece
  • place_piece
aMove the current piece to the left by one column
  • move_piece
dMove the current piece to the right by one column
  • move_piece
pPlace the current piece into the field
  • place_piece
cAllow the player to choose which piece will drop next
  • choose_next_shape
?Output the current state of the game
  • show_debug_info
qQuit the game

Running & Testing

To run your MIPS code, simply enter the following in your terminal: CourseNana.COM

1521 mipsy tetris.s

Once you have finished your translation, 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. CourseNana.COM

The game takes a lot of input, so it's a good idea to write a file with the input you want to test, and then pipe that into your program. CourseNana.COM

You have been given a file called input.txt as an example. CourseNana.COM

dcc tetris.c -o tetris
cat input.txt | ./tetris | tee c.out
cat input.txt | 1521 mipsy tetris.s | tee mips.out
diff -s c.out mips.out
Files c.out and mips.out are identical

Try this for different sequences of inputs. When testing some functions you may find using the ? command (which calls show_debug_info) to be useful. CourseNana.COM

Hints

  • You should implement all the functions from one subset before moving on to the next. CourseNana.COM

  • You may find the provided show_debug_info and game_loop function implementation to be useful guidance for your implementation including comments, label names, indentation and register usage. CourseNana.COM

Simplified C code

You are encouraged to simplify your C code to remove any loop constructs and if-else statements, and test that your simplified code works correctly before translating it to MIPS, in a separate file tetris.simple.c. CourseNana.COM

This file will not be marked - you do not need to submit it. CourseNana.COM

In order to allow you to check that your simplified code works correctly, we have provided a simple set of automated tests. CourseNana.COM

You can run these tests by running the following command: CourseNana.COM

1521 autotest tetris.simple

An example game of Tetris

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
UNSW代写,COMP1521代写,CS1521代写,Computer Systems Fundamentals代写,Tetris in MIPS代写,MIPS代写,C代写,UNSW代编,COMP1521代编,CS1521代编,Computer Systems Fundamentals代编,Tetris in MIPS代编,MIPS代编,C代编,UNSW代考,COMP1521代考,CS1521代考,Computer Systems Fundamentals代考,Tetris in MIPS代考,MIPS代考,C代考,UNSWhelp,COMP1521help,CS1521help,Computer Systems Fundamentalshelp,Tetris in MIPShelp,MIPShelp,Chelp,UNSW作业代写,COMP1521作业代写,CS1521作业代写,Computer Systems Fundamentals作业代写,Tetris in MIPS作业代写,MIPS作业代写,C作业代写,UNSW编程代写,COMP1521编程代写,CS1521编程代写,Computer Systems Fundamentals编程代写,Tetris in MIPS编程代写,MIPS编程代写,C编程代写,UNSWprogramming help,COMP1521programming help,CS1521programming help,Computer Systems Fundamentalsprogramming help,Tetris in MIPSprogramming help,MIPSprogramming help,Cprogramming help,UNSWassignment help,COMP1521assignment help,CS1521assignment help,Computer Systems Fundamentalsassignment help,Tetris in MIPSassignment help,MIPSassignment help,Cassignment help,UNSWsolution,COMP1521solution,CS1521solution,Computer Systems Fundamentalssolution,Tetris in MIPSsolution,MIPSsolution,Csolution,