讲解:CSE 220、MIPS、Python、PythonSQL|Prolog

CSE 220: Systems Fundamentals IStony Brook UniversityProgramming Project #2Spring 2019Assignment Due: Friday, March 15, 2019 by 11:59 pmLearning OutcomesAfter completion of this programming project you should be able to: Read and write strings of arbitrary length. Implement non-trivial algorithms that require conditional execution and iteration. Design and code functions that implement the MIPS assembly register conventions.Getting StartedVisit Piazza and download the file proj2.zip. Decompress the file and then open proj2.zip. Fill in thefollowing information at the top of proj2.asm:1. your first and last name as they appear in Blackboard2. 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 informationbut don’t remember until after the deadline has passed, don’t worry about it – we will track down your submission.Inside proj2.asm you will find several function stubs that consist simply of jr $ra instructions. Your jobin this assignment is implement all the functions as specified below. Do not change the function names, as thegrading scripts will be looking for functions of the given names. However, you may implement additional helperfunctions of your own, but they must be saved in proj2.asm. Helper functions will not be graded.If you are having difficulty implementing these functions, write out pseudocode or implement the functions in ahigher-level language first. Once you understand the algorithm and what steps to perform, then translate the logicto MIPS assembly code.Be sure to initialize all of your values (e.g., registers) within your functions. Never assume registers or memorywill hold any particular values (e.g., zero). MARS initializes all of the registers and bytes of main memory tozeroes. The grading scripts will fill the registers and/or main memory with random values before calling yourfunctions.Finally, do not define a .data section in your proj2.asm file. A submission that contains a .data sectionwill probably receive a score of zero.CSE 220 – Spring 2019 Programming Project #2 1Important Information about CSE 220 Homework Assignments Read the entire homework documents twice before starting. Questions posted on Piazza whose answers areclearly stated in the documents will be given lowest priority by the course staff. You must use the Stony Brook version of MARS posted on Piazza. Do not use the version of MARSposted 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 homework assignments. When writing assembly code, try to stay consistent with your formatting and to comment as much aspossible. It is much easier for your TAs and the professor to help you if we can quickly figure out what yourcode does. You personally must implement homework assignments in MIPS Assembly language by yourself. You maynot write or use a code generator or other tools that write any MIPS code for you. You must manually writeall 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 semesterand from previous semesters. Do not submit a file with the function/label main defined. You are also not permitted to start your labelnames with two underscores ( ). You will obtain a zero for an assignment if you do this. Submit your final .asm file to Blackboard by the due date and time. Late work will not be accepted orgraded. Code that crashes and cannot be graded will earn no credit. No changes to your submission will bepermitted once the deadline has passed.How Your CSE 220 Assignments Will Be GradedWith minor exceptions, all aspects of your homework submissions will be graded entirely through automatedmeans. 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 this homework assignment youwill be writing functions in assembly language. The functions will be tested independently of each other. This isvery important to note, as you must take care that no function you write ever has side-effects or requires that otherfunctions be called before the function in question is called. Both of these are generally considered bad practicein programming.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 benecessary, 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. Thenassemble and run your code as normal. Any excess output from your program (debugging notes, etc.) might impact grading. Do not leave erroneousprint-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 workwill 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 expectedresults used for testing will be released.CSE 220 – Spring 2019 Programming Project #2 2Register ConventionsYou must follow the register conventions taught in lecture and reviewed in recitation. Failure to follow them willresult in loss of credit when we grade your work. Here is a brief summary of the register conventions and howyour use of them will impact grading: It is the callee’s responsibility to save any $s registers it overwrites by saving copies of those registers onthe stack and restoring them before returning. If a function calls a secondary function, the caller must save $ra before calling the callee. In addition, ifthe caller wants a particular $a, $t or $v register’s value to be preserved across the secondary functioncall, the best practice would be to place a copy of that register in an $s register before making the functioncall. A function which allocates stack space by adjusting $sp must restore $sp to its original value beforereturning. Registers $fp and $gp are treated as preserved registers for the purposes of this course. If a functionmodifies one or both, the function must restore them before returning to the caller. There really is no reasonfor your code to touch the $gp register, so leave it alone.The following practices will result in loss of credit: “Brute-force” saving of all $s registers in a function or otherwise saving $s registers that are not overwrittenby a function. Callee-saving of $a, $t or $v registers as a means of “helping” the caller. “Hiding” values in the $k, $f and $at registers or storing values in main memory by way of offsets to$gp. This is basically cheating or at best a form of laziness, so don’t do it. We will comment out any suchcode we find.How to Test Your FunctionsTo test your implementated functions, open the provided main files in MARS. Next, assemble the main file andrun it. MARS will include the contents of any .asm files referenced with the .include directive(s) at the endof the file and then add the contents of your proj2.asm file before assembling the program.Each main file calls a single function with one of the sample test cases and prints any return value(s). You willneed to change the arguments passed to the functions to test your functions with the other cases. To test eachof your functions thoroughly, create your own test cases in those main files. Your submission will not be gradedusing the examples provided in this document or using the provided main file(s).Again, any modifications to the main files will not be graded. You will submit only your proj2.asm forgrading. Make sure that all code required for implementing your functions is included in the proj2.asm file.To make sure that your code is self-contained, try assembling your proj2.asm file by itself in MARS. If youget any errors (such as a missing label), this means that you need to refactor (reorganize) your code, possibly bymoving labels you inadvertently defined in a main file (e.g., a helper function) to proj2.asm.CSE 220 – Spring 2019 Programming Project #2 3A Reminder on How Your Work Will be GradedIt is imperative (crucial, essential, necessary, critically important) that you implement the functions belowexactly as specified. Do not deviate from the specifications, even if you think you are implementing theprogram in a better way. Modify the contents of memory only as described in the function specifications!The Bacon CipherIn this assignment you will implementing a simple encryption scheme known as Bacon’s cipher. For each lowercaseletter and for five other characters we assign a five-letter code as given in the below table:Character Encoding Character Encoding Character Encoding Character Encodinga AAAAA i ABAAA q BAAAA y BBAAAb AAAAB j ABAAB r BAAAB z BBAABc AAABA k ABABA s BAABA space BBABAd AAABB l ABABB t BAABB ! BBABBe AABAA m ABBAA u BABAA ’ BBBAAf AABAB n ABBAB v BABAB , BBBABg AABBA o ABBBA w BABBA . BBBBAh AABBB p ABBBB x BABBB eom BBBBBBBBAA is matched with a single quotation mark; BBBAB is matched with a comma. BBBBB is the codefor “end-of-message”, which is explained below.EncryptionEncryption requires a plaintext message, which may consist of any uppercase letters, lowercase letters and thefive other characters given in the table. The first step of encryption is to change all letters in the plaintext messageto lowercase. Then, each character of the modified plaintext is mapped to its five-letter code.For example, I’m.a.Seawolf!! is converted to i’m.a.seawolf!!. Then, each character is mappedto its five-letter code from the above table:ABAAA BBBAA ABBAA BBBBA AAAAA BBBBA BAABA AABAA AAAAA BABBA ABBBA ABABBi ’ m . a . s e a w o lAABAB BBABB BBABB BBBBBf ! ! eomWe refer to this encoding as “A/B text” of the encoded plaintext throughout this document. The end-of-messagemarker, BBBBB, is appended to the end of the A/B text, which is needed during the decryption process. Notethat the number of characters in the A/B text is exactly 5n + 5, where n is the length of the plaintext. Spacesbetween the five-letter codes are shown only for clarity and are not part of the actual A/B text.The encryption algorithm also requires a string of text that may contain any combination of any printable characters.This text will be manipulated to become the ciphertext. Each letter of the ciphertext will encode either anA or a B from the A/B text, while other non-letter characters carry no information. An A from the A/B text isencrypted in the ciphertext as a lowercase letter, whereas a B from the A/B text is encrypted in the ciphertext asCSE 220 – Spring 2019 Programming Project #2 4an uppercase letter. An example will help to clarify how this works.Suppose we wanted to encode the A/B given above in the text “Python features a dynamic type system andautomatic memory management. It supports multiple PROGRAMMING paradigms.” On line 1 of each blockbelow we see the ciphertext before the letter cases have been changed. On line 2 is the A/B text generated duringthe encoding process.Python features a dynamic type system and automatic memory management.ABAAAB BBAAABBA A BBBBAAA AAAB BBBABA ABA AABAAAAAA ABABBA ABBBAABABBIt supports multiple PROGRAMMING paradigms.AA BABBBABB BBABBBBB BBFinal ciphertext:pYthoN FEatuREs a DYNAmic typE SYStEm aNd auTomatic mEmORy mANAgeMeNT.it SuPPOrTS MUlTIPLE PROGRAMMING paradigms.Any letters from the ciphertext that follow the encoded end-of-message marker are left unmodified.DecryptionDecryption is fundamentally the reverse process of encryption. Note that the original cases of the letters in theplaintext are lost during encryption. Therefore, the decryption process will generally not exactly reproduce theoriginal plaintext message.Suppose we have the following ciphertext:Cse 220 AnD csE 320 FoRM A twO-CoURSe seQUeNce. 11001101 is a BInarY nUMBer.81FE2D is A bAsE-16 NUMBer. Base conversion is FUN!That ciphertext will be decoded into the following A/B text:BAABABAABBABBBAABBABBBAAABBABAAAAABBAAABABBBAABBBAABABABBBBBIf we overlay the ciphertext with A/B text we will see why:Cse 220 AnD csE 320 FoRM A twO-CoURSe seQUeNce. 11001101 is a BInarY nUMBer.BAA BAB AAB BABB B AAB BABBBA AABBABAA AA A BBAAAB ABBBAA81FE2D is A bAsE-16 NUMBer.BB B AAB ABABBBB BThe last few characters of the ciphertext don’t need to be decoded because they lie after the end-of-messagemarker, BBBBB.Now we take the A/B text and group it into five-letter groups that can be decoded:BAABA BAABB ABBBA ABBAB BBAAA BBABA AAAAB BAAAB ABBBA ABBBA ABABA BBBBBS T O N Y space B R O O KCSE 220 – Spring 2019 Programming Project #2 5The decrypted message is always generated in uppercase letters, regardless of the letter cases in the originalplaintext message.ImplementationBefore implementing the encryption and decryption algorithms we will need to write a few functions for workingwith strings.Part I: Convert a String to Lowercaseint to_lowercase(string str)This function takes a null-terminated string (possibly empty) and changes all of its uppercase letters to lowercase.All other characters in the string remain unchanged.The function takes the following arguments, in this order: str: The starting address of a null-terminated string.Returns in $v0: The number of letters changed from uppercase to lowercase.Additional requirements: The function must not write any changes to main memory except as specified.Examples:Function Argument Return Value Updated strWolfie Seawolf!!! 2019?? 2 wolfie seawolf!!! 2019?? 0 programming 0 programmingPart II: Compute a String’s Lengthint strlen(string str)This function takes a null-terminated string (possibly empty) and returns its length (i.e., the number of charactersin the string).The function takes the following arguments, in this order: str: The starting address of a null-terminated stringReturns in $v0: The length of the string, not including the null-terminator.Additional requirements:CSE 220 – Spring 2019 Programming Project #2 6? The function must not write any changes to main memory.Examples:Function Arguments Return ValueWolfie Seawolf!!! 2019?? 24MIPS 4 0Part III: Count the Number of Letters in a Stringint count_letters(string str)This function takes a null-terminated string (possibly empty) and returns the number of letters in the string.The function takes the following arguments, in this order: str: The starting address of a null-terminated stringReturns in $v0: The number of letters in the string.Additional requirements: The function must not write any changes to main memory.Examples:Function Arguments Return ValueWolfie Seawolf!!! 2019?? 13220 0 0Part IV: Encode Plaintext in “A/B” Format(int, int) encode_plaintext(string plaintext, char[] ab_text,int ab_text_length, char[] codes)This function takes the null-terminated string plaintext (possibly empty) consisting of lowercase letters,spaces and punctuation marks, and encodes each lowercase letter as its 5-letter uppercase Bacon code in ab text.After the last letter of plaintext has been encoded and stored in ab text, theCSE 220作业代写、代做MIPS留学生作业、代做Python语言作业、Python编程作业调试 代做数据库SQL|代 function writes the stringBBBBB into ab text immediately after after the last encoded letter. BBBBB is called the “end-of-messagemarker.” Because ab text might not be long enough to accommodate the fully-encoded plaintext, the functionencodes as many characters of the plaintext as possible, following them with the end-of-message code(BBBBB). The function does not null-terminate ab text. In some cases, ab text might not even be largeenough to store the end-of-message marker. See the examples below.CSE 220 – Spring 2019 Programming Project #2 7The function takes the following arguments, in this order: plaintext: The starting address of the null-terminated string to encode. ab text: The starting address of a memory buffer set aside to store the encoded plaintext. ab text length: The number of bytes in ab text. codes: The starting address of the array described below.The codes array will always have the following contents. This array is provided merely as a convenience toseveral of the functions for the assignment. Your functions are not required to use it.# The codes for lowercase letters a through z are followed by codes# for other characters..ascii AAAAA # a.ascii AAAAB # b.ascii AAABA # c# ... etc. ....ascii BBAAA # y.ascii BBAAB # z.ascii BBABA # space.ascii BBABB # exclamation mark.ascii BBBAA # quotation mark.ascii BBBAB # comma.ascii BBBBA # period.ascii BBBBB # end-of-message markerReturns in $v0: The number of lowercase letters from plaintext that were encoded as 5-letter codes in ab text. Thiscount does not include the end-of-message marker.Returns in $v1: 1 if the entire plaintext was sucessfully encoded in ab text; 0 if not all of the plaintext could be encodedin ab text.Additional requirements: The function must not write any changes to main memory except as specified. encode plaintext must call strlen.Examples:The examples given below do not cover every possible edge case your function might encounter. Think carefullyabout special cases and, if it is not clear to you how the function should handle a special case, post a question onPiazza.Case #1: plaintext is non-empty and ab text is large enough to encode the entire plaintext message,including the end-of-message marker. The function completely encodes the plaintext and returns N, 1, where NCSE 220 – Spring 2019 Programming Project #2 8is the number of characters in plaintext.Function arguments:plaintext = java! not. a. fan.ab_text = **************************************************************************************************ab_text_length = 98Return values: 18, 1Updated ab text: ABAABAAAAABABABAAAAABBABBBBABAABBABABBBABAABBBBBBABBABAAAAAABBBBABBABAAABABAAAAAABBABBBBBABBBBB***Case #2: plaintext is non-empty and ab text is not large enough to encode the entire plaintext message, butcan accommodate at least one plaintext character’s code, plus the end-of-message marker. The function encodesas much of the plaintext as possible, writes the end-of-message marker, and returns N, 0, where N is the numberof characters in plaintext that were successfully encoded.Function arguments:plaintext = we love mips...ab_text =ab_text_length = 63Return values: 11, 0Updated ab text: BABBAAABAABBABAABABBABBBABABABAABAABBABAABBAAABAAAABBBBBBBBBCase #3: plaintext is non-empty and ab text is not large enough to encode even a single character fromthe plaintext, but it does have enough room to store the end-of-message marker. The function writes only theend-of-message marker into ab text and returns 0, 0.Function arguments:plaintext = we love mips...ab_text = *********ab_text_length = 9Return values: 0, 0Updated ab text: BBBBB****Case #4: plaintext is non-empty and ab text is not large enough to encode even the end-of-messagemarker. The function writes no changes to ab text and returns 0, 0.CSE 220 – Spring 2019 Programming Project #2 9Function arguments:plaintext = we love mips...ab_text = @@@ab_text_length = 3Return values: 0, 0Updated ab text: @@@Case #5: plaintext is empty and ab text is large enough to encode the end-of-message marker. Thefunction writes the end-of-message marker to ab text and returns 0, 1.Function arguments:plaintext = ab_text = !!!!!!!!!!!!!!!!ab_text_length = 16Return values: 0, 1Updated ab text: BBBBB!!!!!!!!!!!Case #6: plaintext is empty and ab text is not large enough to encode the end-of-message marker. Thefunction writes no changes to ab text and returns 0, 0.Function arguments:plaintext = ab_text = gg!ab_text_length = 2Return values: 0, 0Updated ab text: gggPart V: Encrypt a Message(int, int) encrypt(string plaintext, string ciphertext, char[] ab_text,int ab_text_length, char[] codes)This function takes the null-terminated string plaintext (possibly empty) consisting of lowercase letters,spaces and punctuation marks, and encrypts the plaintext using Bacon’s cipher as explained earlier in the assignment,storing the result in ciphertext.The function takes the following arguments, in this order:CSE 220 – Spring 2019 Programming Project #2 10? plaintext: The starting address of the null-terminated string to encrypt. ciphertext: The starting address of the null-terminated string that will be modified to store the encryptedplaintext. The function may change the case of only those letters that must be changed to represent A/Bletters taken from the ab text. No other characters may be changed. For example, once BBBBB hasbeen represented as five sequential uppercase letters in the ciphertext string, no characters after those fiveletters from the ciphertext may be modified. See the examples below for further explanation. ab text: The starting address of a memory buffer created to store the encoded plaintext. You may notassume that ab text is long enough to encode the entire plaintext. In such cases, only a portion of theplaintext will be encrypted. ab text length: The number of bytes in ab text. codes: The starting address of the array of Bacon cipher codes described earlier in the assignment.Returns in $v0: The number of letters of ciphertext that actually encode A/B code letters. See the examples below forfurther explanation.Returns in $v1: 1 if the entire plaintext was successfully encrypted in ciphertext; 0 if not all of the plaintext could beencrypted because ab text is too short.Additional requirements: The function must not write any changes to main memory except as specified. As an example, this functionmust not write any changes to ab text; only encode plaintext may write such changes. encrypt must call to lowercase, count letters and encode plaintext.Examples:The examples given below do not cover every possible edge case your function might encounter. Think carefullyabout special cases and, if it is not clear to you how the function should handle a special case, post a question onPiazza.Case #1: plaintext is non-empty and ab text is large enough to encode the entire plaintext message,including the end-of-message marker. The function completely encrypts the plaintext and returns 5*(N+1), 1,where N is the number of characters in plaintext.Function arguments:plaintext = Stony Brookciphertext = CSE 220 and CSE 320 form a two-course sequence. 11001101 is abinary number. 81FE2D is a base-16 number. Base conversion isFUN!ab_text = *******************************************************************ab_text_length = 67CSE 220 – Spring 2019 Programming Project #2 11Return values: 60, 1Updated plaintext: stony brookUpdated ciphertext: Cse 220 AnD csE 320 FoRM A twO-CoURSe seQUeNce. 11001101is a BInarY nUMBer. 81FE2D is A bAsE-16 NUMBer. Base conversion is FUN!Note that the substring E-16 NUMB encodes end-of-message marker, BBBBB and that the remainder of theinitial ciphertext remains unchanged: er. Base conversion is FUN!.Case #2: plaintext is non-empty and ab text is not large enough to encode the entire plaintext message,but can accommodate at least one plaintext character’s code, plus the end-of-message marker. The functionencrypts as much of the plaintext as possible and returns 5*(N+1), 0, where N is the number of characters inplaintext that were successfully encrypted.Function arguments:plaintext = I’m.a.Seawolf!!ciphertext = Python features a dynamic type system and automatic memorymanagement. It supports multiple PROGRAMMING paradigms.ab_text = &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ab_text_length = 72Return values: 70, 0Updated plaintext: i’m.a.seawolf!!Updated ciphertext: pYthoN FEatuREs a DYNAmic typE SYStEm aNd auTomatic mEmORymANAgeMeNT. it SuPPORTS multiple PROGRAMMING paradigms.Case #3: plaintext is non-empty and ab text is not large enough to encode even a single character fromthe plaintext, but it does have enough room to store the end-of-message marker. The function encrypts only theend-of-message marker and returns 5, 0.Function arguments:plaintext = Wolfie Seawolfciphertext = Python features a dynamic type system and automatic memorymanagement. It supports multiple programming paradigms.ab_text = ******ab_text_length = 6Return values: 5, 0Updated plaintext: wolfie seawolfUpdated ciphertext: PYTHOn features a dynamic type system and automatic memoryCSE 220 – Spring 2019 Programming Project #2 12management. It supports multiple programming paradigms.Case #4: plaintext is non-empty and ab text is not large enough to encode even the end-of-messagemarker. The function writes no changes to ab text or ciphertext and returns 0, 0.Function arguments:plaintext = Wolfie Seawolfciphertext = Python features a dynamic type system and automatic memorymanagement. It supports multiple programming paradigms.ab_text = %%ab_text_length = 2Return values: 0, 0Updated plaintext: Wolfie SeawolfUpdated ciphertext: Python features a dynamic type system and automatic memorymanagement. It supports multiple programming paradigms.Case #5: plaintext is empty and ab text is large enough to encode the end-of-message marker. Thefunction call to encode plaintext writes the end-of-message marker to ab text and then encrypt returns5, 1.Function arguments:plaintext = ciphertext = The Scholars program is a vibrant community of high-achievingstudents at Stony Brook.ab_text = !!!!!!!!!!!!!!!!ab_text_length = 16Return values: 5, 1Updated plaintext: Updated ciphertext: THE SCholars program is a vibrant community of high-achievingstudents at Stony Brook.Case #6: plaintext is empty and ab text is not large enough to encode the end-of-message marker. Nochanges are written ab text or plaintext. The function returns 0, 0.Function arguments:plaintext = ciphertext = The Scholars program is a vibrant community of high-achievingstudents at Stony Brook.CSE 220 – Spring 2019 Programming Project #2 13ab_text = !!!!ab_text_length = 4Return values: 0, 0Updated plaintext: Updated ciphertext: The Scholars program is a vibrant community of high-achievingstudents at Stony Brook.Part VI: Decode Ciphertext into an “A/B” Stringint decode_ciphertext(string ciphertext, char[] ab_text, int ab_text_length,char[] codes)This function takes a string of ciphertext and decodes it into a string of A and B characters. In sequential manner,starting at the leftmost character of ciphertext, each lowercase letter is encoded as an A character in ab text,and each uppercase letter is encoded as a B character in ab text. Non-letter characters in ciphertext aresimply ignored. You may assume that the end-of-message marker is encoded somewhere in the ciphertext. Thefunction does not null-terminate the ab text string.If the number of letters in ciphertext is greater than the length of ab text, the function returns -1 andmakes no changes to memory.The function takes the following arguments, in this order: ciphertext: The starting address of the null-terminated ciphertext string to decode as explained above. ab text: The starting address of a memory buffer created to store the decoded ciphertext. ab text length: The size of the ab text in bytes. codes: The starting address of the array of Bacon cipher codes described earlier in the assignment.Returns in $v0: The number of characters written to ab text by the function, or -1 on error as described above.Additional requirements: The function must not write any changes to main memory except as specified. decode ciphertext must call strlen and count letters.Examples:The examples given below do not cover every possible edge case your function might encounter. Think carefullyabout special cases and, if it is not clear to you how the function should handle a special case, post a question onPiazza.Case #1: ab text is exactly the right length to store the decoded ciphertext.CSE 220 – Spring 2019 Programming Project #2 14Function arguments:ciphertext = AbcDefgHijkLMnOpqrSTUVwXyzaBCDefGhijKlMNoPQRSTUvWXYZABCab_text = ///////////////////////////////////////////////////////ab_text_length = 55Return value: 55Updated ab text: BAABAAABAAABBABAAABBBBABAAABBBAABAAABABBABBBBBBABBBBBBBCase #2: ab text has bytes leftover after storing the decoded ciphertextFunction arguments:ciphertext = sHARDPLate Is aN AncIENt AND maGIcAL TyPe OF fUlL-BODy ARMOrFOUNd ON ROsHAr. It iS infUseD wITh StoRMLigHt AnD GRANtsgreat power.ab_text = ******************************************************************************************************************ab_text_length = 114Return value: 95Updated ab text: ABBBBBBAAABAABBAABBBABBBAABBABBBABABBABABBBBABBBBABBBBABBBBABBABAABAAABAABABBABAABBBAABABABBBBB*******************Case #3: ciphertext contains only the end-of-message marker.Function arguments:ciphertext = 2019 GO STONY BROOK!ab_text = +++++++++++++++ab_text_length = 15Return value: 5Updated ab text: BBBBB++++++++++Part VII: Decrypt a Messageint decrypt(string ciphertext, string plaintext, char[] ab_text,int ab_text_length, char[] codes)This function takes a ciphertext string as its first argument, calls decode ciphertext to transform the ciphertextinto an A/B string, and then finally decrypts the A/B string, storing the decrypted plaintext in the givenplaintext buffer. The function null-terminates the plaintext before returning.CSE 220 – Spring 2019 Programming Project #2 15If the call to decode ciphertext returns -1, decrypt returns -1 and makes no changes to memory.The function takes the following arguments, in this order: ciphertext: The starting address of the null-terminated ciphertext string to decrypt. plaintext: The starting address of a memory buffer to store the plaintext. The buffer is guaranteed to belarge enough to store the decrypted message and a null-terminator. ab text: The starting address of a memory buffer created to store the decoded ciphertext. ab text length: The size of the ab text in bytes. codes: The starting address of the array of Bacon cipher codes described earlier in the assignment. Notethat this argument will be passed to decrypt on the stack at memory address 0($sp).Returns in $v0: The number of characters in the decrypted message, not including the null-terminator written by the function,or -1 on error as described above.Additional requirements: The function must not write any changes to main memory except as specifie转自:http://www.3daixie.com/contents/11/3444.html

你可能感兴趣的:(讲解:CSE 220、MIPS、Python、PythonSQL|Prolog)