Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMSC 104, Lecture 061 Stored Programs A look at how programs are executed.

Similar presentations


Presentation on theme: "CMSC 104, Lecture 061 Stored Programs A look at how programs are executed."— Presentation transcript:

1 CMSC 104, Lecture 061 Stored Programs A look at how programs are executed

2 CMSC 104, Lecture 062 The Central Processing Unit l The CPU is the computer’s mechanism for performing operations on data and coordinating the sequence of these operations. l The CPU consists of two main parts oThe Arithmetic Logic Unit - contains circuitry that performs operations oThe Control Unit - contains circuitry that coordinates the machine’s activities

3 CMSC 104, Lecture 063 Registers l Since the CPU is a separate device from main memory, it needs to have special memory cells to use as a temporary storage place to hold the data it will be working with. These memory cells within the CPU are called registers.

4 CMSC 104, Lecture 064 Control Unit & ALU jobs l The control unit is responsible for placing the data that’s needed in the registers, telling the ALU which registers are being used, and to turn on the correct circuitry in the ALU for the desired operation. l The ALU uses the data in the indicated registers to do the operation and places the result in the indicated register.

5 CMSC 104, Lecture 065 CPU - Main Memory Diagram Bus Central Processing Unit Main Memory Arithmetic Logic Unit Control Unit Registers The number of registers varies from machine to machine The number is a multiple of 2, typically 16 or 32.

6 CMSC 104, Lecture 066 Machine Instructions : Example 1 Add Two Numbers Stored in Memory 1)Get one value and put it in a register. 2)Get the other value and put it in a register. 3)Activate the addition circuitry with the registers used in steps 1 and 2 as inputs and another register designated to hold the result. 4)Store the result in memory. 5)Stop.

7 CMSC 104, Lecture 067 Machine Instructions Example 2 Division 1)LOAD a register with a value in memory 2)LOAD another register with another value in memory 3)If this second value is zero, jump to step 6. 4)Divide the contents of the first register by the contents of the second register and put the result in the accumulator 5)STORE the contents of the accumulator in memory 6)Stop.

8 CMSC 104, Lecture 068 3 Categories of Machine Instructions l Data Transfer - Instructions that move data around (#s 1, 3, & 4 in example 1). oData isn’t really moved, which implies that the original location is left vacant. oData is actually copied from one place to another. The original is undisturbed. l Arithmetic/Logic - Instructions that tell the control unit to request an activity within the ALU (Arithmetic operations or Logical operations)

9 CMSC 104, Lecture 069 3 Categories of Machine Instructions (con’t) l Control - Instructions that direct the execution of a program rather than manipulate data. oConditional Branch (Step 3 in example 2) - branch to a different step if a certain condition is true. oUnconditional branches or jumps - Example : Jump to step 25.

10 CMSC 104, Lecture 0610 The Stored Program l The idea that a program can be stored in main memory is generally credited to John Von Neumann. l In fact, modern computers are said to have Von Neumann architecture. l Many programs can be stored in memory. To execute the program we want its first instruction is fetched from memory.

11 CMSC 104, Lecture 0611 The Stored Program (con’t) l Remember that whether the program is written in a high-level language, like C, or in assembly language, it is transformed into machine language before the computer can use it. l Machine language is comprised of a series of individual instructions that are coded into 1’s and 0’s.

12 CMSC 104, Lecture 0612 Machine Language Instructions l Each machine language instruction is made up of two parts oThe opcode - a bit pattern (of 1’s and 0’s) that is a code for an operation, like LOAD, ADD, JUMP or STORE oThe operands - bit patterns that provide more information about the instruction. Example: If the opcode was for LOAD, the the operands would have to say what memory location was to be read and the register to place the value in.

13 CMSC 104, Lecture 0613 Program Execution l A computer follows a program stored in its memory by getting the instructions from memory and putting a copy of them in the control unit as they are needed. l There are two special purpose registers used for program execution: oInstruction register oProgram counter

14 CMSC 104, Lecture 0614 Instruction Register & Program Counter l The Instruction Register (IR) contains the instruction that is currently being executed. l The Program Counter (PC) contains the address of the next instruction in memory.

15 CMSC 104, Lecture 0615 Program Execution l The control unit performs its job by continually repeating what is called the machine cycle l The machine cycle consists of 3 steps: oFetch - gets the next instruction from memory oDecode - decodes the bit pattern in the instruction register oExecute - performs the action requested by the instruction in the instruction register

16 CMSC 104, Lecture 0616 Program vs Data l Many programs can be stored in the computer’s memory l We can start a program running by putting its starting address in the program counter. l Both data and programs are stored in memory, and remembering that they are both just a collection of 1’s and 0’s, if the address of data is put into the program counter, the machine will attempt to execute data. The likelihood is that it won’t get very far.

17 CMSC 104, Lecture 0617 Other ALU Operations l Arithmetic Instructions (already mentioned) l Logic Instructions o AND, OR and EXCLUSIVE OR are the logic instructions. oThey all take two operands and produce one result.

18 CMSC 104, Lecture 0618 Logical Operations l For all logical operations, we consider a 1 to be true and a 0 to be false. l Truth tables can be constructed for each of the logical operations and the contents of these truth tables can be considered the definitions of the operations. l With logical operations, unlike addition, each column’s result is independent of the results of its neighboring columns.

19 CMSC 104, Lecture 0619 Truth Tables l A truth table is a table of values for an operation. To construct a truth table for an operation, put all possible values of one variable across the top of the table and all possible values of a second variable down the left side of the table. l The upper left corner of the table is divided in two and should give the names of the variables being used.

20 CMSC 104, Lecture 0620 Truth Table for AND 0 1 0 1 0 0 0 1 A B

21 CMSC 104, Lecture 0621 AND l We can see from the truth table for AND that the only way we can get a result of true is if both operands are true. l So A AND B is true if and only if A is true and B is also true.

22 CMSC 104, Lecture 0622 Truth Table for OR 0 1 0 1 0 1 A B 1 1

23 CMSC 104, Lecture 0623 OR l We can see from the truth table for OR that the only way we can get a result of false is if both operands are false. l So A OR B is true, if A is true and B is also true, or if only A is true, or if only B is true. So either A or B needs to be true or both can be true.


Download ppt "CMSC 104, Lecture 061 Stored Programs A look at how programs are executed."

Similar presentations


Ads by Google