Starting from:
$30

$24

Homework 5 Solution

Overview



1.1 Purpose:




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:




mult.asm



selectionsort.asm



printvowels.asm



linkedlist.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 LC3 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!














































2
Detailed Instructions



2.1 Part 1: Implementing Multiply




To start you o with this homework, we are implementing the multiply function! Store the result of the operation in the label ANSWER. Arguments A and B are stored in memory, and you will load them from there to perform this operation. Assume the values of A and B are positive integers. Implement your assembly code in mult.asm.




Suggested Pseudocode:







a = (argument 1);




b = (argument 2);




ANSWER = 0;




while (b 0) {




ANSWER = ANSWER + a;




b--;




}




// note: when the while-loop ends, the value stored at ANSWER is a times b.




2.2 Part 2: Selection Sort




The second assembly function is to selection-sort all elements of an array in memory. Use the pseudocode to help plan out your assembly and make sure you are sorting it properly! Implement your assembly code in selectionsort.asm. For more information on selection sort and a good visual representation, check out this link.




Suggested Pseudocode:


x = 0;


// current swapping index in the array
len = length of array;


while(x < len - 1) {


z = x;
// index of minimum value in unsorted portion of array
y = x + 1;
// current index in array
while (y < len) {


if (arr[y] < arr[z]) {


z = y;
// update the index of the minimum value
}




y++;


}




if (z != x) {


temp = arr[x];
// perform a swap
arr[x] = arr[z];


arr[z] = temp;


}




x++;


}

























3
2.3 Part 3: Printing Vowels




The third assembly function is to print the vowels in a null-terminated string. The label STRING will contain the address of the rst character of the string. Remember that strings are just arrays of consecutive characters. Implement your assembly code in printvowels.asm




Assume every character in the string is UPPERCASE.




To check for these vowel characters, refer to the ASCII table and remember that each of these characters are represented 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 = "TWENTY ONE TEN";




i = 0;




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




if(string[i] == ’A’ || string[i] == ’E’ ||




string[i] == ’I’ || string[i] == ’O’ ||




string[i] == ’U’){




print(string[i]);




}




i++;




}







Hint: Take a look at the trap vectors in Appendix A for printing characters to the console.























































































More products