CS Introduction to Computers 2

Embed Size (px)

Citation preview

  • 8/13/2019 CS Introduction to Computers 2

    1/43

    Computer SystemsMay 16,2011

  • 8/13/2019 CS Introduction to Computers 2

    2/43

    Module: Computer System

    Learning Unit: Computer System Components

    The contents here are for Aricent internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 2

  • 8/13/2019 CS Introduction to Computers 2

    3/43

    Objective

    Computation & ComputersComputer HardwareInstruction Set

    Assembly & High Level Language

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 3

  • 8/13/2019 CS Introduction to Computers 2

    4/43

    Computation & Computers

    A Program is a set of instructions however unless the instructions from thisset can be executed it is not useful.

    The set of instructions to achieve a task.

    Consider the following problem: A person wants to buy pearls to make necklaces. He has to make five necklaces

    and each necklace requires 10 pearls. How many pearls does he need to buy?

    Consider Me as a machine who can provide him the result to this problem.

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 4

    Let us say the Machine does not know how to find the answer to this question.However it can be instructed to do so through a program using Multiplication Operation.

    How would the program for this machine look like?

    No of Pearls = Multiply 5 by 10

    The Machine (I) knows how to do multiplication so it can provide the result.

    This is a program written in a set of instructions which can be executed by theMachine called Me.

  • 8/13/2019 CS Introduction to Computers 2

    5/43

    Computation & Computers

    Let us change to a machine which does not understand Multiplication.Change it to a child who knows counting, addition, subtraction but notmultiplication.

    What will be the program that needs to be written?No_of_pearls = 0;

    no_of_necklace = 10;

    While (no_of_necklace > 0){

    no of earls = no of earls + 5

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 5

    _ _ _ _

    no_of_necklace = no_of_necklace - 1}

    The program changes, because the programming language changesbecause the machine changes

    You can't have multiplication instruction in a program written for the child

    Conclusion:

    With every machine you have an instruction set which can be used to instruct themachine

  • 8/13/2019 CS Introduction to Computers 2

    6/43

    Computation & Computers

    What is a machine?

    Everything that we see is a machine

    or is capable of behaving like a machine

    Mostly you can change a program written in a language to an equivalent

    program in another language as it happened in our previous example and

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 6

    o w g ve you e es re resu

    How will you ask the machine to execute multiple instructions in a program

    There has to be an interface through which you instruct the machine

    Car has parts like clutch, gear, accelerator, brake and you can operate these devices to do

    the required thing

  • 8/13/2019 CS Introduction to Computers 2

    7/43

    Computation & Computers

    How does a car move ?

    Put the Car in the Neutral state

    Start it

    Press the Clutch

    Take the gear to state One

    Press Accelerator

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 7

    The Car starts moving

    A Simple Model of a Car ?

    States how many ?

    Inputs how many ? State Transition how many transitions ?

    Finite State Machine

  • 8/13/2019 CS Introduction to Computers 2

    8/43

    Computation & Computers

    Computation

    ~Information Processing

    Information : Data

    e.g., Temperature measured in Celsius

    Processing

    Take the value measured in Celsius

    Convert from Celsius to Farenheit

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 8

    Show the value in FarenheitComputer

    Equipment which can do Information Processing by an algorithmic process

    Algorithm

    Is a finite list of well-defined instructions for accomplishing some task that, given an initial state, willterminate in a defined end-state

  • 8/13/2019 CS Introduction to Computers 2

    9/43

    Computation & Computers

    Calculator vs Computer?

    Are they same?

    No, why not

    The defining feature of modern computers:

    They can be programmed

    A list of instructions (algorithm or the program) can be stored in the computer and can

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 9

    be carried out any time in the future

    Distinguishes them from all other machines

  • 8/13/2019 CS Introduction to Computers 2

    10/43

    Computation & Computers

    How will you Design a computing machine? which components are

    required?

    Machines has to provide interface to enter the Instructions and data

    Machine has to have an Instruction Set which would be used to process

    data

    Mostly computer instructions are simple, e.g.:

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 10

    move some data from one location to another

    Machines has to provide interface to provide/display the result to the user

    Provide capability to store data and instructions, the defining feature

  • 8/13/2019 CS Introduction to Computers 2

    11/43

    Structure - Top Level

    MainMemory

    Peripherals

    CentralProcessingUnit

    Computer

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 11

    Computer

    InputOutput

    SystemsInterconnection

    Communicationlines

  • 8/13/2019 CS Introduction to Computers 2

    12/43

    Computer Hardware

    Arithmetic and Logic Unit

    Program Control Unit

    CPU

    Instruction RegisterProgram Counter

    Stack Pointer

    Register2

    Register1

    Registern

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 12

    Memory-I/O BUS

    Main MemoryDevice 1(DISK)

    Device 2 Device n

  • 8/13/2019 CS Introduction to Computers 2

    13/43

    Components

    The Control Unit and the Arithmetic and Logic Unit constitute the

    Central Processing Unit

    Data and instructions need to get into the system and results out

    Input/output

    Temporary storage of code and results is needed

    Main memory

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 13

  • 8/13/2019 CS Introduction to Computers 2

    14/43

    What is a program?

    A sequence of steps

    For each step, an arithmetic or logical operation is done

    For each operation, a different set of control signals is needed

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 14

  • 8/13/2019 CS Introduction to Computers 2

    15/43

    Function of Control Unit

    For each operation a unique code is provided

    e.g. ADD, MOVE

    A hardware segment accepts the code and issues the control signals

    We have a computer!

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 15

  • 8/13/2019 CS Introduction to Computers 2

    16/43

    Instruction Cycle

    Two steps:

    Fetch

    Execute

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 16

  • 8/13/2019 CS Introduction to Computers 2

    17/43

    Fetch Cycle

    Program Counter (PC) holds address of next instruction to fetch

    Processor fetches instruction from memory location pointed to by PC

    Increment PC

    Unless told otherwise

    Instruction loaded into Instruction Re ister IR

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 17

    Processor interprets instruction and performs required actions

  • 8/13/2019 CS Introduction to Computers 2

    18/43

    Execute Cycle

    Processor-memory

    data transfer between CPU and main memory

    Processor I/O

    Data transfer between CPU and I/O module

    Data processing

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 18

    Some arithmetic or logical operation on data

    Control

    Alteration of sequence of operations

    e.g. jumpCombination of above

  • 8/13/2019 CS Introduction to Computers 2

    19/43

  • 8/13/2019 CS Introduction to Computers 2

    20/43

    Interrupt Cycle

    Added to instruction cycle

    Processor checks for interrupt

    Indicated by an interrupt signal

    If no interrupt, fetch next instruction

    If interrupt pending:

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 20

    Save context

    Set PC to start address of interrupt handler routine

    Process interrupt

    Restore context and continue interrupted program

  • 8/13/2019 CS Introduction to Computers 2

    21/43

    Multiple Interrupts

    Disable interrupts

    Processor will ignore further interrupts while processing one interrupt

    Interrupts remain pending and are checked after first interrupt has been processed

    Interrupts handled in sequence as they occur

    Define priorities

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 21

    Low priority interrupts can be interrupted by higher priority interrupts When higher priority interrupt has been processed, processor returns to previous

    interrupt

  • 8/13/2019 CS Introduction to Computers 2

    22/43

    Connecting

    All the units must be connected

    Different type of connection for different type of unit

    Memory

    Input/Output

    CPU

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 22

  • 8/13/2019 CS Introduction to Computers 2

    23/43

    Memory Connection

    Receives and sends data

    Receives addresses (of locations)

    Receives control signals

    Read

    Write

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 23

    Timing

  • 8/13/2019 CS Introduction to Computers 2

    24/43

    Input/Output Connection

    Similar to memory from computers viewpoint

    Output

    Receive data from computer

    Send data to peripheral

    Input

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 24

    Receive data from peripheral

    Send data to computer

  • 8/13/2019 CS Introduction to Computers 2

    25/43

    CPU Connection

    Reads instruction and data

    Writes out data (after processing)

    Sends control signals to other unitsReceives (& acts on) interrupts

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 25

  • 8/13/2019 CS Introduction to Computers 2

    26/43

    Buses

    There are a number of possible interconnection systems

    Single and multiple BUS structures are most common

    e.g. Control/Address/Data bus (PC)e.g. Unibus (DEC-PDP)

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 26

    Ask what is a bus error ?

  • 8/13/2019 CS Introduction to Computers 2

    27/43

    What is a Bus?

    A communication pathway connecting two or more devices

    Usually broadcast

    Often grouped

    A number of channels in one bus

    e.g. 32 bit data bus is 32 separate single bit channels

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 27

  • 8/13/2019 CS Introduction to Computers 2

    28/43

    Data Bus

    Carries data

    Remember that there is no difference between data and instruction at

    this level

    Width is a key determinant of performance

    8, 16, 32, 64 bit

    different set of control signals is needed

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 28

  • 8/13/2019 CS Introduction to Computers 2

    29/43

    Address bus

    Identify the source or destination of data

    e.g. CPU needs to read an instruction (data) from a given location in

    memory

    Bus width determines maximum memory capacity of system

    e.g. 8080 has 16 bit address bus giving 64k address space

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 29

  • 8/13/2019 CS Introduction to Computers 2

    30/43

    Control Bus

    Control and timing information

    Memory read/write signal

    Interrupt request

    Clock signals

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 30

  • 8/13/2019 CS Introduction to Computers 2

    31/43

    Instruction Set

    Instruction Set of a Machine

    Operands & Operators

    Operators are those operations that are supported on the machine, e.g., add,

    subtract

    What are the operands of Compute hardware

    C example

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 31

    int a,b,c; a = b + c; These are variables

    Can Operands be Variables for Machine Instructions?

    No, these are symbolic names and a general purpose hardware can not work with

    symbolic names

    Operands have to be memory locations

    Either Registers or Memory Addresses

  • 8/13/2019 CS Introduction to Computers 2

    32/43

    Instruction Set

    Instruction Set of a Machine

    Types of Instructions

    Instructions to perform fundamental Arithmetic/Logical Operations

    Add/subtract operation

    Example a = b + c //sum of b and c is placed in a

    Converted into machine language of a particular machine

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 32

    00000010001100100100000000100000

    Basically means: add $R1, $R2, $R3, i.e., sum of values kept in CPU registers R2 andR3 is to be placed in register R1

    Similarly sub $R1, $R2, $R3

    Value kept in register $R3 subtracted from value in $R2 is placed in register $R1

  • 8/13/2019 CS Introduction to Computers 2

    33/43

    Instruction Set

    Instruction Set of a Machine

    Data Movement Instructions

    Load and Store Instructions

    10001101001010000000010010110000

    Load $R1, ($A1) //Load data from memory location M1 into Register R1

    10101101001010000000010010110000

    Store R1 A1 //Store data from Re ister R1 into memor location M1

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 33

  • 8/13/2019 CS Introduction to Computers 2

    34/43

    Instruction Set

    Instruction Set of a Machine

    Logical Operations

    AND

    Instruction looks as follows: AND $R1, $R2, $R3 // $R1 = $R2 & $R3

    Bit-by-bit OR

    NOT

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 34

    Shift right

  • 8/13/2019 CS Introduction to Computers 2

    35/43

    Instruction Set

    Instruction Set of a Machine

    What Distinguishes a Computer from a Calculator?

    Instructions for making Decisions

    Conditional Branch Instructions, an example

    Branch on equal

    beq $R1, $R2, L1 //go to the statement labelled L1 if value in R1 == R2

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 35

    Jump L2 // jump to the statement labelled L2Other such instructions

    Branch if not equal

    Set on less than

  • 8/13/2019 CS Introduction to Computers 2

    36/43

    Instruction Set

    An Issue

    CPU Instruction Set is in the binary form as the CPU understands only 0s

    and 1s

    very difficult for human beings to read/write such instructions

    Programming is very difficult

    Solution

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 36

    Assembly Language

    Symbolic Representation of CPU Instruction Set

    Symbolic name for operators and operands

    add $R1, $R2, $R3

    sub $R1, $R2, $R3

    One statement in Assembly produces exactly one machine instructionThere is one-to-one correspondence between machine instructions and statements

    in the program

  • 8/13/2019 CS Introduction to Computers 2

    37/43

    Instruction Set

    Assembly Language

    Symbolic Representation of CPU Instruction Set

    How do you write a program in this language

    Start an Editor

    Type characters corresponding to instructions

    These characters are saved in ascii format

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 37

    e.g., Assembly language statement: add $R1, $R2, $R3

    Stored form:

    a d d $ R

    01100001011001000110010000100000001001000101 00100011 0001

    Can you execute this statement?

  • 8/13/2019 CS Introduction to Computers 2

    38/43

    Instruction Set

    Assembly Language

    program written in this language can not run as it is in not in binary format

    You need a converter from Assembly language to machine language

    Assembler

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 38

  • 8/13/2019 CS Introduction to Computers 2

    39/43

    Programming in High Level Languages

    Assembly Language

    Is difficult to write programs in Assembly Language also

    Not Portable can run on only one type of machine

    Very Difficult to Debug and very hard to maintain

    Performance can be much better if you write in Assembly performance

    critical applications especially which are small in size can be written in this

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 39

    anguage

    Some programs require detailed access to hardware, like device controllers

    in some embedded applications so those programs can be written in

    Assembly only

    Many times in time critical systems a mixed program is a necessity (80-20

    principle)

  • 8/13/2019 CS Introduction to Computers 2

    40/43

    Programming in High Level Languages

    High level Language

    Better Maintainability

    Closer to language like English

    Easier to understand

    Easier to write, test & debug programs

    Portable across platforms

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 40

    You need a tool called compiler to convert into native machine language

  • 8/13/2019 CS Introduction to Computers 2

    41/43

    Aricent Group makes no representations or warranties with respect to contents of these slides

    and the same are being provided as is. The content/materials in the slides are of a general

    nature and are not intended to address the specific circumstances of any particular individual

    or entity. The material may provide links to internet sites (for the convenience of users) overwhich Aricent Group has no control and for which Aricent Group assumes no responsibility for

    the availability or content of these external sites. While the attempt has been to acknowledge

    sources of materials wherever traceable to an individual or an institution; any materials not

    Disclaimer

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 41

    41

  • 8/13/2019 CS Introduction to Computers 2

    42/43

    Revision History

    Version

    No.

    Date of

    Release

    Author Reviewer Approver Changes

    3.0 16-May-11 Soma Tiwari BS Aligned as per new template

    The contents here are for Aricent Group internal training purposes only and do not carry any commercial value Restricted Aricent Group 2011 42

  • 8/13/2019 CS Introduction to Computers 2

    43/43

    an ou