GCSE Computing Sample Assessment Material Write Up Mr Travi Royal Grammar School No 1 Introduction to the Little Man Computer Introduction In this practical investigation I am going to look at the Littleman Computer Simulation. The software for this is provided at www.atkinson.yorku.ca/~sychen/research/LMC/LMCHome.html The Littleman Computer Simulation simulates simple microprocessor and contains the following elements Program counter – this tells the program where the next instruction is going to be executed from Accumulator is a register in which intermediate arithmetic and logic results are stored whilst the program is being assembled Inbox – this is where the user enters data that the program is going to execute Outbox – this is where the data that is processed and produced by the program is going to be displayed Using the Little Man Computer Simulation The LMC responds to commands in the same as any high level programming language and has its own instruction set. Instruction Mnemonic Machine Code Comments Load LDA 5xx Load what is stored a location into the accumulator in the accumulator into for example LDA count – this would load the contents of whatever is store location count and place this into the accumulator Store STA 3xx Store the contents of the input box into a storage location. For example STA COUNT this would store the contents into location count which would be the next available storage location in the littleman computer simulation Add ADD 1xx Add One – add the contents of storage location one to the accumulator Subtract SUB 2xx Subtract One – Subtract the contents of storage location one to the accumulator Input INP 901 Read in the contents of the input box into the accumulator Output OUT 902 Display the contents of the accumulator in the output box End HLT 000 End the program Branch if zero BRZ 7xx This is selection / iteration statements Branch if the contents of the accumulator are zero - Branch if zero or BRP 8xx Branch if the contents of the accumulator are zero or positive- positive Instruction set Continued Branch always BRA Data storage DAT 6xx Branch always if the contents of the accumulator are not zero DAT – declares the names of storage locations and value Count DAT – declares count as a location ONE DAT 1 - declares one as a location with a set value of 1 Task 1 As part of this assessment I am going to look at the working of 2 of the sample programs / tutorials which came with the LMC software and explain how these operate. The two programs I have chosen are 1. Produce a program using the LMC to input 2 integer values and output the add output the largest then the smallest 2. Produce a program using the LMC to input 2 integer values and add them together I am going to illustrate how the LMC with a further 3 programs as well 1. Produce a program which use the LMC instruction set to write a program to add the first 2 values together and subtract the third integer value and store the results into the accumulator and display it in the out box together 2 integer values and then terminate 2. Produce a program using the LMC that will output the values from 1 to 10 I am going to modify this program so that the user can chose what number to input between 1 and 10. I will then change the program so that it counts down 3. Produce a program which will give the user a chance of a range of numbers and output odd and even numbers between these totals These programs will demonstrate the use of branching statements within the LMC Program 1 Using selection to find out which number is the largest of 2 numbers entered 1) This represents the flowchart / algorithm for the program to be entered into the littleman ting 2) This shows the instructions being loaded into the computer simulators memory location now click on run Program 1 Coded example INP STA first Input first value store in location first INP STA second Input first value store in location first SUB FIRST Subtract first from second number BRP SECONDBIG Is what is left a positive number if so LDA FIRST Load the contents of first into the accumulator and display to output OUT BRA PROGRAMEND If not load the Load the contents of second into the accumulator and display to output SECONDBIG LDA SECOND OUT PROGRAMEND HLT End the program first DAT Declare memory location first second DAT Declare memory location second INP STA FIRST INP STA SECOND SUB FIRST BRP SECONDBIG LDA FIRST OUT BRA PROGRAMEND SECONDBIG LDA SECOND OUT PROGRAMEND HLT FIRST DAT SECOND DAT The first number is loaded and then stored in memory location first The second number is loaded and then stored in memory location second The second number is subtracted from the first and the result stored in the accumulator Are the results in the accumulator greater than or equal to zero? If so load the results of storage location first and load then into the accumulator and output them – end that part of the program Else Load the contents of storage location second and load then into the accumulator and output them – end that part of the program Program 1 Using selection to find out which number is the largest of 2 numbers entered In this video (called largestof2numbers.avi) I tested this program. Program 1 Using selection to find out which number is the largest of 2 numbers entered test plan and table Test Data Expected Outcome Actual Outcome 1 I am going to enter 65 as the first number 64 as the second number 65 should come out as the largest As expected 2 I am going to enter 64 as the first number 65 as the second number 65 should come out as the largest As expected The program loads the instruction set 64 is entered - stored in the first memory location 65 is entered – stored in the second memory location INP opcode 901 stored in 0 STA opcode 312 result stored in 12 on the LMC stored in 1 INP opcode 901 stored in 2 STA opcode 313 result stored in 13 on the LMC stored in 3 Sub FIRST opcode 212 stored in 4 BRP SECONDBIG opcode 809 – branch if positive stored in 5 LDA FIRST – load the result of first and place into accumulator stored at 6 Out – display results of accumulator to output box stored at 7 Branchalways if value in accumulator is not postive stored at 8 LDA second load the result off first and place into accumulator stored at 9 Out – display results of accumulator to output box stored at 10 End program Produce a program using the LMC to input 2 integer values and add them together inp Input a value into the input and copy this into the accumulator sta first Store this value in store location called first LMC allocates this to the first memory location available inp Input a value into the input and copy this into the accumulator sta second Store this value in store location called first LMC allocates this to the next memory location available add first Add the contents of the accumulator to what is stored in memory location first and return these values to the accumulator out Output these values first dat Define memory location first dat Second dat Define memory location Second dat Test 1 Data I am going to enter4 as the first number 4 as the second number Expected Outcome The result in the accumulator should be 6 Actual Outcome As expected 2) Produce a program using the LMC to input 2 integer values and add them together In this video (called adding2nos.avi) I tested this program. I have enclosed the video as a standalone file in case this does not load and shows the test mentioned above 3) Produce a program using the LMC that will output the values from 1 to 10 counting up I am going to modify this program so that the user can chose what number to input between 1 and 10. I will then change the program so that it counts down Start INP STA COUNT OUT LOOPTOP LDA COUNT ADD ONE OUT STA COUNT SUB TWENTY BRP ENDLOOP BRA LOOPTOP ENDLOOP HLT ONE DAT 001 TWENTY DAT 020 COUNT DAT Is the result positive? Input a number and store in count Load the result into the accumulator Add the contents of memory location 1 to the accumulator Subtract the contents of memory location 1 to the accumulator (20) Output the results to the accumulator No Yes End 3) Produce a program using the LMC that will output the values from 1 to 10 counting up I am going to modify this program so that the user can chose what number to input between 1 and 10. I will then change the program so that it counts down test plan Test 1 Data I am going to 4 into the accumulator 2 I am going to 1 into the accumulator Expected Outcome The program will output all the numbers between 4 and 10 in increments of 1 The program will output all the numbers between 1 and 10 in increments of 1 Actual Outcome As expected As expected In this video (called countingprog1to10) I tested this program. I have enclosed the video as a standalone file in case this does not load and shows the test mentioned above Video Counting prog and testing counting up 1 to 10 3) I am going to modify the program in 3a so that it counts down. I will then change the program so that it counts down test plan Test 1 Data I am going to enter 19 as the first number 2 I am going to enter 2 as the first number Expected Outcome 19 should come out and the program should count down in increments of 1 until it reaches 0 2 should come out and the program should count down in increments of 1 until it reaches 0 Actual Outcome As expected As expected INP Input value STA COUNT store value in memory location count OUT output value LOOPTOP LDA COUNT load the value into the accumulator BRZ ENDLOOP is the value 0 if so go to endloop sub if not SUB ONE subtract 1 OUT load the value into the accumulator STA COUNT store value in memory location count SUB TWENTY subtract 20 from the value in count BRA LOOPTOP go back to loopcount ENDLOOP HLT end the program ONE DAT 001 one declared as memory location with a value of 1 TWENTY DAT 020 COUNT DAT twenty declared as memory location with a value of 20 count declared as variable Video Counting prog and testing counting down 20 to 1 I have saved this as countprog20to1.avi and this will show the program working counting back from 19 in increments of 1 to 0 and from 2 in increments of 1 to 0 Produce a program which will give the user a chance of a range of numbers and output odd and even numbers between these totals Test 1 Data I am going to enter 1 as the first number 2 I am going to enter 57 as the first number Expected Outcome 1 should come out and the program should count down in increments of 2 until it reaches 99 57 should come out and the program should count down in increments of 1 until it reaches 99 Actual Outcome As expected As expected INP Number initally input LOOP STA ODD start loop save this number in storage location ODD located at 111 LDA NUM load the contents of number into the accumulator SUB ODD subtract from the contents of number the vale in ODD BRP MORE Branch if the number is postive END HLT end the program MORE LDA ODD if not load the contents of odd OUT send this to display in the out box ADD TWO add the value of storage location two (which is 2) and loop again BRA LOOP TWO DAT 2 Declaration of variable TWO with value 2 ODD DAT 1 Declaration of variable ONE with value 1 NUM DAT 99 Declaration of variable NUM with value 99 Video Counting prog and testing counting up from a user defined no to 99 in increments of 2 I have produced a video called countprog1TO99ODDNOS which I have embedded here and have included with this portfoilio For the second task I have been given a number of programming tasks to tackle 1) Write programs to run in LMC: a) Produce a multiplication table from 1 to 10 for any number input by the user b) Modify this program so that a user can enter a value and it produces the square of that number for example if the user entered 5 it would produce 25 c) Modify the program so that a can user can enter a value and it produces the cube of that number for example if the user entered 2 it would produce the number 8 (which is 2*2*2) (d) Produce evidence to show that you have planned, written and tested your code. (e) Produce an evaluation of your solutions. 2) Write a conclusion about the possibility of writing effective and complex programs with only a limited instruction set. a) Produce a multiplication table from 1 to 10 for any number input by the user Start Add the contents of number1 into the accumulator Is the result positive? Input a first number and store in Number1 Store the result into memory location RESULT Input a number Subtract the contents of the accumulator by the contents in memory location ONE Store the result of this in memory location number2 Load the contents of storage location RESULTS into the accumulator Load the contents of memory location TWO and load this into the accumulator subtract the contents of this by the contents in memory location ONE Store the result into memory location Number2 Load the contents of result into the accumulator and display in the output boc End yes Test 1 2 Data I am going to enter 12 in memory location number1 and 12 in memory location 2 I am going to enter 12 in memory location number1 and 12 in memory location 2 Expected Outcome The program will add 12 together 12 times and will display 144 in the accumulator at the end Accepted outcome As expected The program will add 9 together 8 times and will display 72 in the accumulator at the end As expected INP Input a number STA NUMBER1 store this number in memory location number1 INP Input a number SUB ONE subtract the contents of this by the contents in memory location ONE STA NUMBER2 store this number in memory location number2 LOOPTOP LDA RESULT load the contents of store location result and load this into the accumulator ADD NUMBER1 add the contents of memory location number1 STA RESULT store the result of this into memory location result LDA NUMBER2 load the contents of store location number2 and load this into the accumulator SUB ONE subtract the contents of this by the contents in memory location ONE STA NUMBER2 store this number in memory location number2 BRP LOOPTOP is the result postive? If yes go back to top of looptop and load result again LDA RESULT if no load the result into the accumulator OUT output this result to the accumulator HLT end the program BRA LOOPTOP ONE DAT 001 ONE memory location declared initialised NUMBER1 DAT Number 1 memory location declared NUMBER2 DAT Number 2 memory location declared RESULT DAT 000 Result memory location declared initialised a) Produce a multiplication table from 1 to 10 for any number input by the user I have produced a video called mulplicationof2nos. which I have embedded here and have included with this portfoilio b) Modify this program so that a user can enter a value and it produces the square of that number for example if the user entered 5 it would produce 25 Test 1 Data I am going to enter 6 2 I am going to enter 31 INP STA FIRST STA SECOND SUB ONE STA SECOND LDA FIRST LOOPTOP ADD FIRST STA RESULT LDA SECOND SUB ONE STA SECOND BRZ LOOKIFZERO LDA RESULT BRA LOOPTOP LOOKIFZERO LDA RESULT OUT STA RESULT HLT FIRST DAT SECOND DAT ONE DAT 1 RESULT DAT Expected Outcome The program will add 6 together 6 times and will display 36 in the accumulator at the end The program will add 31 together 31 times and will display 961 in the accumulator at the end This is the highest that the LMC could display using this program Accepted outcome As expected As expected Input a number store this number in memory location FIRST store this number in memory location Second subtract the contents of this by the contents in memory location ONE store this number in memory location Second load the contents of store location First and load this into the accumulator add the contents of memory location First store the result of this into memory location result load the contents of store location Second and load this into the accumulator subtract the contents of this by the contents in memory location ONE store this number in memory location Second is the result zero? If no go back to top of looptop and load result again if no load the result into the accumulator output this result to the accumulator if second is zero load the result into the accumulator and output Store the contents of the accumulator into the memory location results end the program First memory location declared Second memory location declared one memory location declared and initialised Result memory location declared initialised b) Modify this program so that a user can enter a value and it produces the square of that number for example if the user entered 5 it would produce 25 I have produced a video called squareof2nos. which I have embedded here and have included with this portfoilio c) Modify the program so that a can user can enter a value and it produces the cube of that number for example if the user entered 2 it would produce the number 8 (which is 2*2*2) INP Input a number STA FIRST store this in memory location first STA COUNTER store this in memory location counter SUB ONE subtract this from the contents held in memory location one STA COUNTER store this in memory location counter LDA FIRST load the contents of memory location FIRST into the accumulator LOOPTOP ADD FIRST add the contents of memory location FIRST into what is currently in the accumulator STA RESULT store this number in memory location result LDA COUNTER load the contents of memory location Counter into the accumulator SUB ONE subtract this from the contents held in memory location one STA COUNTER store this number in memory location counter BRZ LOOKIFZERO is this result zero? LDA RESULT no load the result into the accumulator BRA LOOPTOP go back to looptop LOOKIFZERO LDA RESULT if counter = 0, load the contents in memory location result into the accumulator OUT and display in out box Prog C continued STA RESULT LDA FIRST STA COUNTER LDA RESULT STA number LOOPTOP1 LDA result ADD NUMBER STA result LDA Counter SUB ONE STA counter BRZ LOOKUP LDA RESULT SUB NUMBER BRA LOOPTOP1 LOOKUP LDA RESULT SUB NUMBER OUT HLT FIRST DAT Counter DAT ONE DAT 1 RESULT DAT Number DAT Store this number in memory location result load the contents of memory location FIRST into the accumulator store this in memory location counter load the contents of memory location result into the accumulator Store this number in memory location number load the contents of memory location result into the accumulator add the contents of memory location NUMBER into what is currently in the accumulator Store this number in memory location RESULT load the contents of memory location counter into the accumulator subtract this from the contents held in memory location one store this in memory location counter is this result zero? load the contents of memory location result into the accumulator subtract this from the contents held in memory location NUMBER go back to looptop1 if counter = 0, load the contents in memory location result into the accumulator subtract this from the contents held in memory location NUMBER Send this to the outbox end the program First memory location declared where inital number to be processed is declared Counter memory location declared one memory location declared and initialised Result memory location declared initialised Number memory location declared where result of first calculation is stored Testing stage Test 1 Data I am going to enter 2 2 I am going to enter 9 Expected Outcome Accepted outcome The program add 2 to together As expected 2 times giving a result of 4 and take that result and perform the same calculation again leaving a result of 8 The program will add 9 As expected together 9 times giving a result of 81 and will perform the same calculation again giving a result of 729 Modify the program so that a can user can enter a value and it produces the cube of that number for example if the user entered 2 it would produce the number 8 (which is 2*2*2) I have embedded a video which shows the results of the program being run testing 2 * 2 * 2 and 9 * 9 * 9. This is also available as a standalone video called cubeof1nos (e) Produce an evaluation of your solutions and (f) Write a conclusion about the possibility of writing effective and complex programs with only a limited instruction set. . For each of the programs I have as produced detailed code and shown my solution through the videos which are attached to this presentation and have been submitted as standalone products. In each case I have tested the programs at the extreme ends of what the LMC simulator is capable of doing. The LMC is limited in its functionality as this will support numbers upto a 1000, will not accept decimal or real numbers or data types and can only perform limited arithmetic operations namely addition and division. This is a severely limiting factor on the use of the LMC but this does highlight the basic principles of machine architecture in that it shows the fetch execute cycle in action and the respective role of the registers. If the LMC or programs like it were to be used for the calculations then a lot of processing is going to be undertaken by the program and the result will not be as accurate owing to its (the LMC’s) operation when compared to modern software applications and high level programming compilers Bibliography Slide 2 Definitions and ideas taken from Wikipedia and adapted Slide 3 Instruction set taken from http://www.atkinson.yorku.ca/~sychen/research/LMC/LMCHome.html