Basics of String Manipulation in Python Project

2. MARIE (50 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 the code, test your code with sample inputs and write a small analysis explaining the expected outcome. Your MARIE program must contain brief comments explaining the purpose of your subroutines and main programs (to be written in the .mas file). You must submit your code as .mas files together with the rest of your assignment. The description of your experiences while testing your code with test inputs and the subsequent analysis needs to be submitted as part of the main PDF file you submit for this assignment.

In some cases wherever it is appropriate, you may add test data to your program to prepare test cases. These test cases, which are mostly appropriate for programs processing numeric data, should be working without requiring much input from the user, i.e. a self-contained MARIE assembly program. The following section introduces some concepts that you need for the rest of the assignment. Name as Strings 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 a single character. ● The characters are encoded using the ASCII encoding. End of a string is marked by the ASCII character comma ‘,’. ● A name will be composed of two strings, namely, First Name and Last Name.

● End of a name will be marked by another ASCII character dot ‘.’. Representation of Strings in Memory using ASCII code An illustrated example below showing how a name “John Noah” would be represented in memory (written as hexadecimal numbers): Note that for a string with n characters, we need n + 2 words of memory in order to store all the characters belonging to a first name, a last name, the additional ‘,’ and ‘.’. Strings in MARIE In MARIE assembly language programming, we can make use of the ADR command, the HEX keyword and a label “myName” to put a string into memory: myNameAdd, ADR myName myName, HEX 04A /J HEX 06F //o HEX 068 //h HEX 06E //n HEX 02C //, HEX 04E //N HEX 06F //o HEX 061 //a HEX 068 //h HEX 02E //. After assembling the above MARIE code, we will find that the variable (or label) myNameAdd contains the address of the string i.e. the address of the first character ‘J’ of the string “John Noah”. An example below shows how to access the first character of the above string and display: start, LoadI Output ……… Halt myNameAdd 2.1 Write a MARIE Program to Store Multiple User Entered Names in Consecutive Memory Rows and Print Them at the End of Data Entry. (20 marks) Prepare a MARIE program to enter full names using Unicode / ASCII characters. Limit each part of a name (First Name or Last Name) to at most 5 characters – if a name is longer, you can shorten it (limit the maximum number of characters per full name to 12). After assembling and running your MARIE program, it should prompt for entering names using a keyboard. For the MARIE simulator, Unicode input from the keyboard can only be entered character by character. Your program should store the names in MARIE memory and print them at the end.

(i). Subroutine subInputNames: The first part of your program should focus on getting the full names as input from the keyboard and storing them in a particular location in MARIE memory. For this task, prepare a MARIE subroutine called subInputNames. Your subroutine should input (Unicode /ASCII) ‘,’ terminated First name and (Unicode /ASCII) ‘.’ terminated Last name as described in the previous section. The names have to be stored starting from the memory address 300H. A single name (First Name and Last Name) is to be stored in one row of MARIE memory. After entering a full name, a Unicode/ASCII ‘.’ will be stored to mark the end of the name in the memory, and the program should proceed to take the next name, which is to be stored at memory location 310H. This location is one row (16 words) ahead from the memory location of the previous name entry. You can use memory locations 320H, 330H , … to store more names respectively.

After entering a full name, a ‘$’ from input will terminate the entire name entry process and will return control to the calling program. You have to store the ‘$’ in the memory to mark the end of the name database. Your program must be capable of accepting names one after the other, until a user enters a ‘$’ to stop taking inputs. You can verify the correct working of your program by viewing the memory content starting from #300H. (ii). Subroutine subPrintString: In the second part of your program, prepare a MARIE subroutine called subPrintString that can print all the full names stored. This subPrintString subroutine should access all the full names in the memory (that are entered and saved by the subInputNames earlier) and printout using the “Output” instruction. Start by using a label “PrintNameAdd” that holds the start address of a name string (like, myNameAdd in the example above). The code should then load a character from that address, output it if it is not ‘,’, then increment the address by one, and keep doing that until the character loaded from the address is a ‘,’ (which signals the end of the first name).

Then, instead of printing (or output) the ASCII “,” character, print an ASCII “Space” character, and proceed to print the second part of the name string, i.e. Last Name until the character loaded from the address is a ‘.’ (which signals the end of the Last Name). Then, when you load the ASCII ‘.’ which marks the “end of a name”, instead of printing (or output) the ASCII “.” character, print an ASCII “New Line” character. Then your program should proceed to print the next name. If the loaded character is ‘$’, the subroutine needs to stop printing and gives control to the main program. While testing your code and writing the test cases for this task, you have to use at least three names (your First Name and Last Name, your friend’s name and your tutor’s name). Please note that these names should not be hard coded and assigned labels to identify each of these three names. To receive full marks, your code needs to be in the form of a main program and use of subroutine that can be called using the JnS instruction. Save your code as “2_1_Enter_and_PrintingNames.mas”. 2.2 A MARIE Subroutine to Convert Names to UpperCase and Print (15 marks) Write a subroutine to change and print all characters of the user entered name strings to UPPER CASE characters. Name the subroutine as subToUpperCase.

This subroutine modifies all characters of a string in memory to upper case. The program should then print the original name string and the modified upper case string. Submit your MARIE code and documentation of test cases converting at least three names. To receive full marks, the main program from section 2.1 must be extended to print the original name string and the modified upper-case name string by calling the respective subroutines. Name your MARIE code file as “2_2_UpperCase.mas”. Hint: you can easily identify the lowercase ASCII value ranges through the ASCII table and notice the numeric difference between the uppercase and lowercase characters. Names in Upper Case 2.3 A Three Function Calculator in MARIE (15 marks) In this task, you will develop a MARIE program that performs three mathematical functions of a calculator – multiplication, division and exponent. The program should be performing the user selected tasks (one of the mentioned mathematical operations) after the user enters one of the selections, ‘m’, ‘d’, or ‘e’. Here, input ‘m’ selects the multiplication process, ‘d’ selects the division process and ‘e’ is for calculating the exponent. User enters ‘q’ to quit the program. If the user input is ‘m’, ‘d’, or ‘e’, then the program should ask for operands x and y and display the result.

Example: ● INPUT SELECTION = ‘m’ and the input numbers are ‘x’ & ‘y’ then the resultant output = ‘x * y’ ● INPUT SELECTION = ‘d’ and the input numbers are ‘x’ & ‘y’ then the resultant output = ‘x/y’ ● INPUT SELECTION = ‘e’ and the input numbers are ‘x’ & ‘y’ then the resultant output = ‘xy’ ● INPUT SELECTION = ‘q’ simply quits the program and exit. The program should run infinitely, until a user enters ‘q’. You are required to write subroutines (for each operation) to perform these tasks (multiplication, division and exponent) and write a main program to process user operation selection, accept the ‘x’ & ‘y’ inputs and call the appropriate subroutine thereof. The codes must contain comments, as a paragraph before any block of code (i.e. subroutine) or as inline comments wherever appropriate. You should submit the “2_3_Calculator.mas” file together with the rest of your assignment. Files to be submitted: 4. Task 2.1 – MARIE File. Name the file as “2_1_Enter_and_PrintingNames.mas”. 5. Task 2.3 – MARIE File. Name the file as “2_2_UpperCase.mas”. 6. Task 2.2 – MARIE File. Name the file as “2_3_Calculator.mas”. Zip the folder with this name (YourFirstName_LastName_StudentID.zip) and submit it to Moodle. You need to make sure there are no spaces in any of the filenames. End of Assignment 1 Page 1 of 8.

Do you have a similar assignment and would want someone to complete it for you? Click on the ORDER NOW option to get instant services at EssayBell.com