08 Jun Part I Write a program called A2P1 to run in the LC-3 simulator. The program asks for the user to type in
Question
Part I
Write a program calledA2P1 to run in the LC-3 simulator. The program asks for the user to type in his or her UPI. Then the program asks for the age of the user and prints the UPI out that many times. Here is an example of input and what should be produced in the simulator’s console window.
For Part I you may assume (in fact you must assume) that the input provided will always match what is expected. i.e. do not consider what would happen if the user makes a mistake entering data.
The program should work exactly like this:
The program displays “Enter your upi: “.
It then waits until the user has typed 7 characters (these get stored by the program).
The characters typed by the user are shown on the console as the user types them.
After the 7th character the console output goes to the next line automatically without the user having to type return/enter and displays “Enter your age: “
It then waits until the user has typed a number (you may assume it will always be between 0 and 999) and has pressed return/enter.
Once again the characters typed by the user are shown (echoed) on the console as the user types them.
Then the program prints the upi the same number of times as the user’s entered age. Each upi appears on a separate line.
Then the program halts.
Page 1
Part II
This program should be calledA2P2. This part is very similar to Part I, however you have no guarantees about the accuracy of the input from the user. You have to check all input and give helpful error messages to assist the user. In particular you must ensure that the user does not enter more data than your program is able to safely accept, i.e. you must prevent buffer overflows. If the user enters valid input then the program should behave exactly as the program in Part I with the exception that the user has to press return/enter after typing in his or her UPI.
You also have to include a function in your program namedpromptInput which is called twice (usingJSR). ThepromptInput function takes three parameters:
1. the address of the prompt string e.g. “Enter your upi: “
2. the address of the buffer to hold the typed input
3. the length of the buffer (this will have to be 1 more word than the expected maximum number of characters the user will type), why?
The function should return a value of 0 to its calling context if the input fits in the buffer or -1 if the user types in too many characters.
As soon as the user types more characters than can fit in the buffer your program should respond with the message “You have entered too many characters, you must startagain.” This message appears without the user having to type return/enter. It appears on a newline and after this the program once again prompts the user either for a UPI or an age (depending on what the user was doing at the time of the buffer overflow).
Once the UPI has been entered in thepromptInput function it then needs to be checked for validity. A valid UPI for this assignment consists of 4 lowercase alphabetical characters followed by 3 digits. If an invalid UPI is typed the program responds with the message “Invalid upi. Tryagain.” on a new line. Then the program asks “Enter your upi:“ again and the programcontinues.
Similarly the age needs to be checked for validity. Valid ages are any value from 0 to 999 (ok not very realistic). Only digits are valid e.g. if the user enters “_23” with the first character being a space this should be rejected. If an invalid age is typed the program responds with the message “Invalid age. Try again.” on a new line. Then the programs asks “Enter your age: “ again and the program continues.
Hints
Be careful when calling a function/subroutine which includesTRAP instructions orJSR instructions. R7 is used by both of these to store the return address. If you don’t save the return address somewhere else you won’t be able to get back to where you were coming from.
The console window in the LC-3 simulator only allows up to about 21 lines of output. You can also dump the output to a file using “Start Console File …” from theFile menu.
Page 2
Marking Guide
Part I (8 marks)
Displays “Enter your upi: “ (1 mark)
Accepts exactly 7 characters and echoes them to the console. Moves on to the next line after 7 characters without waiting for return/enter. (2 marks)
Displays “Enter your age: “. Accepts ages from 0 to 999. Waits for return/enter before progressing. Echoes digits to the console. (2 marks)
Prints upi on separate lines the correct number of times. (3 marks)
Part II (9 marks)
Clearly shows thepromptInput function in your code. Comments include a careful description explaining the use of all registers for passing parameters and returning the result of the function. Also a description of how you handle storing the return address. (3 marks)
Does not allow buffer overflows (7 chars for the UPI, 3 digits max for the age). User has to reenter as specified if a buffer overflow occurs. (2 marks)
Only valid UPIs accepted. User has to reenter as specified if invalid. (2 marks)
Only valid ages accepted. User has to reenter as specified if invalid. (2 marks)
Style
All files submitted include the UPI in the starting comment. (1 mark)
Sections of code are clearly commented and laid out consistently. (1 mark)
Contents of registers are shown. (1 mark)
Total (20 marks)
Page 3
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
