CIS 21JA - Assignment 8
In addition to covering string instructions and 2D a
ays, this last lab also reviews concepts that are covered this quarter. Class notes from earlier modules can be helpful.
Overview
Write a program that stores user input strings in a 2D a
ay. Then the program tells the user whether a specified string is a palindrome.
A palindrome is a string that reads the same forward and backward. (Here's a humorous view of a palindrome)
Requirements
Here are the ordered steps to complete your program:
1. Create 2 constants called ROW and COL that specify the size of the 2D a
ay.
· Set ROW to 4, COL to 20
· Make sure ROW and COL are constants (not memory variables), and define them at the top of the program so they're easily found. To test your program you will set these 2 constants to different values, so the easier it is to find them, the faster you can test.
2. Write a macro that accepts an integer as input, and then prints the integer followed by a space character.
3. In the .data section, define a 2D a
ay with ROW and COL size.
Make sure you use ROW and COL to define the a
ay, don't use immediate values (literal constants) like 3 or 5.
During testing, when you set ROW and COL to different values, the 2D a
ay should change size accordingly and your code should change behavior accordingly.
Below is an example of a 2D a
ay with ROW = 3, COL = 10, filled with 2 strings: "21JA" and " XXXXXXXXXX"
2
1
J
A
0
0
0
0
0
0
1
2
3
4
5
4
3
2
1
0
0
0
0
0
0
0
0
0
0
0
Other than the 2D a
ay and text strings, the .data section should not contain any other memory variable.
4. Write the main procedure that does 2 tasks:
A. Call a fillA
ay procedure that uses the stack to pass data.
1. Pass to it the 2D a
ay and any necessary text string addresses
2. Receive a return value which is the number of text strings that are in the a
ay (the return value is 2 for the example a
ay above)
B. Loop to ask the user to select a string from the a
ay and print whether the string is a palindrome or not.
1. The user can keep selecting a string location (a number) until -1 is entered
2. Check that the string location is within the valid number of strings or keep prompting (see sample output below)
3. When the user selection is valid, call the checkString procedure:
a. Use the stack to pass to it the 2D a
ay, the number of strings, and the user selection
. Receive a return value of 1 (palindrome) or 0 (not a palindrome)
4. Based on the return value, main prints the appropriate text.
5. Write the fillA
ay procedure Â
· Loop to ask for a string and store it in the next available row of the a
ay. You can assume the user will enter a string that is shorter than the COL number.
· Stop the loop when one of these conditions occurs:
· when all rows of the a
ay are filled, or,
· when the user chooses to stop by hitting the enter key only
· When the loop to input strings is done, call a printA
ay procedure that uses registers to pass data.
· Pass to it the 2D a
ay, the number of strings in the a
ay, and any necessary text string addresses
· See the sample output for how the a
ay is printed
6. Write the printA
ay procedure
· print a header line (see sample output below)
· for each string, print a number and a space (use the macro), and then print the string.
Numbering starts at 1 and increments.
7. Write the checkString procedureÂ
· Use the input parameters (2D a
ay and user input number) to get to the co
ect string
· Use string instructions to check if the string is palindrome.
· Return 1 for palindrome, 0 for not a palindrome
Testing
Here are the test cases I will run with your program:
· change ROW and COL
· strings that are: not palindrome, palindrome with even string length, palindrome with odd string length
· try to enter more strings than ROW
· enter invalid string numbe
Sample output
Enter text string: 12321
Enter text string: abc
Enter text string: noon
Enter text string:
List of strings
1 12321
2 abc
3 noon
Enter string number (-1 to end): 0
Enter string number (-1 to end): -2
Enter string number (-1 to end): 1
Palindrome
Enter string number (-1 to end): 2
Not a palindrome
Enter string number (-1 to end): 3
Palindrome
Enter string number (-1 to end): 4
Enter string number (-1 to end): -1
Press any key to continue . . .
Additional reminders
- Use string instructions when you need to walk a string and access data.
- Procedures should pass data through the stack or through registers as required.
- Except for main, no other procedure should directly access data defined in .data.
- Other than the 2D a
ay and text strings, you should not use any other memory variables in .data