Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 How the CPU Works The Little Man Computer Version.

Similar presentations


Presentation on theme: "1 How the CPU Works The Little Man Computer Version."— Presentation transcript:

1 1 How the CPU Works The Little Man Computer Version

2 2 Download the tutorial You can download your own copy of the Little Man Computer simulation from the University of Hertfordshire Start the download now Start the download now Save it to your hard drive Save it to your hard drive We will use it shortly We will use it shortly The link: /mm5/# /mm5/# /mm5/# You can access this link directly from my website

3 3 The Little Man Computer

4 4 LMC Instruction Codes LOAD instruction – op code 1 The Little Man goes to the mailbox specified The Little Man goes to the mailbox specified Reads the three-digit number in the mailbox Reads the three-digit number in the mailbox Puts that into the Calculator Puts that into the CalculatorNote: The number in the mailbox is unchanged The number in the mailbox is unchanged The number in the calculator is replaced by the new number The number in the calculator is replaced by the new number

5 5 LMC Instruction Codes STORE instruction – op code 2 The Little Man goes to the Calculator and reads the number there The Little Man goes to the Calculator and reads the number there He writes the number down on a slip of paper and puts it into the mailbox specified in the instructions He writes the number down on a slip of paper and puts it into the mailbox specified in the instructionsNote: The number in the Calculator does not change The number in the Calculator does not change The number in the Mailbox is replaced with the new value The number in the Mailbox is replaced with the new value

6 6 LMC Instruction Codes ADD instruction – op code 3 The Little Man walks over to the mailbox address specified in the instructions The Little Man walks over to the mailbox address specified in the instructions He reads the number and adds this number to the number already in the calculator. He reads the number and adds this number to the number already in the calculator.Note: The number in the mailbox is unchanged The number in the mailbox is unchanged

7 7 LMC Instruction Codes SUBTRACTION – op code 4 Same as the ADD instruction, except the number is subtracted Same as the ADD instruction, except the number is subtracted For this model we will assume that the Little Man handles negative numbers correctly, though we will not deal with it here. Note: The number in the mailbox is left unchanged The number in the mailbox is left unchanged

8 8 LMC Instruction Codes INPUT (or READ) – op code 5, address 00 (the 00 is ignored for this special instruction code) The Little Man gets a slip of paper in from the in-basket The Little Man gets a slip of paper in from the in-basket He types this number into the calculator He types this number into the calculator Each INPUT instruction handles only 1 slip of paper Each INPUT instruction handles only 1 slip of paper The Little Man will ignore the address portion of this code The Little Man will ignore the address portion of this code

9 9 LMC Instruction Codes OUTPUT (or PRINT) – op code 6, address 00 (the 00 is ignored for this special instruction code) The Little Man walks to the calculator and writes down the number on a slip of paper The Little Man walks to the calculator and writes down the number on a slip of paper This slip is put in to the out basket This slip is put in to the out basket Each OUTPUT instruction places 1 piece of paper in the out basket Each OUTPUT instruction places 1 piece of paper in the out basket The Little Man will ignore the address portion of this code The Little Man will ignore the address portion of this code

10 10 LMC Instruction Codes COFFEE BREAK (or HALT) – op code 7 The Little Man takes a break. The Little Man takes a break. He will ignore the address portion of the instruction He will ignore the address portion of the instruction

11 11 A Simple Program A few items We need to store the instructions somewhere We need to store the instructions somewhere We need a method to tell the Little Man where to find the particular instructions that he is supposed to perform at any given time We need a method to tell the Little Man where to find the particular instructions that he is supposed to perform at any given time

12 12 A Simple Program Assumed Solutions Assume that the instructions are stored in the mailbox starting at mailbox number 00 Assume that the instructions are stored in the mailbox starting at mailbox number 00 The Little Man will perform instructions by looking at the value in the instruction location counter and execute the instruction found in the mailbox whose address has that value The Little Man will perform instructions by looking at the value in the instruction location counter and execute the instruction found in the mailbox whose address has that value

13 13 A Simple Program Assumed Solutions Each time the LM completes and instruction, he will increment the Instruction Location Counter and do the instruction specified by the counter Each time the LM completes and instruction, he will increment the Instruction Location Counter and do the instruction specified by the counter

14 14 A Simple Program Look at a program where the USER uses the Little Man Computer to add two numbers. The User will place two numbers in the in basket The sum of the two will appear as a result in the out basket

15 15 A Simple Program INPUT500 The first step is to give the LM access to the data The first step is to give the LM access to the data This instruction has the LM read the first number from the in basket in to the calculator This instruction has the LM read the first number from the in basket in to the calculator

16 16 A Simple Program STORE It is not possible for the LM to simply read another number into the calculator. It is not possible for the LM to simply read another number into the calculator. It would destroy the first number It would destroy the first number We must save the first number somewhere We must save the first number somewhere Mailbox 99 is chosen so that we dont have any conflicts with other data or programs Mailbox 99 is chosen so that we dont have any conflicts with other data or programs Discuss this

17 17 A Simple Program INPUT 500 The LM reads the second number into the calculator The LM reads the second number into the calculator ADD399 We do not need to save the 2 nd number in the example, but we could have. We do not need to save the 2 nd number in the example, but we could have. The 1 st number from mailbox 99 is added to the 2 nd number in the calculator The 1 st number from mailbox 99 is added to the 2 nd number in the calculator

18 18 A Simple Program OUTPUT600 The LM puts the result in to the out basket The LM puts the result in to the out basket COFFEE BREAK700 The program terminates The program terminatesNote: These instructions are stored sequentially starting from mailbox 00. These instructions are stored sequentially starting from mailbox 00. This is so we could run the program again This is so we could run the program again

19 19 A Simple Program Code Summary MailboxInstruction Stepcodedescription 00500INPUT 01299STORE DATA 02500INPUT 2 ND # 03399ADD 1 ST # TO it 04600OUTPUT RESULT 05700STOP 99DATA

20 20 Extended Code Set Example of Branching 45LDA is assumed to have a value 46BRZ Branch if the value is 0 47BR Exit loop; Jump to NextStatement 48 …This is where the task is located 59BR End of Task; loop test again 60 Next code statement

21 21 Run the CPU Simulator Now you try it. Do the sample program included with the simulation Write your own program (and show me that they work) Write a program to add 3 numbers Write a program to add 3 numbers Write a program that correctly calculates x + y + z – a – b (Ex – 4 – 5 = -3) Write a program that correctly calculates x + y + z – a – b (Ex – 4 – 5 = -3) For the bold and intelligent ones: Write the last program only using 2 mailboxes! Write the last program only using 2 mailboxes!

22 22 How the CPU Works A More Complex View

23 23 Overview We saw in the Little Man Computer a simplified version of how a CPU works. Memory, the Control Unit, the Accumulator (calculator) were all located in the same area Memory, the Control Unit, the Accumulator (calculator) were all located in the same area Decimal system used for communication of instructions Decimal system used for communication of instructions Memory was limited to 100 mailboxes Memory was limited to 100 mailboxes

24 24 CPU Components 3 Major Parts Arithmetic/Logic Unit (ALU) Arithmetic/Logic Unit (ALU) Control Unit (CU) Control Unit (CU) Memory Memory The ALU & CU are known as the Central Processing Unit

25 25 Block Diagram of System Memory CPU ALU I/O Control Unit Program Counter

26 26 Direct Comparison of LMC & CPU ALU I/O Interface Control Unit Memory Program Counter

27 27 Arithmetic/ Logic Unit (ALU) The component where data is held temporarily Calculations occur here It knows how to perform operations such as ADD, SUB, LOAD, STORE, SHIFT. It knows the commands that make up the machine language of the CPU It is the calculator Memory CPU ALU I/O Control Unit Program Counter

28 28 Control Unit Interprets and controls the execution of instructions This control corresponds to the fetch- execute cycle The fetch cycle gets the instructions The fetch cycle gets the instructions The execute cycle does the work specified in the instruction The execute cycle does the work specified in the instruction Note Memory CPU ALU I/O Control Unit Program Counter

29 29 Registers A Register is a single, permanent storage location within the CPU used for a PARTICULAR, defined purpose. A register is used to hold a binary value temporarily for storage, for manipulation, and/or for simple calculations. Registers have special addresses Memory CPU ALU I/O Control Unit Program Counter

30 30 The End…


Download ppt "1 How the CPU Works The Little Man Computer Version."

Similar presentations


Ads by Google