Question
Here is the pseudocode algorithm from the textbook: Write How many pairs? Read numberOfPairs Set numberRead to 0 While (numberRead < numberOfPairs) Write Enter two
Here is the pseudocode algorithm from the textbook:
Write "How many pairs?"
Read numberOfPairs
Set numberRead to 0
While (numberRead < numberOfPairs)
Write "Enter two numbers: "
Read number1
Read number2
If (number1 < number2)
Print number 1, " ", number2
Else
Print number2, " ", number1
Set numberRead to numberRead + 1
Modify this pseudocode algorithm so that it uses an event controlled loop which ends when the user enters a sentinel value for the first number (for example, your sentinel could be an unusual number like 999, but you can decide what the sentinel value should be). Write a test plan for this program. Write the program in assembly language and test it using your test plan.
Hint:
To turn the loop from counter-controlled to event-controlled:
Eliminate the numberOfPairs variable.
Create a variable for the sentinel value and initialize it to the value you chose for the sentinel.
Eliminate the prompt that asks for the number of pairs.
Change the prompt for the input values to: "Enter two numbers or XXX to end: " where XXX is your sentinel value.
Write the prompt and read number1 before the While loop.
Change the condition in the While loop to see if number1 equals the sentinel value
Inside the loop:
Read number2
Write out the selection statement to determine which number to write first and which number to write second.
Write the prompt again and read in number1
For the test plan, consider how many test cases you will need. At a minimum you will need 3 test cases:
1.One where the first number entered is smaller than the second number.
2.One where the first number entered is larger than the second number.
3.One where the sentinel value is entered for the first number.
To start your assembly language code:
Start with an unconditional branch (BR main) to the start of your instructions.
Follow that with your assembler directives to allocate for your sentinel value (use .Word to set it to your sentinel value), number1 and number2 (use .Block 2 to allocate 2 bytes for each number).
To allocate storage for the prompt, use .ASCII. "Enter two numbers or XXX to end\x00" (the \x00 is called the null terminator and tells the computer when it has reached the end of the string).
To output a string, use STRO prompt,d.
To compare the first number to your sentinel value to see if they are the same:
Load the first number in the accumulator
Use CPA sentinel,d to compare the number in the accumulator with the sentinel value in memory.
Use BREQ, finish which will branch to the end of the program if the number entered and the sentinel are the same, otherwise the program will branch back to the beginning of the loop (main).
Use CPA and BRGT (or BRLE) to see if num1 is > num2. Remember that this selection statement will print out either num1 first or num2 first depending on results of your test. In either case, use an unconditional branch back to main to continue the loop if the sentinel value was not entered.
To output a number, use DECO. To output a space between the numbers use CHARO ' ', i. To output a new line at the end, use CHARO ' ', i.
Turn in:
Your pseudocode algorithm
Your test plan
The assembly language source code (which will have .pep extension when saved). Verify that your source code saved correctly before turning it in.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started