Lesson 6 - Input and Output LMC
New LearningLast lesson you began to look at how processors work by using the LMC.
Today we will explore how the LMC processes inputs in order to output data. You may find it useful to have a word processor open while you work on todays tasks as the LMC does not store your mnemonics. Copy and paste the mnemonic into the word processor so you can use it again (or adapt it). The LMC can also store the inputs you use. Add this mnemonic to your LMC: INP STA first INP STA second OUT second LDA first OUT first HLT first DAT second DAT The first DAT part declares that the variable 'first' is data. STA will store your INPUT using the variable name 'first'. |
Learning objectiveUnderstand the concepts of input, process and output.
Write a simple program for addition and subtraction using the LMC Learning outcomesALL: Level 5
Understand how data, such as numbers, sound and images are physically stored on a computer system MOST: Level 6 Understand how instructions are run inside a computer SOME: Level 7 Understand how instructions can be written efficiently and be able to describe the efficiency of your programs. KeywordsLMC
Mnemonics Processor Input Output Store Declare Variable |
Talk TaskYour teacher will ask you to try to explain what is happening in each line of code.
|
Learning DevelopmentAdd this mnemonic to your LMC: INP STA first INP STA second LDA first ADD second OUT HLT first DAT second DAT Line By Line
INP <-- Prompt the user for an input [stored in accumulator temporarily] STA first <-- Store the answer [currently in accumulator] in a variable called first INP <-- Prompt the user for an input [stored in accumulator temporarily] STA second <-- Store the answer [currently in accumulator] in second LDA first <-- Load the number in variable first back into the accumulator ADD second <-- Add the contents of second to whatever is in the accumulator OUT <-- Put the contents of the accumulator into the out-box HLT <-- End of program first DAT <-- Declare that first is data [i.e. a variable] second DAT <-- Declare that second is data [i.e. a variable] The LMC compiler (technically an assembler) converts each mnemonic into an opcode. INP <-- 901 [Input] STA first <-- 308 [Store in memory address 09] INP <-- 901 [Input] STA second <-- 309 [Store in memory address 10] LDA first <-- 508 [Load the data from memory address 09] ADD second <-- 109 [Load the data from memory address 10] OUT <-- 902 [Output] HLT <-- 0 [End of program] first DAT <-- [Declare first as a variable] second DAT <-- [Declare second as a variable] Points to Note The accumulator (think: short term memory) stores the last number the computer was dealing with. The ADD command loads the data into the MEM Data register to be added to the accumulator. How would you need to adapt this code to subtract 'first' from 'second'? |
Independent Task - Assessment task - This will be deep marked
Download the attached document and have a go at finding the answers to each of the tasks.
Submit your work on Edmodo |
|
Plenary
Your teacher will test you on some of the mnemonics used in the LMC.
"Little Man Computer" by Mark Clarkson is licensed under CC BY 2.0
"Little Man Computer" by Mark Clarkson is licensed under CC BY 2.0