[Solved]Homework 5 Intro to Assembly

$24.99 $18.99

So far in this class, you have seen how binary or machine code manipulates our circuits to achieve a goal. However, as you have probably gured out, binary can be hard for us to read and debug, so we need an easier way of telling our computers what to do. This is where assembly comes…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Categorys:

Description

5/5 – (2 votes)

So far in this class, you have seen how binary or machine code manipulates our circuits to achieve a goal. However, as you have probably gured out, binary can be hard for us to read and debug, so we need an easier way of telling our computers what to do. This is where assembly comes in. Assembly language is symbolic machine code, meaning that we don’t have to write all of the ones and zeros in a program, but rather symbols that translate to ones and zeros. These symbols are translated with something called the assembler. Each assembler is dependent upon the computer architecture on which it was built, so there are many di erent assembly languages out there. Assembly was widely used before most higher-level languages and is still used today in some cases for direct hardware manipulation.

1.2 Task

The goal of this assignment is to introduce you to programming in LC-3 assembly code. This will involve writing small programs, translating conditionals and loops into assembly, modifying memory, manipulating strings, and converting high-level programs into assembly code.

You will be required to complete the four functions listed below with more in-depth instructions on the following pages:

  1. square.asm

  1. arrayModify.asm

  1. removeVowels.asm

  1. toggleCase.asm

1.3 Criteria

Your assignment will be graded based on your ability to correctly translate the given pseudocode into LC-3 assembly code. Check the deliverables section for deadlines and other related information. Please use the LC-3 instruction set when writing these programs. More detailed information on each instruction can be found in the Patt/Patel book Appendix A (also on Canvas under \LC-3 Resources”). Please check the rest of this document for some advice on debugging your assembly code, as well some general tips for successfully writing assembly code.

You must obtain the correct values for each function. While we will give partial credit where we can, your code must assemble with no warnings or errors (Complx will tell you if there are any). If your code does not assemble, we will not be able to grade that le and you will not receive any points. Each function is in a separate le, so you will not lose all points if one function does not assemble. Good luck and have fun!

  • Detailed Instructions

2.1 Part 1: Square

To start you o with this homework, we are implementing a function that takes a positive integer A, and calculate the square. Store the result of the operation in the label ANSWER. Argument A is stored in memory, and you will load it from there to perform this operation. Implement your assembly code in square.asm.

Suggested Pseudocode:

a = (argument 1);

ANSWER = 0;

for (int i = 0; i < a; i++) {

ANSWER += a;

}

return ANSWER;

2.2 Part 2: Array Modify

The second assembly function is to implement certain array modi cations to an array. You will be modifying an array out of place, meaning that the original array will remain the same and your code will produce a resulting array with said modi cations. The resulting array will have enough space for the nal answer. Use the pseudocode to help plan out your assembly and implement your assembly code in arrayModify.asm.

In this assembly code, you will need to look through the array x. If the index is odd, then take the value of that index, subtract by 10, and save the updated value in array y at that index. If the index is even, then take the value of that index, multiply by 2, and save the updated value in array y at that index.

Suggested Pseudocode:

i = 0; // first index

len = Len(ARR_X);

while (i < len) {

if (i % 2 == 0) {

//if we are at an even index, subtract 10 and save it to the array at that index ARR_Y[i] = ARR_X[i] – 10;

} else {

//if we are at odd index, multiply by 2 and save it to the array at that index ARR_Y[i] = ARR_X[i] * 2;

}

i++;

}

2.3 Part 3: Remove Vowels

The third assembly function is to modify a null-terminated string by removing all vowels. (a/A, e/E, i/I, o/O, u/U) Your function should work for both uppercase and lowercase letters. You should iterate through the string, and return a new string that has all of the vowels removed.

The label STRING will contain the address of the rst character of the string to be converted. Store the modi ed string in the label ANSWER. Remember that strings are just arrays of consecutive characters. You are given two constants to use in your program, A which is the value of the ASCII character ’A’, LOWERA which is the value of ’a’. Keep in mind that you may add more constants if you wish. Implement your assembly code in removeVowels.asm

Assume that the strings are random: they can contain characters, numbers, spaces and sym-bols.

To modify a character, refer to the ASCII table and remember that each of these characters are repre-sented by a word (16-bits) in the LC-3’s memory. This is a null-terminated string, meaning that a 0 will be stored immediately after the nal character in memory!

NOTE:

  • 0 is the same as ‘n0’

  • 0 is di erent from ‘0’

Suggested Pseudocode:

STRING = (argument 1);

ANSWER = “”;

for (int i = 0; i < a.length; i++) {

if (string[i] == ’\0’){

break;

}

if (string[i] == ’A’ || string[i] == ’a’) {

continue;

} else if (string[i] == ’E’ || string[i] == ’e’) { continue;

} else if (string[i] == ’I’ || string[i] == ’i’) { continue;

} else if (string[i] == ’O’ || string[i] == ’o’) { continue;

} else if (string[i] == ’U’ || string[i] == ’u’) { continue;

}

ANSWER += STRING[i];

}

ANSWER += ’\0’

return ANSWER;

2.4 Part 4: Toggle Case

For the nal problem, your goal is to look through a null-terminated string, and change the uppercase to a lowercase; a lowercase to an uppercase. The label ANSWER will contain the address of the answer string that you will use to store the modi ed string. You will read the value from a provided string, if the letter at that index is uppercase, then change it to a lowercase. If the letter at that index is lowercase, then change it to an uppercase.

The label STRING will contain the address of the rst character of the string to be read from. Remember that this string is null-terminated. The result string will be stored at the label ANSWER (ANSWER will contain the address of the rst character of the result string. Implement your assembly code in toggleCase.asm

Assume every character in the string is an English alphabetic letter and not a number. You must also ignore the spaces in between.

NOTE:

  • 0 is the same as ‘n0’

  • 0 is di erent from ‘0’

  • “A” in ASCII is 65

  • “Z” in ASCII is 90

  • ASCII table: https://www.asciitable.com/

Suggested Pseudocode:

string = “Assembly is interesting”; // given string Array[string.len()] answer; // array to store the result string i = 0;

while (string[i] != ’\0’) {

if (string[i] == ” “) {

answer[i] = ” “;

} else if (string[i] >= “A” && string[i] <= “Z”) { answer[i] = string[i].lowerCase();

} else {

answer[i] = string[i].upperCase();

}

i++;

}

  • Deliverables

Turn in the following les on Gradescope:

  1. square.asm

  1. arrayModify.asm

  1. removeVowels.asm

  1. toggleCase.asm

Note: Please do not wait until the last minute to run/test your homework. Last minute turn-ins will result in long queue times for grading on Gradescope. You have been warned.

  • Running the Autograder and Debugging LC-3 Assembly

When you turn in your les on Gradescope for the rst time, you may not receive a perfect score. Does this mean you change one line and spam Gradescope until you get a 100? No! You can use a handy Complx feature called \replay strings”.

  1. First o , we can get these replay strings in two places: the local grader, or o of Gradescope. To run the local grader:

    • Mac/Linux Users:

      1. Navigate to the directory your homework is in (in your terminal on your host machine, not in the Docker container via your browser)

      1. Run the command sudo chmod +x grade.sh

      1. Now run ./grade.sh

    • Windows Users:

      1. In Git Bash (or Docker Quickstart Terminal for legacy Docker installations), navigate to the directory your homework is in

      1. Run chmod +x grade.sh

      1. Run ./grade.sh

When you run the script, you should see an output like this:

Copy the string, starting with the leading ’B’ and ending with the nal backslash. Do not include the quotation marks.

Side Note: If you do not have Docker installed, you can still use the tester strings to debug your assembly code. In your Gradescope error output, you will see a tester string. When copying, make sure you copy from the rst letter to the nal backslash and again, don’t copy the quotations.

2. Secondly, navigate to the clipboard in your Docker image and paste in the string.

3. Next, go to the Test Tab and click Setup Replay String

4. Now, paste your tester string in the box!

  1. Now, Complx is set up with the test that you failed! The nicest part of Complx is the ability to step through each instruction and see how they change register values. To do so, click the step button. To change the number representation of the registers, double click inside the register box.

  1. If you are interested in looking how your code changes di erent portions of memory, click the view tab and indicate ’New View’

  1. Now in your new view, go to the area of memory where your data is stored by CTRL+G and insert the address

  1. One nal tip: to automatically shrink your view down to only those parts of memory that you care about (instructions and data), you can use View Tab ! Hide Addresses ! Show Only Code/Data.

  • Appendix

5.1 Appendix A: ASCII Table

Figure 1: ASCII Table | Very Cool and Useful!

5.2 Appendix B: LC-3 Instruction Set Architecture

5.3 Appendix C: LC-3 Assembly Programming Requirements and Tips

  1. Your code must assemble with NO WARNINGS OR ERRORS. To assemble your program, open the le with Complx. It will complain if there are any issues. If your code does not assemble you WILL get a zero for that le.

  1. Comment your code! This is especially important in assembly, because it’s much harder to interpret what is happening later, and you’ll be glad you left yourself notes on what certain instructions are contributing to the code. Comment things like what registers are being used for and what less intuitive lines of code are actually doing. To comment code in LC-3 assembly just type a semicolon (;), and the rest of that line will be a comment.

  1. Avoid stating the obvious in your comments, it doesn’t help in understanding what the code is doing.

Good Comment

ADD R3, R3, -1 ; counter–

BRp LOOP ; if counter == 0 don’t loop again

Bad Comment

ADD R3, R3, -1 ; Decrement R3

BRp LOOP ; Branch to LOOP if positive

  1. DO NOT assume that ANYTHING in the LC-3 is already zero. Treat the machine as if your program was loaded into a machine with random values stored in the memory and register le.

  1. Following from 3, you can load the le with randomized memory by selecting \File” > \Advanced Load” and selecting randomized registers/memory.

  1. Do NOT execute any data as if it were an instruction (meaning you should put .fills after HALT or RET).

  1. Do not add any comments beginning with @plugin or change any comments of this kind.

  1. Test your assembly. Don’t just assume it works and turn it in.

Rules and Regulations

6.1 General Rules

  1. Although you may ask TAs for clari cation, you are ultimately responsible for what you submit. As such, please start assignments early, and ask for help early. This means that (in the case of demos) you should come prepared to explain to the TA how any piece of code you submitted works, even if you copied it from the book or read about it on the internet.

  1. If you nd any problems with the assignment it would be greatly appreciated if you reported them to the author (which can be found at the top of the assignment). Announcements will be posted if the assignment changes.

6.2 Submission Conventions

  1. Do not submit links to les. The autograder does not understand it, and we will not manually grade assignments submitted this way as it is easy to change the les after the submission period ends. You must submit all les listed in the Deliverables section individually to Gradescope as separate les.

6.3 Submission Guidelines

  1. You are responsible for turning in assignments on time. This includes allowing for unforeseen circum-stances. If you have an emergency let us know IN ADVANCE of the due time supplying documenta-tion (i.e. note from the dean, doctor’s note, etc). Extensions will only be granted to those who contact us in advance of the deadline and no extensions will be made after the due date.

  1. You are also responsible for ensuring that what you turned in is what you meant to turn in. After submitting you should be sure to download your submission into a brand new folder and test if it works. No excuses if you submit the wrong les, what you turn in is what we grade. In addition, your assignment must be turned in via Canvas/Gradescope. Under no circumstances whatsoever we will accept any email submission of an assignment. Note: if you were granted an extension you will still turn in the assignment over Canvas/Gradescope.

6.4 Syllabus Excerpt on Academic Misconduct

Academic misconduct is taken very seriously in this class. Quizzes, timed labs and the nal examination are individual work.

Homework assignments are collaborative, In addition many if not all homework assignments will be evaluated via demo or code review. During this evaluation, you will be expected to be able to explain every aspect of your submission. Homework assignments will also be examined using computer programs to nd evidence of unauthorized collaboration.

What is unauthorized collaboration? Each individual programming assignment should be coded by you. You may work with others, but each student should be turning in their own version of the assignment. Submissions that are essentially identical will receive a zero and will be sent to the Dean of Students’ O ce of Academic Integrity. Submissions that are copies that have been super cially modi ed to conceal that they are copies are also considered unauthorized collaboration.

You are expressly forbidden to supply a copy of your homework to another student via elec-tronic means. This includes simply e-mailing it to them so they can look at it. If you supply an electronic copy of your homework to another student and they are charged with copying, you will also be charged. This includes storing your code on any site which would allow other parties to obtain your code such as but not limited to public repositories (Github), pastebin, etc. If you would like to use version control, use github.gatech.edu

6.5 Is collaboration allowed?

Collaboration is allowed on a high level, meaning that you may discuss design points and concepts relevant to the homework with your peers, share algorithms and pseudo-code, as well as help each other debug code. What you shouldn’t be doing, however, is pair programming where you collaborate with each other on a single instance of the code. Furthermore, sending an electronic copy of your homework to another student for them to look at and gure out what is wrong with their code is not an acceptable way to help them, because it is frequently the case that the recipient will simply modify the code and submit it as their own.

15

[Solved]Homework 5 Intro to Assembly
$24.99 $18.99