1. Homepage
  2. Programming
  3. DPST1092 Computer Systems Fundamentals - Assignment 1: Breakout in MIPS

DPST1092 Computer Systems Fundamentals - Assignment 1: Breakout in MIPS

Engage in a Conversation
UNSWDPST1092Computer Systems FundamentalsBreakout in MIPSMIPS

Assignment 1: Breakout in MIPS

version: 1.0 last updated: 2024-09-20 12:00:00 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 breakout, change to this directory, and fetch the provided code by running these commands: CourseNana.COM

mkdir -m 700 breakout
cd breakout
1092 fetch breakout

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

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

Breakout: The Game

1092 mipsy breakout.s
Welcome to 1092 breakout! In this game you control a paddle (---) with
the a and d (or A and D for fast movement) keys, and your goal is
to bounce the ball (*) off of the bricks (digits). Every ten bricks
destroyed spawns an extra ball. The . key will advance time one step.

Enter the width of the playing field: 12

 SCORE: 0
==============
|            |
|            |
|000111222333|
|000111222333|
|000111222333|
|000111222333|
|000111222333|
|000111222333|
|            |
|            |
|      *     |
|   ------   |
 >> ;
 SCORE: 5
==============
|            |
|            |
|000111222333|
|000111222333|
|000111222333|
|000111222333|
|000111222333|
|000   222333|
|     *      |
|            |
|            |
|   ------   |
 >> q

breakout.c is an implementation of a version of Breakout, a popular and influential video game. CourseNana.COM

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

A game of Breakout takes place on a 2D grid, where the player must move a paddle to bounce a ball (*) into a group of bricks (digits). CourseNana.COM

You can move the paddle left (a and A) and right (d and D). CourseNana.COM

Hitting bricks with the ball will destory the bricks, and reward the player with score points. Every 10 bricks destroyed will spawn a new ball, with up to 3 balls on the screen at any given time. CourseNana.COM

If a ball leaves the bottom of the screen then it is destroyed, and if there are no more balls left the game ends. CourseNana.COM

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

dcc breakout.c -o breakout
./breakout

You should read through breakout.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

breakout.s: The Assignment

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

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

The functions run_commandprint_deubg_info and print_screen_updates have already been translated to MIPS assembly for you. CourseNana.COM

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

  • print_welcome
  • main
  • read_grid_width
  • game_loop
  • initialise_game
  • move_paddle
  • count_total_active_balls
  • print_cell
  • register_screen_update
  • count_balls_at_coordinate
  • print_game
  • spawn_new_ball
  • move_balls
  • move_ball_in_axis
  • hit_brick
  • check_ball_paddle_collision
  • move_ball_one_cell

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
  • print_welcome
  • main
10%
Subset 1
  • read_grid_width
  • game_loop
  • initialise_game
  • move_paddle
  • count_total_active_balls
  • print_cell
45%
Subset 2
  • register_screen_update
  • count_balls_at_coordinate
  • print_game
  • spawn_new_ball
  • move_balls
25%
Subset 3
  • move_ball_in_axis
  • hit_brick
  • check_ball_paddle_collision
  • move_ball_one_cell
20%

Commands

The run_command function calls various other functions. 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 called
aMove the paddle one cell leftmove_paddle
dMove the paddle one cell rightmove_paddle
AMove the paddle three cells leftmove_paddle
DMove the paddle three cells rightmove_paddle
.Simulate the movement of the ball(s)move_balls
;Simulate the movement of the ball(s) for 3 stepsmove_balls
,Simulate the movement of the ball(s) for ⅓ of a stepmove_balls
?Output the internal state of the gameprint_debug_info
hOutput the welcome messageprint_welcome
sOutput changes to the screen (used by play-breakout)print_screen_updates
pPrint the game, and turn off auto-printingprint_game
qQuit the game

Running & Testing

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

1092 mipsy breakout.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 breakout.c -o breakout
cat input.txt | ./breakout | tee c.out
cat input.txt | 1092 mipsy breakout.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 print_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 run_commandprint_debug_info and print_screen_updates function implementations 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 breakout.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

1092 autotest breakout.simple

An example game of Breakout

Assumptions, Clarifications, and Restrictions

  • Like all good programmers, you should make as few assumptions as possible. CourseNana.COM

  • 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. CourseNana.COM

  • You may not copy a solution from an online source. e.g. Github. CourseNana.COM

  • Your functions will be tested individually. They must exactly match the behaviour of the corresponding C function and they must follow MIPS calling conventions. CourseNana.COM

  • The C code defines constants using #define. Your MIPS translation should use the corresponding provided named constants, in the places where a #define is used in the C code. You should not use a #define constant in your MIPS translation if it is not used in the corresponding part of the C code. CourseNana.COM

  • There will be a correctness penalty for assignments that do not follow standard MIPS calling conventions including: CourseNana.COM

    • Function arguments are passed in registers $a0..$a3. CourseNana.COM

    • Function return values are passed in register $v0 CourseNana.COM

    • Values in registers $s0..$s7 are preserved across function calls.
      If a function changes these registers, it must restore the original value before returning. CourseNana.COM

    • The only registers' values that can be relied upon across a function call are $s0..$s7$gp$sp, and $fp.
      All other registers must be assumed to be have, an undefined value after a function call, except $v0 which has the function return value. CourseNana.COM

  • If you need clarification on what you can and cannot use or do for this assignment, ask in the class forum. CourseNana.COM

  • You are required to submit intermediate versions of your assignment. See below for details. CourseNana.COM

Breakout wrapper

If you complete this assignment, you may notice that the finished game is not particularly fun to play. To make the game more interesting to play, you can run a wrapper script that adds extra functionality to your MIPS translation. In a directory which contains your completed breakout.s, run: CourseNana.COM

1092 play-breakout 60

CourseNana.COM

You can change the parameter 60 to other numbers for different grid widths. You can also optionally supply another parameter slowmedium (which is the default), fast or increasing to alter the game speed. For example, this will start a game with fast speed and a grid width of 42: CourseNana.COM

1092 play-breakout 42 fast

CourseNana.COM

This adds colour and automatic time progression amongst other things. Inputs from the set aAdD are recognised. You may need to experiment with which terminal you use as well as terminal size to get the best playing experience. Note that this wrapper is just for fun, there are no marks associated with whether or not your translation works with the wrapper script. CourseNana.COM


Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
UNSW代写,DPST1092代写,Computer Systems Fundamentals代写,Breakout in MIPS代写,MIPS代写,UNSW代编,DPST1092代编,Computer Systems Fundamentals代编,Breakout in MIPS代编,MIPS代编,UNSW代考,DPST1092代考,Computer Systems Fundamentals代考,Breakout in MIPS代考,MIPS代考,UNSWhelp,DPST1092help,Computer Systems Fundamentalshelp,Breakout in MIPShelp,MIPShelp,UNSW作业代写,DPST1092作业代写,Computer Systems Fundamentals作业代写,Breakout in MIPS作业代写,MIPS作业代写,UNSW编程代写,DPST1092编程代写,Computer Systems Fundamentals编程代写,Breakout in MIPS编程代写,MIPS编程代写,UNSWprogramming help,DPST1092programming help,Computer Systems Fundamentalsprogramming help,Breakout in MIPSprogramming help,MIPSprogramming help,UNSWassignment help,DPST1092assignment help,Computer Systems Fundamentalsassignment help,Breakout in MIPSassignment help,MIPSassignment help,UNSWsolution,DPST1092solution,Computer Systems Fundamentalssolution,Breakout in MIPSsolution,MIPSsolution,