Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Programming Project
Important Information about CSE 220 Programming Projects
Read the entire project description document twice before starting. Questions posted on Piazza whose
answers are clearly stated in the documents will be given lowest priority by the course staff.
When writing assembly code, try to stay consistent with your formatting and to comment as much as
possible. It is much easier for your TAs and the professor to help you if we can quickly figure out what your
code does.
You personally must implement the projects in MIPS Assembly language by yourself. You may not write
or use a code generator or other tools that write any MIPS code for you. You must manually write all MIPS
assembly code you submit as part of the assignments.
Do not copy or share code. Your submissions will be checked against other submissions from this semester
and from previous semesters.
You must use the Stony Brook version of MARS posted on Piazza. Do not use the version of MARS posted
on the official MARS website. The Stony Brook version has a reduced instruction set, added tools, and
additional system calls you will need to complete the programming projects.
Submit your final .asm file to Blackboard by the due date and time. Late work will not be accepted or
graded. Code that crashes and cannot be graded will earn no credit. No changes to your submission will be
permitted once the deadline has passed.
How Your CSE 220 Assignments Will Be Graded
With minor exceptions, all aspects of your programming assignments will be graded entirely through automated
means. Grading scripts will execute your code with input values (e.g., command-line arguments, function arguments)
and will check for expected results (e.g., print-outs, return values, etc.) For Programming Project #1, your
program will be generating output that will be checked for exact matches by the grading scripts. Therefore, it is
imperative that you implement the “print statements” exactly as specified in the assignment.
Some other items you should be aware of:
All test cases must execute in 100,000 instructions or fewer. Efficiency is an important aspect of programming.
This maximum instruction count will be increased in cases where a complicated algorithm might be
necessary, or a large data structure must be traversed. To find the instruction count of your code in Mars,
go to the Tools menu and select Instruction Statistics. Press the button marked Connect to MIPS. Then
assemble and run your code as normal.
Any excess output from your program (debugging notes, etc.) will impact grading. Do not leave erroneous
CSE 220 – Spring 2019 Programming Project #1 1
print-outs in your code.
We will provide you with a small set of test cases for each assignment to give you a sense of how your work
will be graded. It is your responsibility to test your code thoroughly by creating your own test cases.
The testing framework we use for grading your work will not be released, but the test cases and expected
results used for testing will be released.
Learning Outcomes
After completion of this programming project you should be able to:
Use system calls to print values to the screen in different formats.
Design and implement algorithms in MIPS assembly that involve if-statements and counter-driven loops.
Read and write values stored in a MIPS assembly .data section.
Use bitwise operations to perform simple computations in MIPS assembly.
Getting Started
Visit Piazza and download the files proj1.asm and MarsSpring2019.jar. Fill in the following information
at the top of proj1.asm:
1. your first and last name as they appear in Blackboard
2. your Net ID (e.g., jsmith)
3. your Stony Brook ID # (e.g., 111999999)
Having this information at the top of the file helps us locate your work. If you forget to include this information
but don’t remember until after the deadline has passed, don’t worry about it – we will track down your submission.
Inside proj1.asm you will find some code to start with. Your job in this assignment is implement all the
operations as specified below. If you are having difficulty implementing these operations, write out pseudocode
or implement the algorithms in a higher-level language first. Once you understand the algorithm and what steps
to perform, then translate the logic to MIPS assembly code.
Configuring MARS for Command-line Arguments
Your program is going to accept command-line arguments, which will be provided as input to the program. To
tell MARS that we wish to accept command-line arguments, we must go to the Settings menu and check the box
marked:
Program arguments provided to the MIPS program
While you’re at it, also check the box marked:
Initialize Program Counter to global ‘main’ if defined
After assembling your program, in the Execute tab you should see a text box where you can type in your
command-line arguments before running the program:
CSE 220 – Spring 2019 Programming Project #1 2
The command-line arguments must be separated by spaces. Note that your program must always be run with
at least one command-line argument. When your program is assembled and then run, the arguments to your
program are placed in main memory before execution. Information about the arguments is then provided to your
code using the argument registers, $a0 and $a1. The $a0 register contains the number of arguments passed to
your program. The $a1 register contains the starting address of an array of strings. Each element in the array is
the starting address of the argument specified on the command-line.
All arguments are saved in memory as ASCII character strings, terminated by the null character (ASCII 0, which
is denoted by the character ‘\0’ in assembly code). So, for example, if we want to read an integer argument on
the command-line, we actually must take it as a string of digit characters (e.g., "2034") and then convert it to an
integer ourselves in assembly code. We have provided code for you that stores the addresses of the command-line
arguments at pre-defined, unique labels (e.g., addr arg0, addr arg1, etc.) Note that the strings themselves
are not stored at these labels. Rather, the starting addresses of the strings are stored at those labels. You will need
to use load instructions to obtain the contents of these strings stored at the addresses: lw to load the address of a
string, then multiple lbu instructions to get the characters.
Running the Program
Running the provided proj1.asm file is pretty simple. Hit F3 on the keyboard or press the button shown below
to assemble your code:
If your code has any syntax errors, MARS will report them in the Mars Messages panel at the bottom of the
window. Fix any syntax errors you may have. Then press F5 or hit the Run button shown below to run your
program:
Any output generated by your program will appear in the Run I/O panel at the bottom of the window.
Part I: Validate the First Command-line Argument and the Number of Command-line
Arguments
For this assignment you will be implementing several operations that perform computations and do data manipulation.
In proj1.asm, begin writing your program immediately after the label called start coding here.
CSE 220 – Spring 2019 Programming Project #1 3
You may declare more items in the .data section after the provided code. Any code that has already been
provided must appear exactly as defined in the given file. Do not remove or rename these labels, as doing so will
negatively impact grading.
The number of arguments is stored in memory at the label num args by code already provided for you. You will
need to use various system calls to print values that your code generates. For example, to print an string in MIPS,
you need to use system call 4. You can find a listing of all the official MARS system calls on the MARS website.
You can also find the documentation for all instructions and supported system calls within MARS itself. Click the
in the right-hand end of tool bar to open it.
Later in the document is a list of the operations that your program will execute. Each operation is identified by
a single character. The character is given by the first command-line argument (whose address is addr arg0).
The parameter(s) to each argument are given as the remaining command-line arguments (located at addresses
addr arg1, addr arg2, etc.). Not all operations expect the same number of parameters. In this first part of
the assignment your program must make sure that each operation is valid and has been given the correct number
of parameters. Perform the validations in the following order:
1. The first command-line argument must be a string of length one that consists of one of the following characters:
2, S, L, D or A. If the argument is a letter, it must be given in uppercase. If the argument is not one
of these strings, print the string found at label invalid operation error and exit the program (via
system call #10). This string contains a newline character at the end, so you do not need to provide your
own.
2. If the first command-line argument is 2, S,L or D then there must be exactly one other argument. If the total
number of command-line arguments is not two, print the string found at label invalid args error and
exit the program (via system call #10). This string contains a newline character at the end, so you do not
need to provide your own.