[SOLVED] CS algorithm assembler prolog Java mips assembly gui 1 Purpose

$25

File Name: CS_algorithm_assembler_prolog_Java_mips_assembly_gui_1_Purpose.zip
File Size: 584.04 KB

5/5 - (1 vote)

1 Purpose
CS 252: Computer Organization
Assembly Project #2
Loops, Arrays, and Strings
due at 3pm, Fri 26 Feb 2021
In this project, you will be using loops, iterating over arrays of integers and strings. You will be implementing both for() and while() loops.
1.1 Reminders
Be sure to pay attention to the Asm Style Guide, which is available on Piazza.
1.2 Required Filenames to Turn in
Name your assembly language file asm2.s. 1.3 Allowable Instructions
When writing MIPS assembly, the only instructions that you are allowed to use (so far) are:
add, addi, sub, addu, addiu
and, andi, or, ori, xor, xori, nor beq, bne, j
slt, slti
sll, sra, srl
lw, lh, lb, sw, sh, sb
la
syscall
While MIPS has many other useful instructions (and the assembler recog- nizes many pseudo-instructions), do not use them! We want you to learn the fundamentals of how assembly language works you can use fancy tricks after this class is over.
1.4 Standard Wrapper
Use the same Standard Wrapper as Asm1; read the spec from that project to find information about it. This is the function prologue and epilogue so that the tests can call your code.
1

2 Task Overview
As with Asm 1, you will read a number of different control variables (each of which are words). They will be either 0 or 1; you will do that particular task if the control variable is 1.
In addition, there will be a number of other variables, used by the various tasks. These will be detailed in the appropriate sections below.
2.1 Matching the Output
You must match the expected output exactly, byte for byte. Every task ends with a blank line (if it does anything at all); do not print the blank line if you do not perform the task. (Thus, if a testcase asks you to perform no tasks, your code will print nothing at all.)
To find exactly the correct spelling, spacing, and other details, always look at the .out file for each example testcase Ive provided. Any example (or stated requirement) in this spec is approximate; if it doesnt match the .out file, then trust the .out file.
(Of course, if there are any cases in the spec which are not covered by any testcase that Ive provided, then use the spec as the authoritative source.)
2

3 Task 1: Fibonacci
In this task, you will print out Fibonacci numbers. Use the iterative algorithm Ive provided below. (You have certainly seen the recursive implementation, but that has O(2n) cost, whereas this one has O(n) cost. Plus, you dont know how to do functions yet.)
Implement the following code:
if (fib != 0) {
printf(Fibonacci Numbers:
);
printf(0: 1
);
printf(1: 1
);
int prev = 1, beforeThat = 1;
int n = 2;
while (n <= fib){int cur = prev+beforeThat;printf(“%d: %d
“, n, cur);n++;beforeThat = prev;prev = cur;}printf(”
“);}NOTE: Unlike most other control variables in this project, fib can take more values than just 0 or 1. If fib==0, then do nothing; if it is positive, then use it as the limit for the loop. (You may assume that it will never be negative.)34 Task 2: squareIn this task, you will implement the following C code:if (square != 0){// NOTE: square_fill is a byte// NOTE: square_size is a wordfor (int row=0; row < square_size; row++){char lr, mid;if (row == 0 || row == square_size-1){lr = +;mid = -; }else {mid = square_fill;}printf(“%c”, lr);for (int i=1; i = the one before) or a descending list (<=).If runCheck==1, then scan through the array of integers. You can find its location at intArray, and it contains intArray len integers. (You may assume that the length I provide you is non-negative, and that the array has at least that many values. It might have more, but if so, you must ignore them.)If it is an ascending list, then print outRun Check: ASCENDINGand if it is a descending list, then print outRun Check: DESCENDING(It is possible, in a corner few cases, for both cases to be true. In that case, print out both lines, ascending first.)If neither is true, then print outRun Check: NEITHERIn any of these cases, print out a blank line afterwards, if you performed the task.NOTE: Zero-length arrays, and arrays with only a single element, are both valid. Both of these special cases should be reported as BOTH ascending and descending lists.6 Task 4: countWordsIf countWords==1, then read the string str. Count the number of words in it; words will be separated by spaces or newlines (you do not have to check for any other types of whitespace). Print out the number of words, followed by a blank line, like this:3Ignore leading and trailing spaces, and multiple spaces in a row. For instance, the following string has 3 words: str = ” foo barbaz “;Do not modify the string in memory.5 7 Task 5: revStringIf revString==1, then scan through the string str and reverse it in memory. You may implement your own code if you wish, but your algorithm must be able to handle any size string!Here is one possible implementation – implement this, or your own design:if (revString != 0){int head = 0;int tail = 0;// advance the tail until we find the correct locationwhile (str[tail] != )tail++;tail–;// when we get here, tail gives the index of the last non-NULL// character in the string.If the string is empty, it actually// would be -1, which is weird but OK.while (head < tail){swap(str[head], str[tail]);head++;tail–;}printf(“String successfully swapped!
“);printf(”
“);}8 Requirement: Dont Assume Memory Lay- out!It may be tempting to assume that the variables are all laid out in a particular order. Do not assume that! Your code should check the variables in the order that we state in this spec – but you must not assume that they will actually be in that order in the testcase. Instead, you must use the la instruction for every variable that you load from memory.To make sure that you dont make this mistake, we will include testcases that have the variables in many different orders.69 Running Your CodeYou should always run your code on lectura using the grading script before you turn it in. However, while you are writing (or debugging) your code, it is often handy to run the code yourself.9.1 Running With Mars (GUI)To launch the Mars application (as a GUI), open the JAR file that you down- loaded from Piazza. You may be able to just double-click it in your operating system; if not, then you can run it by typing the following command:java -jar
This will open a GUI, where you can edit and then run your code. Put your code, plus one1 testcase, in some directory. Open your code in the Mars editor; you can edit it there. When its ready to run, assemble it (F3), run it (F5), or step through it one instruction at a time (F7). You can even step backwards in time (F8)!
9.1.1 Running the Mars GUI the First Time
The first time that you run the Mars GUI, you will need to go into the Settings menu, and set two options:
Assemble all files in directory so your code will find, and link with, the testcase
Initialize Program Counter to main if defined-sothatthepro- gram will begin with main() (in the testcase) instead of the first line of code in your file.
9.2 Running Mars at the Command Line
You can also run Mars without a GUI. This will only print out the things that you explicitly print inside your program (and errors, of course).2 However, its an easy way to test simple fixes. (And of course, its how the grading script works.) Perhaps the nicest part of it is that (unlike the GUI, as far as I can tell), you can tell Mars exactly what files you want to run so multiple testcases in the directory is OK.
To run Mars at the command line, type the following command:
1 Why cant you put multiple testcases in the directory at the same time? As far as I can tell (though Im just learning Mars myself), the Mars GUI only runs in two modes: either (a) it runs only one file, or (b) it runs all of the files in the same directory. If you put multiple testcases in the directory, it will get duplicate-symbol errors.
2 Mars has lots of additional options that allow you to dump more information, but I havent investigated them. If you find something useful, be sure to share it with the class!
7

java -jar sm .s .s
10 A Note About Grading
Your code will be tested automatically. Therefore, your code must:
Use exactly the filenames that we specify (remember that names are case sensitive).
Not use any other files (unless allowed by the project spec) since our grading script wont know to use them.
Follow the spec precisely (dont change any names, or edit the files I give you, unless the spec says to do so).
(In projects that require output) match the required output exactly! Any extra spaces, blank lines misspelled words, etc. will cause the testcase to fail.
To make it easy to check, I have provided the grading script. I strongly recommend that you download the grading script and all of the testcases, and use them to test your code from the beginning. You want to detect any problems early on!
10.1 mips checker.pl
In addition to downloading grade asm2, you should also download mips checker.pl,
and put it in the same directory. The grading script will call the checker script.
10.2 Testcases
For assembly language programs, the testcases will be named test *.s . For C programs, the testcases will be named test *.c . For Java programs, the testcases will be named Test *.java . (You will only have testcases for the languages that you have to actually write for each project, of course.)
Each testcase has a matching output file, which ends in .out; our grading script needs to have both files available in order to test your code.
For many projects, we will have secret testcases, which are additional testcases that we do not publish until after the solutions have been posted. These may cover corner cases not covered by the basic testcase, or may simply provide additional testing. You are encouraged to write testcases of your own, in order to better test your code.
8

10.3 Automatic Testing
We have provided a testing script (in the same directory), named grade asm2, along with a helper script, mips checker.pl. Place both scripts, all of the testcase files (including their .out files), and your program files in the same directory. (I recommend that you do this on Lectura, or a similar department machine. It might also work on your Mac or Linux box, but no promises!)
10.4 Writing Your Own Testcases
The grading script will grade your code based on the testcases it finds in the current directory. Start with the testcases I provide however, I encourage you to write your own as well. If you write your own, simply name your testcases using the same pattern as mine, and the grading script will pick them up.
While you normally cannot share code with friends and classmates, test- cases are the exception. We encourage you to share you testcases ideally by posting them on Piazza. Sometimes, I may even pick your testcase up to be part of the official set, when I do the grading!
11 Turning in Your Solution
Turn in the required files to gradescope. Turn in only your program; do not turn in any testcases or other files.
11.1 Late Work
Gradescope accepts submissions that are within 24 hours of the deadline. These submissions are marked as late. I tally late days at the end of the semester. If you have used all of your late days, any other late work is given a 0.
9

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS algorithm assembler prolog Java mips assembly gui 1 Purpose
$25