关键词 > COMP1521
COMP1521 Assignment 1: Flood in MIPS
发布时间:2025-07-01
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
COMP1521 25T2: Computer Systems Fundamentals
Assignment 1: Flood in MIPS
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 calledflood, change to this directory, and fetch the provided code by running these commands:
$ mkdir -m 700 flood
$ cd flood
$ 1521 fetch flood
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.
flood.s : a stub MIPS assembly file to complete.
flood.c : a reference implementation of flood in C.
flood. simple.c : a copy of the reference implementation of flood, for you to simplify.
input.txt :example input file.
flood.mk: a moke fragment for compiling flood.c.
Flood: The Game
Flood is an implementation of Simon Tatham's Flood, a game where players fill a coloured grid with repeated flood-fill operations on the top left cell.
The provided C program (and eventually, your MIPS translation) implement the following commands:
w/a/s/d move the selected cell up/left/down/right.
h prints instructions.
e performs a flood fill.
c prints a (relatively) optimal solution.
q exits flood.
Flood is won when the grid is all the same colour.
Flood is lost if you run out of steps.
The number of allowed steps is chosen based on an optimal solution, with a few extra to make the game a bit easier.
To get a feel for this game, try it out in a terminal:
$ dcc flood.c -o floods
$ ./flood
You should read through flood.c. There are comments throughout it that should help you understand what the program is doing -which you'll need for the next part of the assignment.
flood.s: The Assignment
Your task in the assignment is to translate the provided flood.cprogram into MIPS assembly.
You have to add code to the provided flood.s file so that it executes exactly the same as flood.c.
Any modifications to the .data section are NOT PERMITTED, and will break autotest.
All global variables and strings are already present in the provided .data section.
You have to implement the following functions in MIPS assembly:
main
print_welcome
in_bounds
game_loop
initialise_game
game_finished
do_fill
initialise_board
initialise_fill_in_progress
find_optimal_solutior
invalid_step
print_optimal_solutior
rate_choice
find_adjacent_cells
fill
solve_next_step
copy_mem
The following functions have already been translated to MIPS assembly for you:
random_in_range
initialise_solver
simulate_step
initialise_solver_adjacent_cells
print_board
print_board_bottom
print_board_row
print_board_inner_line
print_board_seperator_line
process_command
You MUST obey the MIPS calling conventions discussed in lectures.
When translating functions calls, you should avoid making assumptions about any side effects of the called function.
If you make assumptions about the behaviour of called functions that are not made in the provided C implementation, you may be penalised.
