Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. top (6 marks) Let us try working with a memory location for storing data. Replace the program code window's content with this: gete ifzero

image text in transcribed
image text in transcribed
2. top (6 marks) Let us try working with a memory location for storing data. Replace the program code window's content with this: gete ifzero show print add sume store sume gote tope show load sume printe stope sum 0 By the name I have given the memory location sum, you might suspect that this program adds up a list of number values, and you would be right. To see that this is the case, run the program and enter the same sequence of input values that you used for part 1, above. When the value of sum is loaded into the accumulator, and then printed, its value should be 10. Let us modify the program so that it not only prints out the sum, but the number (count) of non- zero values that were entered, too. Here is how: 1. Start by adding a memory address label called count to the bottom of the program code (i.e., under 'sum O') and give it an initial value of 0. 2. Insert a new instruction (on a new line) after the store sum instruction to load the value of count into the accumulator. (Hint: the instruction is load count'. Remember that instructions must be indented!) 3. Insert an instruction after that to add I to the value in the accumulator. 4. Insert an instruction after that to store the value in the accumulator at the memory location you have labelled count. (This will automatically overwrite whatever happens to be stored there.) 5. Insert an instruction after the final 'print' that loads the value stored at memory location count into the accumulator 6. Insert a print instruction after that. (It should be immediately above the 'stop'instruction.) If you have done your work properly, you should end up with a program that is 16 lines long (more if you have added any comments - that is entirely optional), and that when run with the same input data as that used the program in part 1, gives the following output:- 64 -24 5 10 stoppede (where the 10 represents the sum, and the 4 represents the number of input values.) Test your program on some other input, until you are satisfied that it is working correctly. Copy your code into a text file called Lab03_2.toy for inclusion in your solution zip file. 2. top (6 marks) Let us try working with a memory location for storing data. Replace the program code window's content with this: gete ifzero show print add sume store sume gote tope show load sume printe stope sum 0 By the name I have given the memory location sum, you might suspect that this program adds up a list of number values, and you would be right. To see that this is the case, run the program and enter the same sequence of input values that you used for part 1, above. When the value of sum is loaded into the accumulator, and then printed, its value should be 10. Let us modify the program so that it not only prints out the sum, but the number (count) of non- zero values that were entered, too. Here is how: 1. Start by adding a memory address label called count to the bottom of the program code (i.e., under 'sum O') and give it an initial value of 0. 2. Insert a new instruction (on a new line) after the store sum instruction to load the value of count into the accumulator. (Hint: the instruction is load count'. Remember that instructions must be indented!) 3. Insert an instruction after that to add I to the value in the accumulator. 4. Insert an instruction after that to store the value in the accumulator at the memory location you have labelled count. (This will automatically overwrite whatever happens to be stored there.) 5. Insert an instruction after the final 'print' that loads the value stored at memory location count into the accumulator 6. Insert a print instruction after that. (It should be immediately above the 'stop'instruction.) If you have done your work properly, you should end up with a program that is 16 lines long (more if you have added any comments - that is entirely optional), and that when run with the same input data as that used the program in part 1, gives the following output:- 64 -24 5 10 stoppede (where the 10 represents the sum, and the 4 represents the number of input values.) Test your program on some other input, until you are satisfied that it is working correctly. Copy your code into a text file called Lab03_2.toy for inclusion in your solution zip file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions