CSE 220: Systems Fundamentals


CSE 220: Systems Fundamentals I
Stony Brook University
Programming Project #1
Spring 2019
Assignment Due: Monday, February 25, 2019 by 11:59 pm
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.
3. If the first command-line argument is A, then there must be exactly four other arguments. If the total number
of command-line arguments is not five, print the string found at label invalid args error and exit the
program (via system call #10).
Important: You must use the provided invalid operation error and invalid args error strings
when printing error messages. Do not create your own labels for printing output to the screen. If your output is
marked as incorrect by the grading scripts because of typos, then it is your fault for not using the provided strings,
and you will lose all credit for those test cases. See page 1 for more details about how your work will be graded.
Be sure to initialize all of your values (e.g., registers) within your functions. Never assume registers or memory
will hold any particular values (e.g., zero). MARS initializes all of the registers and bytes of main memory to
zeroes. The grading scripts for later assignments will fill the registers and/or main memory with random values
before executing your code.
The following pages will explain how to validate the arguments to each operation.
Examples:
CSE 220 – Spring 2019 Programming Project #1 4
Command-line Arguments Expected Output
R 92831234 INVALID OPERATION
d AD87EF02 INVALID OPERATION
2G 8675309A INVALID OPERATION
2 192hF3?2 INVALID ARGS
S f00d11%4 INVALID ARGS
D feedme!! INVALID ARGS
L 124MOOTT X INVALID ARGS
A 829FE100 Y N INVALID ARGS
Character Strings in MIPS Assembly
In assembly, a string is a one-dimensional array of unsigned bytes. Therefore, to read each character of the string
we typically need to use a loop. Suppose that $s0 contains the base address of the string (that is, the address of
the first character of the string). We could use the instruction lbu $t0, 0($s0) to copy the first character of
the string into $t0. To get the next character of the string, we have two options: (i) add 1 to the contents of $s0
and then execute lbu $t0, 0($s0) again, or (ii) leave the contents of $s0 alone and execute lbu $t0,
1($s0). Generally speaking, the first approach is easier and simpler to use. Note that syntax like lbu $t0,
$t1($s0) is not valid; an immediate value (a constant) must be given outside the parentheses.
There is no length() function or method in assembly to tell us how long a string is. Therefore, if we don’t
know the number of characters in a string, we need a a loop which traverses a string until it reads the null character,
ASCII 0 (‘\0’). The null character denotes the end of the string in memory. For this assignment we will always
assume that the second command-line argument (args[1]) is always present and is always of length 8.
Next: Process the Input
If the program determines that the first command-line argument is a valid operation and that it has been given a
correct number of additional arguments, the program continues by executing the appropriate operation as specified
below. Note that you are permitted to add code to the .data section as necessary to implement these operations.
Part II: Interpret a String of Hexadecimal Digits as a Two’s Complement Number
First Argument: 2
Second Argument: a 32-bit two’s complement value encoded as a string of exactly 8 hexadecimal digit characters
The 2 operation treats the second command-line argument as a string of hexadecimal digit characters (‘0’ – ‘9’,
‘A’ – ‘F’) that represent a two’s-complement number. The leftmost character represents the most significant
nibble (4 bits) of the integer. The operation converts the string into a 32-bit integer, storing in a single register.
Using system call #1, the operation then prints the contents of the register in decimal, followed by a newline
character (‘\n’). Note that you can give an ASCII character as a literal in MIPS (e.g., li $a0, ‘\n’).
There are different algorithms you can devise to implement this operation. To get started, think of how you would
convert characters like ‘7’ and ‘D’ from the binary ASCII values 00110111 and 001000100, respectively,
to the binary values 0111 and 1101, respectively.
CSE 220 – Spring 2019 Programming Project #1 5
Input Validation:
The second command-line argument must consist only of characters that represent hexadecimal digits. If the
argument contains invalid characters, print the string found at label invalid args error and exit the program
(via system call #10). You may assume that the second command-line argument contains exactly 8 characters.
Examples:
Command-line Arguments Expected Output
2 0000002D 45
2 FFFFFFEE -18
2 FFFFFFFF -1
2 00000000 0
2 7FFFFFFF 2147483647
2 80000000 -2147483648
Part III: Interpret a String of Hexadecimal Digits as a Sign/Magnitude Number
First Argument: S
Second Argument: a 32-bit sign/magnitude value encoded as a string of exactly 8 hexadecimal digit characters
The S operation treats the second command-line argument as a string of hexadecimal digit characters (‘0’ – ‘9’,
‘A’ – ‘F’) that represent a sign/magnitude number. The leftmost character represents the most significant nibble
(4 bits) of the integer and contains the sign bit. The operation converts the string into a 32-bit, two’s complement
integer, storing in a single register. Using system call #1, the operation then prints the contents of the register in
decimal, followed by a newline character (‘\n’). Note that you can give an ASCII character as a literal in MIPS
(e.g., li $a0, ‘\n’).
The program must handle positive and negative zero as special cases, as given in the table of examples below.
Input Validation:
The second command-line argument must consist only of characters that represent hexadecimal digits. If the
argument contains invalid characters, print the string found at label invalid args error and exit the program
(via system call #10). You may assume that the second command-line argument contains exactly 8 characters.
Examples:
Command-line Arguments Expected Output
S 00000000 +0
S 80000000 -0
S 7FFFFFFF 2147483647
S 59102CED 1494232301
S D9102CED -1494232301
Part IV: Convert a Location Numeral to Decimal Positional Notation
CSE 220 – Spring 2019 Programming Project #1 6
First Argument: D
Second Argument: a Napier location numeral of at most 8 characters, which might be given in extended or
abbreviated forms.
The D operation treats the second command-line argument as a location numeral, converts it to its equivalent
decimal form, and prints the decimal form to the screen, followed by a newline character (‘\n’). As explained at
the linked article, location numerals provide an alternative to binary positional notation (i.e., what we use today
instead). The lowercase Latin alphabet letters a, b, c, ..., z represent the numbers 2
25, respectively.
When multiple letters are written together, the corresponding values are added together. For example, becgdb =
2
1 + 24 + 22 + 26 + 23 + 21 = 9610. Note that letters can be repeated and that they do not necessarily appear in
alphabetical order.
To accommodate location numerals with fewer than 8 letters we will allow the character ‘0’ to appear anywhere
in the string. A ‘0’ does not contribute to the value of the numeral. A string consisting of all ‘0’ will represent
the value 0.
Input Validation:
The second command-line argument must consist only of lowercase letters and zeroes. If this is not the case, print
the string found at label invalid args error and exit the program (via system call #10).
You may assume that the sum will always be less than or equal to 2
31 1. The input will always be positive.
Examples:
Command-line Arguments Expected Output
D 00000000 0
D dhknpqtu 1680520
D mjuhgrzw 38933184
D 00j0m00f 4640
D qfqqjjui 1246496
Part V: Convert a Decimal Number to a Location Numeral
First Argument: L
Second Argument: a decimal number (given as a character string)
The L operation treats the second command-line argument as a decimal number (given as a string), converts the
argument string to an integer, and then converts/prints the integer to abbreviated, alphabetically sorted location
numerals using only lowercase letters in the output. The output string is followed by a newline character (‘\n’).
There must be no repeated characters in the output.
To convert the input string to an integer, you will need to implement a simplified version of the Java method
String.parseInt or the C language function atoi. The most straightforward way to perform this conversion
is as follows. First, initialize a register to zero. Then, read each digit character and convert it into its decimal value
(e.g., convert the character 5 into the actual number 5). Multiply the register’s current value by 10 and then add
the new digit to the register. Do this for all 8 digits of the input string.
Input Validation:
CSE 220 – Spring 2019 Programming Project #1 7
The second command-line argument must consist only of 8 decimal digits, including any required leading zeroes
to pad the input to 8 characters. If a non-digit character is present in the input, print the string found at label
invalid args error and exit the program (via system call #10).
The the operation only needs to be able to handle values in the range [1, 2
26 1], the upper bound of which is
represented as abcdefghijklmnopqrstuvwxyz in alphabetically sorted, abbreviated location numerals.
Examples:
Remember that the command-line argument for this operation is a decimal integer, not a hexadecimal integer.
Command-line Arguments Expected Output
L 00000128 h
L 67108863 abcdefghijklmnopqrstuvwxyz
L 08293810 befhiklprstuvw
L 00090145 afnoq
Part VI: Collect Counts of Characters
First Argument: A
Second Argument: a string of 8 characters
Third, Fourth and Fifth Arguments: the characters ’Y’ and ’N’ in any combination
The A operation treats the second command-line argument as a general string of letters, digits and punctuation
marks. Depending on three additional command line arguments, it counts the number of uppercase letters and/or
lowercase letters and/or digits characters in the string. Note that each count can be at most 8, meaning that 4 bits
are sufficient to store each count. In light of this, the operation computes the three counts and stores them as three
nibbles in a register, with the count of digits in the rightmost (least significant) nibble, the count of lowercase
letters in the second least significant nibble, and the count of uppercase letters in the third least significant nibble.
An example will help to illustrate the idea. Suppose the input is "Ja#S!517". The counts of uppercase letters,
lowercase letters and digits are, respectively, 2, 1 and 3. In 4-bit binary (i.e., nibbles), these values are 00102,
00012 and 00112, respectively. Thus, the register containing these counts would have the contents
00000000000000000000001000010011
which is the output of the operation. System call #35 will allow you to print an integer in binary. Load the value
to be printed in $a0, load 35 into $v1 and then invoke syscall. After printing the binary string, followed it
with a newline character (‘\n’)
The operation always takes three additional arguments: the single characters ‘Y’ and ‘N’, in any combination.
The first instance of ‘Y’/‘N’ indicates whether or not we should include the count of uppercase letters in the
result; the second instance of ‘Y’/‘N’ indicates whether we should include the count of lowercase letters in the
result; and the third instance of ‘Y’/‘N’ indicates whether we should include the count of digits in the result.
As an example, suppose the following were given as the command-line arguments:
A Ja#S!517 N Y Y
CSE 220 – Spring 2019 Programming Project #1 8
This input indicates that we want to count only the lowercase letters and digits in the second argument. Therefore,
the output of the operation will be:
00000000000000000000000000010011
You may assume that the third, fourth and fifth arguments, if they are present, are always either ‘Y’ or ‘N’.
Input Validation:
No input validation is required for this operation.
Examples:
Command-line Arguments Expected Output
A YO!2wolf Y Y Y 00000000000000000000001001000001
A YO!2wolf Y N Y 00000000000000000000001000000001
A HiWolfie Y Y Y 00000000000000000000001001100000
A HiWolfie N Y N 00000000000000000000000001100000
A 19SUMMER N Y N 00000000000000000000000000000000
A SbuYah!! Y N N 00000000000000000000001000000000
Academic Honesty Policy
Academic honesty is taken very seriously in this course. By submitting your work to Blackboard you indicate
your understanding of, and agreement with, the following Academic Honesty Statement:
1. I understand that representing another person’s work as my own is academically dishonest.
2. I understand that copying, even with modifications, a solution from another source (such as the web or
another person) as a part of my answer constitutes plagiarism.
3. I understand that sharing parts of my homework solutions (text write-up, schematics, code, electronic or
hard-copy) is academic dishonesty and helps others plagiarize my work.
4. I understand that protecting my work from possible plagiarism is my responsibility. I understand the importance
of saving my work such that it is visible only to me.
5. I understand that passing information that is relevant to a homework/exam to others in the course (either
lecture or even in the future!) for their private use constitutes academic dishonesty. I will only discuss
material that I am willing to openly post on the discussion board.
6. I understand that academic dishonesty is treated very seriously in this course. I understand that the instructor
will report any incident of academic dishonesty to the College of Engineering and Applied Sciences.
7. I understand that the penalty for academic dishonesty might not be immediately administered. For instance,
cheating in a homework may be discovered and penalized after the grades for that homework have been
recorded.
8. I understand that buying or paying another entity for any code, partial or in its entirety, and submitting it as
my own work is considered academic dishonesty.
9. I understand that there are no extenuating circumstances for academic dishonesty.
CSE 220 – Spring 2019 Programming Project #1 9
How to Submit Your Work for Grading
To submit your proj1.asm file for grading:
1. Login to Blackboard and locate the course account for CSE 220.
2. Click on “Assignments” in the left-hand menu and click the link for this assignment.
3. Click the “Browse My Computer” button and locate the proj1.asm file. Submit only that one .asm file.
4. Click the “Submit” button to submit your work for grading.
Oops, I messed up and I need to resubmit a file!
No worries! Just follow the steps again. We will grade only your last submission.

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:[email protected] 

微信:codinghelp

猜你喜欢

转载自www.cnblogs.com/mkfa/p/10432681.html
cse
今日推荐