LINKED LIST

CS 318
Due:
Weight:
P RO J E C T 2
Thursday, April 9
4
LINKED LIST
Description & Objectives
Write a MIPS program that manages a linked list of nodes whose data are strings. The
console is used for input/output (no dialog windows).
The objective is proper allocation of memory and use of pointers to maintain a linked list.
The use of a menu to drive the program forms the main interface with the user. Use of functions
is important and the use of registers must follow the calling convention.
Collaboration
Each student is expected to do his/her own work unless otherwise instructed. There is to be no
sharing of code.
Preparation & Submittal
Creating the project: Names
File name: <username>2.asm
e.g. jsmith2.asm
Preparing the project
Use Mars to write and test the program.
Submitting
When the project is done, attach the file to an email to your instructor, [email protected]. Your
instructor will return an acknowledgement email. If you do not get one in a reasonable amount of time,
resend the project or contact the instructor.
Specifications - details
Use Case (how the program behaves from the user’s perspective)
When the program begins, the user interface is output. The interface always includes the string stored
in the current node followed by the action menu. If the list is empty (as it will be at the start), then instead
of the current node’s string being displayed, a simple message tells the user that the list is empty.
The action menu lists the following options for the user to choose from.
• Exit the program
• Insert a string after the current node or at the front if the list is empty. Current is redefined as the
new node.
• Redefine the current node as the next node, if one exists. (Allows user to traverse the list.)
• Redefine the current node as the previous node, if one exists.
• Delete the current node (Do nothing if list is empty.) Decide how to redefine current.
• Reset current as the first node in the list, if the list is not empty.
• Debug - output all strings starting with the first one node. This is useful when debugging code.
Current is unchanged once this operation is complete.
1
For example, the current node string and menu (the user interface) may be displayed as follows:
current string: Mary Smith
Menu:
e - exit
i - insert new string
n - next node
…
When inserting a new string, a new node is created (along with allocated memory for storing the
string) and attached to the list following the current node. Then current is redefined to point to the new
node.
The Debug option may output additional information if desired. But it must traverse the list and
output each string, one per line.
Program Structure (implementation requirements)
The design of the linked list is left to the programmer, but it must involve nodes that have one or more
pointers to other nodes. To manage the list, there must be at least two “external” pointers into the list, first
(points to the first node or null if the list is empty), and current (points to a specific node in the list or is
null and is controlled by the user). If needed, the program can use additional external pointers.
Because the program involves a number of tasks and subtasks, it should rely on functions to break
down the code into manageable units. Proper use of registers for passing parameters and returning values
is required - follow the calling convention introduced in class. Review the notes at the course MIPS
website that cover the use of memory allocation to create nodes and pointers.
Planning
It’s best to build the project in stages and test it at each stage. Here are some ideas…
Begin with the main menu. The main procedure might include a loop with the menu inside. To test
this part, get the user menu choice and for each choice, output a simple message to the console. For
example, if “i” is chosen, print this to the console. Once you know the menu is working. Then for one of
the choices replace the test output code with a procedure call to handle the operation, unless the task is
short enough to be done within the menu code.
Exiting the program might be the first piece of code to write. Inserting a new string and performing
the debug task might be done next. This lets you test building a list and verifying that the strings are in the
right order.
Test the code for each procedure before going to the next one. Also, if one procedure is expected to be
long, consider having it call sub procedures to break up the code into manageable units. Also be sure to
adhere to the calling convention we have studied (use the right registers for the right job, and apply the
convention to properly use them).
Documentation and formatting
2
The assembly file must include appropriate documentation, this includes author name and short
description at the top of the file. Include function description, parameters and return value in a comment
for each function. In addition use line or section comments to help the reader understand what is going
on where necessary.
Formatting code so that its appearance makes reading easy is important. Proper indentation of code
blocks and comments and use of white space around comments are very important. Make it easy for the
reader!
Checklist
•
•
•
•
•
•
Your name and short description of the project. Functions have a description, params, return.
Be sure the code is well formatted and documented.
Use console I/O.
Allocate memory for each node and for each string. Keep track of addresses used by pointers.
Include first and current pointers, but other external pointers may be used. Nodes have at least
one pointer (to the next node).
The menu lets the user perform the tasks listed above.
Use functions to break code into units and adhere to the passing convention.
Grading
The grade will usually be determined by the following
•
•
•
Documentation and formatting.
Adherence to these specs (be sure your program adheres to all the items described above).
Correctness (correct code - i.e. no bugs , correct use of topics introduced in the lectures/textbook.
correct program design, mature code appropriate for the course level).
There is 5% penalty per day for late projects.
No late projects will be accepted after three days.
If you are unable to finish, submit what you have done for partial credit. You can resubmit your file
whenever you want as long as it is not late. Be sure to see or email your instructor if you have questions or
problems.
3