Stored Programs - PowerPoint PPT Presentation

About This Presentation
Title:

Stored Programs

Description:

A look at how programs are executed The Central Processing Unit The CPU is the computer s mechanism for performing operations on data and coordinating the sequence ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 24
Provided by: Denni137
Category:

less

Transcript and Presenter's Notes

Title: Stored Programs


1
Stored Programs
  • A look at how
  • programs are executed

2
The Central Processing Unit
  • The CPU is the computers mechanism for
    performing operations on data and coordinating
    the sequence of these operations.
  • The CPU consists of two main parts
  • The Arithmetic Logic Unit - contains circuitry
    that performs operations
  • The Control Unit - contains circuitry that
    coordinates the machines activities.

3
Registers
  • 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
Control Unit ALU jobs
  • The control unit is responsible for placing the
    data thats 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.
  • The ALU uses the data in the indicated registers
    to do the operation and places the result in the
    indicated register.

5
CPU - Main Memory Diagram
Registers
Arithmetic Logic Unit
Control Unit
Bus
Central Processing Unit
Main Memory
The number of registers varies from machine to
machine The number is a multiple of 2, typically
16 or 32.
6
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
Machine Instructions Example 2Division
  • 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
3 Categories of Machine Instructions
  • Data Transfer - Instructions that move data
    around (s 1, 3, 4 in example 1).
  • Data isnt really moved, which implies that the
    original location is left vacant.
  • Data is actually copied from one place to
    another. The original is undisturbed.
  • Arithmetic/Logic - Instructions that tell the
    control unit to request an activity within the
    ALU (Arithmetic operations or Logical operations)

9
3 Categories of Machine Instructions (continued)
  • Control - Instructions that direct the execution
    of a program rather than manipulate data.
  • Conditional Branch (Step 3 in example 2) - branch
    to a different step if a certain condition is
    true.
  • Unconditional branches or jumps - Example
    Jump to step 25.

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

11
The Stored Program
  • 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.
  • Machine language is comprised of a series of
    individual instructions that are coded into 1s
    and 0s.

12
Machine Language Instructions
  • Each machine language instruction is made up of
    two parts
  • The opcode - a bit pattern (of 1s and 0s) that
    is a code for an operation, like LOAD, ADD, JUMP
    or STORE
  • The 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
Program Execution
  • 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.
  • There are two special purpose registers used for
    program execution
  • Instruction register
  • Program counter

14
Instruction Register Program Counter
  • The Instruction Register (IR) contains the
    instruction that is currently being executed.
  • The Program Counter (PC) contains the address of
    the next instruction in memory.

15
Program Execution
  • The control unit performs its job by continually
    repeating what is called the machine cycle.
  • The machine cycle consists of 3 steps
  • Fetch - gets the next instruction from memory
  • Decode - decodes the bit pattern in the
    instruction register
  • Execute - performs the action requested by the
    instruction in the instruction register.

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

17
Other ALU Operations
  • Arithmetic Instructions (already mentioned)
  • Logic Instructions
  • AND, OR and EXCLUSIVE OR are the logic
    instructions.
  • They all take two operands and produce one result.

18
Logical Operations
  • For all logical operations, we consider a 1 to be
    true and a 0 to be false.
  • 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.
  • With logical operations, unlike addition, each
    columns result is independent of the results of
    its neighboring columns.

19
Truth Tables
  • 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.
  • The upper left corner of the table is divided in
    two and should give the names of the variables
    being used.

20
Truth Table for AND
A
0
1
B
0
0
0
1
0
1
21
AND
  • 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.
  • So A AND B is true if and only if A is true and
    B is also true.

22
Truth Table for OR
A
0
1
B
1
0
0
1
1
1
23
OR
  • 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.
  • 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.
Write a Comment
User Comments (0)
About PowerShow.com