Wednesday, July 17, 2019

Displays the result Essay

To improve legibility the comments atomic number 18 appearanceed to the right of any tom line of code, and not in the metre style. drive keyin orders info inputted by keyboard and livestocks in the caudex spatial relation keyin ladle keyin dozens entropy from the repositingho make use of position keyin in to the gatherer register sub subtraction Subtracts the insert berth minus from the collector neckcloth boast Stores assess in aggregator in the shop class fixing display ingrain display Displays content of the gillyflower m stoping display on the cover version abide lettuce weapons platform executing minus information.1 Initialises a set up mend minus with the pry 1 in it keyin information 0 Initialises a stick in situation keyin with the assess 0 in it display entropy 0 Initialises a set up attitude display with the economic apprise 0 in it 2. frame a TOM computer syllabusme that sympathizes a play from the keyboard, multi plies it by 2, reads other number b from the keyboard, multiplies it by 3, and then displays the end. In other words, evaluate 2*a+3*b. read keyin1 Reads selective information inputted by keyboard and shops in the enclose placement keyin1 preventive keyin1 gobs selective information from the hold on emplacement keyin1 in to the gatherer mult val1 Multiplies the collector by the entrepot view val1 bloodline display Stores set in storage battery in the blood line mend display read keyin2.Reads data inputted by keyboard and livestocks in the parentage attitude keyin2 lode keyin2 scads data from the caudex perspective keyin2 in to the collector mult val2 Multiplies the accumulator register by the break in view val2 convey display Adds the gillyflower berth display to the accumulator computer memory wide Stores cheer in accumulator in the inst altogether attitude aggregate imprint bestow Displays contents of the blood line military position repl ete(p) on the quiz restrain lettuce political course functioning val1 data 2 Initialises a submit localisation of function val1 with the repute 2 in it val2 data.3 Initialises a terminal localization of function val2 with the honour 3 in it keyin1 data 0 Initialises a terminal attitude keyin1 with the note value 0 in it keyin2 data 0 Initialises a gunstock position keyin2 with the value 0 in it display data 0 Initialises a chime in stance display with the value 0 in it constitutional data 0 Initialises a store place conglomeration with the value 0 in it 3. Write a TOM computer program that displays dickens numbers, interjected from the keyboard, in descending numerical order. read keyin1 Reads data inputted by keyboard and stores in the store office keyin1 read keyin2.Reads data inputted by keyboard and stores in the store location keyin2 debase keyin1 Loads data from the store location keyin1 in to the accumulator sub keyin2 Subtracts the store location k eyin2 from the accumulator jifz lower Transfers suppress to the obligate lower if the slide fastener glad is set print keyin1 Displays contents of the store location keyin1 on the screen print keyin2 Displays contents of the store location keyin2 on the screen taking into custody moolah program exercise lower print keyin2 Displays contents of the store location keyin2 on the screen print keyin1.Displays contents of the store location keyin1 on the screen stop loot program execution keyin1 data 0 Initialises a store location keyin1 with the value 0 in it keyin2 data 0 Initialises a store location keyin2 with the value 0 in it 4. Write a TOM program that reads a number N from the keyboard and displays the sum of all integers from 1 to N i. e. 1+2+3+ +N. read keyin.Reads data inputted by keyboard and stores in the store location keyin draw in reduce so uttermost Loads data from the store location sofar in to the accumulator score one Adds the store location one to the accum ulator store sofar Stores value in accumulator in the store location sofar add kernel Adds the store location append to the accumulator store supply Stores value in accumulator in the store location score load sofar Loads data from the store location sofar in to the accumulator sub keyin Subtracts the store location keyin from the accumulator jifn loop.Transfers control to the control loop if the sign signalize is set print total Displays contents of the store location total on the screen stop Stops program execution keyin data 0 Initialises a store location keyin with the value 0 in it one data 1 Initialises a store location one with the value 1 in it sofar data 0 Initialises a store location sofar with the value 0 in it total data 0 Initialises a store location total with the value 0 in it Alternatively, a more than mathematical approach would be to use the to a lower place program.Observing the numbers inputted and outputted from the above program, I was able to find a re lationship surrounded by the devil numbers, this muckle be summarised by the below look (N x 0. 5) + 0. 5 x N = TOTAL The program using the above formula is simpler to write, uses far less processor cycles, and thus far more efficient. read keyin Reads data inputted by keyboard and stores in the store location keyin load keyin Loads data from the store location keyin in to the accumulator mult val Multiplies.the accumulator by the store location val add val Adds the store location val to the accumulator mult keyin Multiplies the accumulator by the store location keyin store total Stores value in accumulator in the store location total print total Displays contents of the store location total on the screen stop Stops program execution keyin data 0 Initialises a store location keyin with the value 0 in it val data .5 Initialises a store location val with the value 0. 5 in it total data 0 Initialises a store location total with the value 0 in it TOM2 1. A fluid telephone company, Odear, makes a monthly stand up load of i 12.50 and charges 5 pence per local call. Write a TOM program that reads the amount of calls do and displays the total monthly bill. read calls Reads data inputted by keyboard and stores in the store location calls load calls Loads data from the store location calls in to the accumulator mult judge Multiplies the accumulator by the store location come in add stand up Adds the store location rest to the accumulator store total Stores value in accumulator in the store location total print total Displays contents of the store location total on the screen stop Stops program execution total data.0 Initialises a store location total with the value 0 in it calls data 0 Initialises a store location calls with the value 0 in it stand up data 12. 50 Initialises a store location standing with the value 12. 50 in it value data . 05 Initialises a store location rate with the value . 05 in it 2. Expand your program of (1) so that the program ex cels back to the beginning, ready to inscribe another bill instead of ending. burst out read calls Reads data inputted by keyboard and stores in the store location calls load calls Loads data from the store location calls in to the accumulator mult rate.Multiplies the accumulator by the store location rate add standing Adds the store location standing to the accumulator store total Stores value in accumulator in the store location total print total Displays contents of the store location total on the screen jump start Transfers control to the schooling start stop Stops program execution total data 0 Initialises a store location total with the value 0 in it calls data 0 Initialises a store location calls with the value 0 in it standing data 12. 50 Initialises a store location standing with the value 12. 50 in it rate data .05 Initialises a store location rate with the value . 05 in it 3. Whats wrong with the program in (2)? The program has no vogue of ending (normally), and will therefore loop continuously. 4. Modify (2) so that if the user innovates 0 for the number of units the program terminates. start read calls Reads data inputted by keyboard and stores in the store location calls load calls Loads data from the store location calls in to the accumulator sub picture Subtracts the store location check from the accumulator jifz end Transfers control to the training end if the zero lurch is set mult rate.Multiplies the accumulator by the store location rate add standing Adds the store location standing to the accumulator store total Stores value in accumulator in the store location total print total Displays contents of the store location total on the screen jump start Transfers control to the instruction start end stop Stops program execution total data 0 Initialises a store location total with the value 0 in it calls data 0 Initialises a store location calls with the value 0 in it standing data 12. 50 Initialises a store location standing with the va lue 12. 50 in it rate data .05 Initialises a store location rate with the value . 05 in it check data 0 Initialises a store location check with the value 0 in it 5. Now metamorphose (4) so that the user can tell the establishment how many bills to calculate and the program terminates after cart track that many times. read billnum Reads data inputted by keyboard and stores in the store location billnum start read calls Reads data inputted by keyboard and stores in the store location calls load calls Loads data from the store location calls in to the accumulator mult rate Multiplies the accumulator by the store location rate add standing.Adds the store location standing to the accumulator store total Stores value in accumulator in the store location total print total Displays contents of the store location total on the screen load billnum Loads data from the store location billnum in to the accumulator sub billsub Subtracts the store location billsub from the accumulator store bill num Stores value in accumulator in the store location billnum jifz end Transfers control to the instruction end if the zero peg is set jump start.Transfers control to the instruction start end stop Stops program execution total data 0 Initialises a store location total with the value 0 in it calls data 0 Initialises a store location calls with the value 0 in it standing data 12. 50 Initialises a store location standing with the value 12. 50 in it rate data . 05 Initialises a store location rate with the value . 05 in it billnum data 0 Initialises a store location billnum with the value 0 in it billsub data 1 Initialises a store location billsub with the value 1 in it 6. Finally, modify the program of (5) so that the user can first bow the price per unit, and the standing charge.Read rate Reads data inputted by keyboard and stores in the store location rate read standing Reads data inputted by keyboard and stores in the store location standing read billnum Reads data inputted by ke yboard and stores in the store location billnum start read calls Reads data inputted by keyboard and stores in the store location calls load calls Loads data from the store location calls in to the accumulator mult rate Multiplies the accumulator by the store location rate add standing.Adds the store location standing to the accumulator store total Stores value in accumulator in the store location total print total Displays contents of the store location total on the screen load billnum Loads data from the store location billnum in to the accumulator sub billsub Subtracts the store location billsub from the accumulator store billnum Stores value in accumulator in the store location billnum jifz end Transfers control to the instruction end if the zero flag is set jump start.Transfers control to the instruction start end stop Stops program execution total data 0 Initialises a store location total with the value 0 in it calls data 0 Initialises a store location calls with the value 0 i n it standing data 0 Initialises a store location standing with the value 0 in it rate data 0 Initialises a store location rate with the value 0 in it billnum data 0 Initialises a store location billnum with the value 0 in it billsub data 1 Initialises a store location billsub with the value 1 in it Modifications in TOM2 In question 1, the program initialises four store locations rate to store the standard call rate of 0. 5, standing to store the standing charge of 12. 50, calls to store the number of calls make and total to store the total bill.The programs reads a value inputted by the user (number of calls), multiplies this value by the call rate, adds the standing order and displays it. interrogative sentence 2 introduces a loop after the total has been displayed to the start of the program so that user may calculate another bill, this but is not ideal as there is no correct way to terminate the program normally. interrogative sentence 4 combats this problem by allowing the u ser to enter 0 to terminate the program. This is done by introducing an extra store location called check with the value 0 assigned to it.The program subtracts check from the number of calls entered, if the result is 0 (0 0 = 0) then the zero flag is set, the jifz statement then transfers control to the end of the program, where it terminates normally. Question 5, in addition to the store location apply in question 1 introduces two more billnum to store the number of bills required and billsub, a store location containing the value 1. The user initially enters the number of bills required, this is stored in billnum, the program then calculates the bill in same way as question 1. after(prenominal) the bill has been displayed, the program subtracts billsub (1) from the number of bills, if the result is zero (ie no more bill to calculate) the zero flag is set, and using the jifz statement jumps to the end of the program. If the zero flag is not set (more bills to calculate) the prog ram is looped back to enter more bill details. Question 6, allows the user to enter the standing charge, rate of calls and number of bills forwards the bills are calculated, these are stored in their respective locations (standing, rate and billnum) before the program continues to execute in the same way as question 5.CSO Tutorial 4 mold 2. 1 We wish to compare the performance of two different machines M1 and M2. The following measurements have been made on these machines Program Time on M1 Time on M2 1 10 seconds 5 seconds 2 3 seconds 4 seconds Which machine is faster for each program and by how much? For program 1, M2 is 5 seconds(or degree Celsius%) faster than M1. For program 2, M1 is 1 second (or 25%) faster than M2. drill 2. 2 Consider the two machines and programs in Exercise 2. 1. The following additional measurements were made Program. instruction manual put to death on M1 Instructions executed on M2 1 200 x 106 one hundred sixty x 106 Find the instruction execution r ate (instructions per second) for each machine running program 1. Instructions executed = Instructions per second (instruction execution rate) time(seconds) M1 200000000 = 20000000 10 = 20 x 106 Instructions per second or 20 Million Instructions per second M2 160000000 = 32000000 5 = 32 x 106 Instructions per second or 32 Million Instructions per second Exercise 2. 3 If the clock rates of machines M1 and M2 in Ex 2.1 are 200 MHz and three hundred MHz respectively, find the clock cycles per instruction (CPI) for program 1 on both machines using the data in Ex 2. 1 & 2. 2. Clock rate = clock cycles per instruction (CPI) Instruction execution rate M1 200000000 = 10 clock cycles per instruction (CPI) 20000000 M2 300000000 = 9. 375 clock cycles per instruction (CPI) 32000000 Question 4 Draw a unspoilt flowchart of the final TOM program produced at the end of exercise TOM2. This should include all the instructions, loops and all the program labels in the appropriate places.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.