Upload
ibrahim-hejab
View
46
Download
3
Tags:
Embed Size (px)
Citation preview
11
How the CPU WorksHow the CPU Works
The “Little Man Computer”The “Little Man Computer”VersionVersion
22
Download the tutorialDownload the tutorialYou can download your own copy of the Little You can download your own copy of the Little Man Computer simulation from the University of Man Computer simulation from the University of HertfordshireHertfordshire Start the download nowStart the download now Save it to your hard driveSave it to your hard drive We will use it shortlyWe will use it shortly
The link: The link: http://www.herts.ac.uk/lis/ltdu_temp/ltdu/projectshttp://www.herts.ac.uk/lis/ltdu_temp/ltdu/projects/mm5/#/mm5/#You can access this link directly from my You can access this link directly from my websitewebsite
33
The Little Man ComputerThe Little Man Computer
44
LMC Instruction CodesLMC Instruction Codes
LOAD instruction – op code 1LOAD instruction – op code 1 The Little Man goes to the mailbox specifiedThe Little Man goes to the mailbox specified Reads the three-digit number in the mailboxReads the three-digit number in the mailbox Puts that into the CalculatorPuts that into the Calculator
Note:Note: The number in the mailbox is unchangedThe number in the mailbox is unchanged The number in the calculator is replaced by The number in the calculator is replaced by
the new numberthe new number
55
LMC Instruction CodesLMC Instruction Codes
STORE instruction – op code 2STORE instruction – op code 2 The Little Man goes to the Calculator and reads the The Little Man goes to the Calculator and reads the
number therenumber there He writes the number down on a slip of paper and He writes the number down on a slip of paper and
puts it into the mailbox specified in the instructionsputs it into the mailbox specified in the instructions
Note:Note: The number in the Calculator does not changeThe number in the Calculator does not change The number in the Mailbox is replaced with the new The number in the Mailbox is replaced with the new
valuevalue
66
LMC Instruction CodesLMC Instruction Codes
ADD instruction – op code 3ADD instruction – op code 3 The Little Man walks over to the mailbox The Little Man walks over to the mailbox
address specified in the instructionsaddress specified in the instructions He reads the number and He reads the number and adds this number to adds this number to
the number already in the calculatorthe number already in the calculator..
Note:Note: The number in the mailbox is unchangedThe number in the mailbox is unchanged
77
LMC Instruction CodesLMC Instruction Codes
SUBTRACTION – op code 4SUBTRACTION – op code 4 Same as the ADD instruction, except the Same as the ADD instruction, except the
number is subtractednumber is subtractedFor this model we will assume that the Little Man For this model we will assume that the Little Man handles negative numbers correctly, though we will handles negative numbers correctly, though we will not deal with it here.not deal with it here.
Note:Note: The number in the mailbox is left unchangedThe number in the mailbox is left unchanged
88
LMC Instruction CodesLMC Instruction Codes
INPUT (or READ) – op code 5, INPUT (or READ) – op code 5, “address” 00 (the 00 is ignored for this “address” 00 (the 00 is ignored for this special instruction code)special instruction code) The Little Man gets a slip of paper in from the The Little Man gets a slip of paper in from the
in-basketin-basket He types this number into the calculatorHe types this number into the calculator Each INPUT instruction handles only 1 slip of Each INPUT instruction handles only 1 slip of
paperpaper The Little Man will ignore the address portion The Little Man will ignore the address portion
of this codeof this code
99
LMC Instruction CodesLMC Instruction Codes
OUTPUT (or PRINT) – op code 6, OUTPUT (or PRINT) – op code 6, “address” 00 (the 00 is ignored for this “address” 00 (the 00 is ignored for this special instruction code)special instruction code) The Little Man walks to the calculator and The Little Man walks to the calculator and
writes down the number on a slip of paperwrites down the number on a slip of paper This slip is put in to the out basketThis slip is put in to the out basket Each OUTPUT instruction places 1 piece of Each OUTPUT instruction places 1 piece of
paper in the out basketpaper in the out basket The Little Man will ignore the address portion The Little Man will ignore the address portion
of this codeof this code
1010
LMC Instruction CodesLMC Instruction Codes
COFFEE BREAK (or HALT) – COFFEE BREAK (or HALT) – op code 7op code 7 The Little Man takes a break.The Little Man takes a break. He will ignore the address portion of the He will ignore the address portion of the
instructioninstruction
1111
A Simple ProgramA Simple Program
A few itemsA few items We need to store the instructions somewhereWe need to store the instructions somewhere We need a method to tell the Little Man where We need a method to tell the Little Man where
to find the particular instructions that he is to find the particular instructions that he is supposed to perform at any given timesupposed to perform at any given time
1212
A Simple ProgramA Simple Program
Assumed SolutionsAssumed Solutions Assume that the instructions are stored in the Assume that the instructions are stored in the
mailbox starting at mailbox number 00mailbox starting at mailbox number 00 The Little Man will perform instructions by The Little Man will perform instructions by
looking at the value in the instruction location looking at the value in the instruction location counter and execute the instruction found in counter and execute the instruction found in the mailbox whose address has that valuethe mailbox whose address has that value
1313
A Simple ProgramA Simple Program
Assumed SolutionsAssumed Solutions Each time the LM completes and instruction, Each time the LM completes and instruction,
he will increment the Instruction Location he will increment the Instruction Location Counter and do the instruction specified by Counter and do the instruction specified by the counterthe counter
1414
A Simple ProgramA Simple Program
Look at a program where the USER uses Look at a program where the USER uses the Little Man Computer to add two the Little Man Computer to add two numbers.numbers.
The User will place two numbers in the in The User will place two numbers in the in basketbasket
The sum of the two will appear as a result The sum of the two will appear as a result in the out basketin the out basket
1515
A Simple ProgramA Simple Program
INPUTINPUT 500500 The first step is to give the LM access to the The first step is to give the LM access to the
datadata This instruction has the LM read the first This instruction has the LM read the first
number from the in basket in to the calculatornumber from the in basket in to the calculator
1616
A Simple ProgramA Simple Program
STORE 99STORE 99 299299 It is not possible for the LM to simply read It is not possible for the LM to simply read
another number into the calculator. another number into the calculator. It would destroy the first numberIt would destroy the first number We must save the first number somewhereWe must save the first number somewhere Mailbox 99 is chosen so that we don’t have Mailbox 99 is chosen so that we don’t have
any conflicts with other data or programsany conflicts with other data or programsDiscuss thisDiscuss this
1717
A Simple ProgramA Simple Program
INPUT INPUT 500500 The LM reads the second number into the The LM reads the second number into the
calculatorcalculator
ADDADD 399399 We do not need to save the 2We do not need to save the 2ndnd number in the number in the
example, but we could have.example, but we could have. The 1The 1stst number from mailbox 99 is added to number from mailbox 99 is added to
the 2the 2ndnd number in the calculator number in the calculator
1818
A Simple ProgramA Simple Program
OUTPUTOUTPUT 600600 The LM puts the result in to the out basketThe LM puts the result in to the out basket
COFFEE BREAKCOFFEE BREAK700700 The program terminatesThe program terminates
Note:Note: These instructions are stored sequentially starting These instructions are stored sequentially starting
from mailbox 00. from mailbox 00. This is so we could run the program againThis is so we could run the program again
1919
A Simple ProgramA Simple ProgramCode SummaryCode Summary
MailboxMailbox InstructionInstruction
StepStep codecode descriptiondescription
0000 500500 INPUTINPUT
0101 299299 STORE DATASTORE DATA
0202 500500 INPUT 2INPUT 2NDND # #
0303 399399 ADD 1ADD 1STST # TO it # TO it
0404 600600 OUTPUT RESULTOUTPUT RESULT
0505 700700 STOPSTOP
9999 DATADATA
2121
Run the CPU SimulatorRun the CPU SimulatorNow you try it.Now you try it.Do the sample program included with the Do the sample program included with the simulationsimulationWrite your own program (and show me that Write your own program (and show me that they work)they work) Write a program to add 3 numbersWrite a program to add 3 numbers Write a program that correctly calculates Write a program that correctly calculates
x + y + z – a – b (Ex. 1 + 2 + 3 – 4 – 5 = -3)x + y + z – a – b (Ex. 1 + 2 + 3 – 4 – 5 = -3)
For the bold and intelligent ones:For the bold and intelligent ones: Write the last program only using 2 mailboxes!Write the last program only using 2 mailboxes!
2222
How the CPU WorksHow the CPU Works
A More Complex ViewA More Complex View
2323
OverviewOverview
We saw in the “Little Man Computer” a We saw in the “Little Man Computer” a simplified version of how a CPU works.simplified version of how a CPU works. Memory, the Control Unit, the Accumulator Memory, the Control Unit, the Accumulator
(calculator) were all located in the same area(calculator) were all located in the same area Decimal system used for communication of Decimal system used for communication of
instructionsinstructions Memory was limited to 100 “mailboxes”Memory was limited to 100 “mailboxes”
2424
CPU ComponentsCPU Components
3 Major Parts3 Major Parts Arithmetic/Logic Unit (ALU)Arithmetic/Logic Unit (ALU) Control Unit (CU)Control Unit (CU) MemoryMemory
The ALU & CU are known as the Central The ALU & CU are known as the Central Processing UnitProcessing Unit
2525
Block Diagram of SystemBlock Diagram of System
Memory
CPU
ALU
I/O
Control UnitProgram Counter
2626
Direct Comparison of Direct Comparison of LMC & CPULMC & CPU
ALU
I/OInterface
ControlUnit
Memory
ProgramCounter
2727
Arithmetic/Arithmetic/Logic Unit (ALU)Logic Unit (ALU)
The component where data is held The component where data is held temporarilytemporarilyCalculations occur hereCalculations occur hereIt knows how to perform operations such It knows how to perform operations such as ADD, SUB, LOAD, STORE, SHIFT. as ADD, SUB, LOAD, STORE, SHIFT. It knows the commands that make up the It knows the commands that make up the machine language of the CPUmachine language of the CPUIt is the calculatorIt is the calculator
Memory
CPU
ALU
I/O
Control UnitProgram Counter
2828
Control UnitControl Unit
Interprets and controls the execution of Interprets and controls the execution of instructionsinstructions
This control corresponds to the “fetch-execute” This control corresponds to the “fetch-execute” cyclecycle The The fetch cyclefetch cycle gets the instructions gets the instructions The The execute cycleexecute cycle does the work specified in the does the work specified in the
instructioninstruction
Note
Memory
CPU
ALU
I/O
Control UnitProgram Counter
2929
RegistersRegisters
““AA Register Register is a single, permanent storage is a single, permanent storage location within the CPU used for a location within the CPU used for a PARTICULAR, defined purpose.”PARTICULAR, defined purpose.”
““A register is used to hold a A register is used to hold a binarybinary value value temporarily for storage, for manipulation, temporarily for storage, for manipulation, and/or for simple calculations.”and/or for simple calculations.”
Registers have special addressesRegisters have special addresses
Memory
CPU
ALU
I/O
Control UnitProgram Counter
3030
The End…The End…