辅导案例-MCD4700-Assignment 1
Monash College MCD4700 - Introduction to Computer Systems, Networks and Security Assignment 1 - Trimester 1, 2020 Submission guidelines This is an individual assignment, group work is not permitted Deadline: 15 April 2020, 7:55pm Submission format: docx for the written tasks, LogiSim circuit files for task 1, MARIE assembly files for task 2. All files must be uploaded electronically via Moodle. Late submission: ● By submitting a Special Consideration Form or visit this link: https://lms.monashcollege.edu.au/course/view.php?id=1331 ● Or, without special consideration, you lose 5 marks of your mark per day that you submit late (including weekends). Submissions will not be accepted more than 5 days late. This means that if you got Y marks, only Y-n*5 will be counted where n is the number of days you submit late. In-class interviews: See instructions for Task 2 for details. Marks: This assignment will be marked out of 100 points, and count for 20% of your total unit marks. Plagiarism: It is an academic requirement that the work you submit be original. If there is any evidence of copying (including from online sources without proper attribution), collaboration, pasting from websites or textbooks, Zero marks may be awarded for the whole assignment, the unit or you may be suspended or excluded from your course. Monash Colleges policies on plagiarism, collusion, and cheating are available here or see this link: https://www.monashcollege.edu.au/__data/assets/pdf_file/0010/17101/dip-assessment-polic y.pdf Further Note: When you are asked to use Internet resources to answer a question, this does not mean copy-pasting text from websites. Write answers in your own words such that your understanding of the answer is evident. Acknowledge any sources by citing them. 1 Monash College MCD4700 Assignment 1 1. Boolean Algebra and Logisim Task (35 marks) Input Output A B C D Z1 Z2 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 1 1 1 0 0 1 0 0 0 1 0 1 0 1 1 1 0 1 1 0 0 1 0 1 1 1 0 0 1 0 0 0 0 0 1 0 0 1 1 0 1 0 1 0 0 0 1 0 1 1 1 0 1 1 0 0 0 1 1 1 0 1 0 0 1 1 1 0 0 1 1 1 1 1 1 1 Truth table for Z1 and Z2 Step 1: Boolean Algebra Expressions (10 marks) Write the Boolean equation for your truth table in sum of products form (your choice). First, think about how to deal with the two outputs. Then, describe each single row in terms of Boolean algebra. Finally, combine the boolean terms for each row into a larger term. Briefly explain these steps for the truth table given. 2 Monash College MCD4700 Assignment 1 Step 2: Logical Circuit in Logisim (10 marks) Model the resulting Boolean terms from Step 1 in a single Logisim circuit, using the basic gates AND, OR, NOT. Use the original boolean expression for drawing the circuit (do not simplify the expression). You can use logic gates with more than two inputs. To do this task you have to use a template Logisim file “task_1.2_template” that has been provided with this assignment. Do not forget to rename the file before saving your circuit in it. And, ‘2’ marks will be deducted if you change the labels (or adding any extra label). Step 3: Optimised Circuit (15 marks) The goal of this task is to find a minimal circuit (using only universal NAND gates). Based on the truth table and Boolean algebra terms from Step 1, optimize the function using Karnaugh maps. You need to create two Karnaugh maps, one for each output. Your documentation should show the maps as well as the groups found in the maps and how they relate to terms in the optimized Boolean function. Then use Logisim to create a logic circuit. Don’t use any other gates, other than NAND. Use the template Logisim file “task_1.3_template” that have been provided with this assignment. Do not forget to rename it. 3 Monash College MCD4700 Assignment 1 2. MARIE (65 marks) In this task you will develop a MARIE application that performs some manipulation of strings. We will break it down into small steps for you. Most of the tasks require you to write code, test cases and some small analysis. The code must contain comments, and you submit it as .mas files together with the rest of your assignment. The test cases should also be working, self-contained MARIE assembly files (without requiring much input from the user). The analysis needs to be submitted as part of the main PDF file you submit for this assignment. In-Class interviews: You will be required to demonstrate your code to your tutor after the submission deadline. Failure to demonstrate will lead to “zero marks” being awarded to the entire programming part of this assignment. Name as a String This section introduces the concepts you need for the rest of the assignment. A string is a sequence of characters. It’s the basic data structure for storing text in a computer. There are several different ways of representing a string in memory and how to deal with strings of arbitrary length. For this assignment, we will use the following string representation: ● A string is represented in a contiguous memory location, with each address containing one character. ● The characters are encoded using the ASCII encoding. ● End of a string is marked by the ASCII character ‘.’ (i.e. dot or full-stop). ● A string can be of any arbitrary length, and will be terminated by a ’.’, and it may contain any of the following: alphabets (A-Z, a-z), numbers (0-9) and ASCII Space Character (Hex 020). Here is an example. A string “John Nguyen.” will be represented in memory (written as hexadecimal numbers): 04A 06F 068 06E 020 04E 067 075 079 065 06E 02E J o h n N g u y e n . Note that, for a string with n characters, we need (n+2 ) words of MARIE memory in order to store all the characters belonging to that string (including space character and ‘.’). In MARIE assembly language programming, we can make use of the ADR command, the HEX keyword and a label “myString” to put this string into memory: 4 Monash College MCD4700 Assignment 1 myStringAddr, ADR myString myString, HEX 04A /’J’ HEX 06F /’o’ HEX 068 /’h’ HEX 06E /’n’ HEX 020 /’Space’ HEX 04E /’N’ HEX 067 /’g’ HEX 075 /’u’ HEX 079 /’y’ HEX 065 /’e HEX 06E /’n’ HEX 02E /’.’ 2.1 A MARIE program for printing a string (10 marks) Prepare a MARIE program called PrintString that can print an ASCII ‘.’ terminated string (using the “Output” instruction) containing your “First Name” and “Last Name”. Start by using a label “PrintStringAddr” that holds the start address of a string (like, myStringAddr). The code should then load a character from that address, output it, then increment the address by one, and keep doing that upto the character loaded from the address is a ‘.’ (which signals the end of the string). The string may look similar to the output below. YourFirstName LastName To receive full marks, you need to write a MARIE program, which once executed, will print your name string on the display. You may use the following template to begin with. Load myStringAddr / Load string start address Store PrintStringAddr / Pass as an argument / Your code may begin here ……… ……… /Your MARIE program ends here /Variables or labels used in the program PrintStringAddr, Dec 0 / variable or label to store the / start address of a string …… myStringAddr, ADR myString myString, HEX ??? /First 5 Monash College MCD4700 Assignment 1 HEX ??? /Name HEX ??? / …………… HEX ??? / HEX 020 /’Space’ HEX ??? /Last HEX ??? /Name HEX ??? / …………… HEX ??? / HEX 02E /’.’ /end of the list 2.2 A subroutine for printing a string (15 marks) Convert the MARIE program done in section 2.1, into a subroutine called subPrintString that can print any ASCII ‘.’ terminated string (using the “Output” instruction). To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to modify the MARIE main program (from section 2.1) to call this subroutine. You may use the following template to begin with. Load myStringAddr / Load string start address Store PrintStringAddr / Pass as an argument Jns subPrintString / Call printing subroutine Halt /Your subroutine “subPrintString ” begins here PrintStringAddr, Dec 0 / variable or label to store the / start address of a string subPrintString, Hex 0 /label (subroutine name) to begin the / subroutine / Your code may begin here ……… ……… /Your subroutine ends here 2.3 Implementation of Caesar Cipher Substitution (20 marks) In this section, we are going to implement Caesar Cipher (a type of substitution cipher) encryption that we have learned in the Cryptography lab. It replaces each character in a string by a different character of the alphabet defined by a simple shift. An encryption “Key” using a shift of 3 positions, shown in the table below. 6 Monash College MCD4700 Assignment 1 a b c d e f g h i j k l m n o p q r s t u v w x y z d e f g h i j k l m n o p q r s t u v w x y z a b c This is a very simple form of encryption. Please note the use of lower case alphabets only, and we will encrypt or decrypt only “alphabets”. One more example “Key” below is showing a Caesar Cipher with a shift of 5 positions. a b c d e f g h i j k l m n o p q r s t u v w x y z f g h i j k l m n o p q r s t u v w x y z a b c d e To encrypt, each letter in the top row is replaced by the corresponding letter in the bottom row, and to decrypt, each letter in the bottom row is replaced by the corresponding letter in the top row. In this part, your task is to implement subroutines that perform Caesar cipher substitution on a string, either performing encryption or decryption (cipher or decipher). You will implement the mapping in MARIE by a lookup table, storing the result of the substitution for each letter. The lookup table below maps an encryption key using a shift of 3 positions. myEncKey1Addr, ADR myEncKey1 myEncKey1, HEX 064 / a -> d HEX 065 / b -> e HEX 066 / c -> f HEX 067 / d -> g HEX 068 / e -> h HEX 069 / f -> i HEX 06A / g -> j HEX 06B / h -> k HEX 06C / i -> l HEX 06D / j -> m HEX 06E / k -> n HEX 06F / l -> o HEX 070 / m -> p HEX 071 / n -> q HEX 072 / o -> r HEX 073 / p -> s HEX 074 / q -> t HEX 075 / r -> u HEX 076 / s -> v HEX 077 / t -> w HEX 078 / u -> x HEX 079 / v -> y HEX 07A / w -> z 7 Monash College MCD4700 Assignment 1 HEX 061 / x -> a HEX 062 / y -> b HEX 063 / z -> c A subroutine to perform encryption on a string In this task, you will implement a MARIE subroutine called subCaesarEnc that can perform encryption using Caesar cipher substitution on a string whose start address is passed as an argument in the EncryptStr label. You need to use the string referred in section 2.1 (myString containing your first name and last name) to encrypt. You need to display the string before and after the encryption process. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table “myEncKey1”, and then store that value back into memory (overwriting the original letter). Think about how to get “a value” from a table. E.g., assume that the original letter is ‘k’, which is the 11th letter in the alphabet. So we need to load the 11th entry in the table– in other words, the entry at address myEncKey1Addr + 10 (which is HEX 06E or DEC 110, or the letter ‘n’). The letter ‘k’ has an ASCII value of HEX 06B (DEC 107). So, how do we determine to add ‘10’ to the address “myEncKey1Addr”? We simply subtract the ASCII value for the letter ‘a’, which is HEX 061 (DEC 97). So, in decimal notation, “117 - 97 = 10” or in HEX notation, “HEX 06B - HEX 061 = HEX A.” The following illustrated example explains the encryption process further. Here, the first name is “patrick”, and the last name is “lee.” And, it will be stored in the memory as shown below. 070 061 074 072 069 063 06B 020 06C 065 065 02E p a t r i c k l e e . During the encryption process, the following transformation (in the memory) will occur. p a t r i c k l e e s d w u l f n o h h And, the new encrypted string will be stored in the memory as shown below. 073 064 077 075 06C 066 06E 020 06F 068 068 02E s d w u l f n o h h . 8 Monash College MCD4700 Assignment 1 Please note that, during the encryption process, ASCII value for “SPACE” and ‘.’ remains unchanged. To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. You may use the following template to begin with. Here, we are (re)using the subPrintString subroutine from section 2.2. /printing the string before encryption Load myStringAddr / Load string start address Store PrintStringAddr / Pass as an argument Jns subPrintString / Call printing subroutine /calling the subroutine to perform encryption Load myStringAddr / Load string start address Store EncryptStr / Pass as an argument Jns subCaesarEnc / Call the cipher subroutine /printing the string after encryption Load myStringAddr / Load string start address Store PrintStringAddr / Pass as an argument Jns subPrintString / Call printing subroutine Halt /Your subroutine “subCaesarEnc” begins here. EncryptStr, Dec 0 / variable or label to store the start / address of a string subCaesarEnc, HEX 0 / label (subroutine name) to begin the / subroutine / Your codes….. ……… ……… /Your subroutine ends here. 2.4 A subroutine to perform decryption on a string (20 marks). In this part, we want to decrypt a string. To do that, we need a second table (in addition to the encryption table “myEncKey1 ” in section 2.3) that has the reverse mapping. Add a table “myDecKey1” to your code that is exactly the inverse of the “myEncKey1” table above. myDecKey1Addr, ADR myDecKey1 myDecKey1, HEX ??? / a -> x HEX ??? / b -> y …….. HEX ??? / z -> w 9 Monash College MCD4700 Assignment 1 Modify your subroutine in section 2.3 to create a new subroutine performing decryption. You can assume that the string only contains lower case characters. For each letter in the string, you will need to load the correct value for its substitution from the table, and then store that value back into memory (overwriting the original letter). The following illustrated example explains the decryption process further. Here, you will encrypt the string first, storing the encrypted string back in the memory, and then, decrypt this string back to the original form. In this example, the first name is “patrick”, and the last name is “lee.” And, it will be stored in the memory as shown below. 070 061 074 072 069 063 06B 020 06C 065 065 02E p a t r i c k l e e . During the encryption process, the following transformation (in the memory) will occur. p a t r i c k l e e s d w u l f n o h h And, the new encrypted string will be stored in the memory as shown below. 073 064 077 075 06C 066 06E 020 06F 068 068 02E s d w u l f n o h h . Now, you will decrypt the above string “sdwulfn ohh.” to its original form “patrick lee.” 070 061 074 072 069 063 06B 020 06C 065 065 02E p a t r i c k l e e . To receive full marks, your code needs to be in the form of a subroutine that can be called using the JnS instruction. You need to write a MARIE main program to call this subroutine. Please note that, as you need to encrypt the string first, so that you can decrypt an already encrypted string, there is a series of activities involved here [Print the original string-> Encryption -> Print the encrypted string-> Decryption -> Print the original string]. You may use the following template to begin with. /To print the original string Load myStringAddr / Load string start address Store PrintStringAddr / Pass as an argument Jns subPrintString / Call printing subroutine 10 Monash College MCD4700 Assignment 1 /Encrypting the string Load myStringAddr / Load string start address Store EncryptStr / Pass as an argument Jns subCaesarEnc / Call the Encryption cipher subroutine /print the encrypted string Load myStringAddr / Load string start address Store PrintStringAddr / Pass as an argument Jns subPrintString / Call printing subroutine /Decrypting the string Load myStringAddr / Load string start address Store DecryptStr / Pass as an argument Jns subCaesarDec / Call the Decryption cipher subroutine /print the decrypted string Load myStringAddr / Load string start address Store PrintStringAddr / Pass as an argument Jns subPrintString / Call printing subroutine Halt /Your subroutine “subCaesarDec” begins here. DecryptStr, DEC 0 / variable or label to store the start / address of a string subCaesarDec, HEX 0 / label (subroutine name) to begin the / subroutine / Your codes….. ……… ……… /Your subroutine ends here. 11 Monash College MCD4700 Assignment 1 Files to be submitted: One folder named “YourFirstNameLastNameStudentID” containing the following files: 1. Report for the written tasks (One Word file called YourFirstNameLastName StudentID.doc / docx). The report should include your Full name, your student ID, your class number and your tutor’s name. 2. Two Logisim files, one for task 1.2 and one for 1.3, name them LogicalCircuit.circ and OptimizedCircuit.circ respectively. 3. MARIE files for tasks 2.1 to 2.4 name them as below: ● 2_1_PrintString.mas ● 2_2_SubPrintString.mas ● 2_3_SubCaesarEncrypt.mas ● 2_4_SubCaesarDecrypt.mas Zip the folder under the same name and submit it to moodle. You need to make sure there are no spaces in any of the filenames. NOTE! Your submitted files must be correctly identified (as described above). Any submission that does not comply will receive an automatic 10 marks penalty (applied after marking). 12