Unit 2
Unit 2
Computer Organization
                     (Autonomous)                                         Basic Computer Organization and Design: Instruction codes –
                                                                          Stored Program Organization, Indirect Address, Computer Registers –
                                                                          Common Bus Systems, Computer instructions – Instruction Set
                                  UNIT II                                 Completeness, Timing and control, Instruction cycle – Fetch and
                                                                          Decode, Determine the Type of Instruction, Register Reference
                      Sections - A & D                                    Instructions, Memory – Reference Instructions – AND to AC, ADD to
                                                                          AC, LDA :Load to AC,STA: Store AC, BUN: Branch Unconditionally,
                                                                          BSA: Branch and Save Return Address, ISZ: Increment and Skip if
                                                                          Zero, Control Flow Chart, Input – Output Instructions and Interrupt –
                                                   Prepared by            Input – Output Configuration, Input-Output Instructions, Program
   Anil Kumar Prathipati, Asst. Prof., Dept. of CSE.                      Interrupt, Interrupt Cycle.
1 2
15 0
                                                                                                                                            4095
                                                                  3                                                                                4
                                                                                                     STORED PROGRAM ORGANIZATION
                          INSTRUCTIONS
                                                                                       Instruction Format
                                                                                       • A computer instruction is often divided into two parts
   • Program
                                                                                          – An opcode (Operation Code) that specifies the operation for that
      – A sequence of (machine) instructions                                                instruction
   • (Machine) Instruction                                                                – An address that specifies the registers and/or locations in memory
      – A group of bits that tell the computer to perform a specific                        to use for that operation
        operation (a sequence of micro-operation)                                      • In the Basic Computer, since the memory contains 4096 (= 212)
   • The instructions of a program, along with any                                       words, we needs 12 bit to specify which memory address this
     needed data are stored in memory                                                    instruction will use
   • The CPU reads the next instruction from memory                                    • In the Basic Computer, bit 15 of the instruction specifies the
                                                                                         addressing mode (0: direct addressing, 1: indirect addressing)
   • It is placed in an Instruction Register (IR)
                                                                                       • Since the memory words, and hence the instructions, are 16 bits
   • Control circuitry in control unit then translates the                               long, that leaves 3 bits for the instruction’s opcode
     instruction into the sequence of microoperations                                                                         Instruction Format
     necessary to implement it                                                                                            15 14  12 11                0
                                                                                                                           I Opcode    Address
                                                                                   5                                                                                       6
                                                                                                                          Addressing
                                                                                                                            mode
                                                                                                                 COMPUTER REGISTERS
                   ADDRESSING MODES
                                                                                         Registers in the Basic Computer
• The address field of an instruction can represent either
   – Direct address: the address in memory of the data to use (the                                     11                      0
                                                                                                                     PC
     address of the operand), (or)                                                                                                             Memory
                                                                                                       11                      0
   – Indirect address: the address in memory of the address in memory                                                AR
                                                                                                                                                 4096 x 16
     of the data to use
                                  Direct addressing          Indirect addressing                15                             0
                                                                                                            IR                                                       CPU
                           22    0 ADD        457      35 1 ADD          300
                                                                                                15                             0       15                      0
                                                      300         1350                                      TR                                     DR
                           457       Operand                                                    7           0    7             0       15                      0
                                                      1350      Operand                              OUTR            INPR                          AC
                                         +                         +                    List of BC Registers
                                         AC                        AC
                                                                                                DR          16       Data Register          Holds memory operand
                                                                                                AR          12       Address Register       Holds address for memory
• Effective Address (EA)                                                                        AC
                                                                                                IR
                                                                                                            16
                                                                                                            16
                                                                                                                     Accumulator
                                                                                                                     Instruction Register
                                                                                                                                            Processor register
                                                                                                                                            Holds instruction code
   – The address, that can be directly used without modification to                             PC          12       Program Counter        Holds address of instruction
     access an operand for a computation-type instruction, or as the                            TR          16       Temporary Register     Holds temporary data
     target address for a branch-type instruction                7                              INPR         8        Input Register        Holds input character          8
                                                                                                OUTR         8        Output Register       Holds output character
                                                                                COMMON BUS SYSTEM
                    COMMON BUS SYSTEM                                                                                                   S2
                                                                                                                                        S1        Bus
                                                                                                                                        S0
                                                                                                                    Memory unit                    7
                                                                                                                     4096 x 16
                                                                                                                                    Address
                                                                                                                Write        Read
                                                                                                                 LD INR CLR
  using a bus                                                                                                            PC                        2
LD INR CLR
                                                                                                                        DR                         3
• This gives a savings in circuitry over complete                                                               LD INR CLR
LD INR CLR
                                                                                                                 INPR
                                                                                                                        IR                         5
                                                                                                               LD
                                                                                                                        TR                         6
                                                                                                                LD INR CLR
                                                                                                                 OUTR
                                                                                                                                         Clock
                                                                9                                               LD                                         10
                                                                                                         16-bit common bus
    – Will determine where the data from the bus gets loaded
 • The 12-bit registers, AR and PC, have 0’s loaded onto
                                                                         Input-Output Instructions                                (OP-code =111, I = 1)
   the bus in the high order 4 bit positions
                                                                                 15                    12 11                                 0
 • When the 8-bit register OUTR is loaded from the bus, the                      1       1    1    1                I/O operation
                     CONTROL UNIT
                                                                                              TIMING AND CONTROL
• Control unit (CU) of a processor translates from machine
  instructions to the control signals for the microoperations              Control unit of Basic Computer
  that implement them                                                                            Instruction register (IR)
                                                                                          15    14 13 12            11 - 0
• Control units are implemented in one of two ways                                                                                     Other inputs
• Hardwired Control
                                                                                                   3x8
   – CU is made up of sequential and combinational circuits to generate                          decoder
                                                                                               7 6543 210
     the control signals                                                                                              D0
                                                                                          I                                         Combinational
                                                                                                                      D7              Control         Control
                                                                                                                                       logic          signals
                                                                   15                                                                                           16
                      TIMING SIGNALS
- Generated by 4-bit sequence counter and 416 decoder
                                                                                                                          INSTRUCTION CYCLE
- The SC can be incremented or cleared.
-- Example: T0, T1, T2, T3, T4, T0, T1, . . .
                                                                                                   •   In Basic Computer, a machine instruction is executed in the
     Assume: At time T4, SC is cleared to 0 if decoder output D3 is                                    following cycle:
active.                                                                                                1. Fetch an instruction from memory
                                D3T 4: SC  0
                      T0          T1               T2             T3            T4   T0                2. Decode the instruction
        Clock
                                                                                                                                                                         T1
                                                                                                                                      IR  M[AR], PC  PC + 1
                T1                                                     S2
                                                                                                                                                                            T2
                T0                                                     S1 Bus                                                      Decode Opcode in IR(12-14),
                                                                                                                                    AR  IR(0-11), I  IR(15)
                                                                       S0
                                  Memory                                    7                                           (Register or I/O) = 1               = 0 (Memory-reference)
                                   unit                                                                                                            D7
                                                        Address
                                            Read                                                                       (I/O) = 1           = 0 (register)          (indirect) = 1         = 0 (direct)
                                                                                                                                      I                                              I
                                        AR                                  1                                                    T3                         T3                 T3                  T3
                                                                                                                        Execute                 Execute               AR  M[AR]        Nothing
                                    LD                                                                               input-output         register-reference
                                                                                                                      instruction             instruction
                                        PC                                  2                                           SC  0                 SC  0                          Execute            T4
                                                                                                                                                                            memory-reference
                                                                                                                                                                               instruction
                                       INR
                                                                                                                                                                                 SC  0
                                       IR                                   5
                                  LD
                                                                                                         D'7IT 3:      AR M[AR]
                                                             Clock                                       D'7I'T 3:     Nothing
                                 Common bus
                                                                                              19         D7I'T 3:      Execute a register-reference instr.                                               20
                                                                                                         D7IT 3:       Execute an input-output instr.
    REGISTER REFERENCE INSTRUCTIONS                                                                  MEMORY REFERENCE INSTRUCTIONS
Register Reference Instructions are identified when                                                    Operation
                                                                                              Symbol                  Symbolic Description
                                                                                                       Decoder
        - D7 = 1, I = 0                                                                        AND      D0         AC     AC  M[AR]
        - Register Ref. Instr. is specified in b 0 -- b11 of IR                                ADD      D1         AC     AC + M[AR], E  Cout
        - Execution starts with timing signal T 3                                              LDA      D2         AC     M[AR]
   r = D7 IT 3 => Register Reference Instruction                                              STA      D3         M[AR]    AC
   Bi = IR(i) , i=0,1,2,...,11                                                                 BUN      D4         PC     AR
                                                                                               BSA      D5         M[AR]    PC, PC  AR + 1
                                                                                               ISZ      D6         M[AR]    M[AR] + 1, if M[AR] + 1 = 0 then PC  PC+1
            r:                    SC  0
    CLA     rB11:                 AC  0
    CLE     rB10:                 E0                                                         - The effective address of the instruction is in AR and was placed there during
    CMA     rB9:                  AC  AC’                                                           timing signal T 2 when I = 0, or during timing signal T 3 when I = 1
    CME     rB8:                  E  E’                                                      - Memory cycle is assumed to be short enough to complete in a CPU cycle
    CIR     rB7:                  AC  shr AC, AC(15)  E, E  AC(0)                          - The execution of MR instruction starts with T 4
    CIL     rB6:                  AC  shl AC, AC(0)  E, E  AC(15)
    INC     rB5:                  AC  AC + 1                                                AND to AC
    SPA     rB4:                  if (AC(15) = 0) then (PC  PC+1)                                 D0T 4:    DR  M[AR]                          Read operand
    SNA     rB3:                  if (AC(15) = 1) then (PC  PC+1)                                 D0T 5:    AC  AC  DR, SC  0                AND with AC
    SZA     rB2:                  if (AC = 0) then (PC  PC+1)                               ADD to AC
    SZE     rB1:                  if (E = 0) then (PC  PC+1)                                      D1T 4:    DR  M[AR]                          Read operand
    HLT     rB0:                  S  0 (S is a start-stop flip-flop)                              D1T 5:    AC  AC + DR, E  Cout, SC  0      Add to AC and store carry in E
                                                                                        21                                                                                22
                 AR = 135                                135           21
                       136        Subroutine         PC = 136       Subroutine
                            FGI=0
                                                                                   FGO=1                            p:       SC  0                                 Clear SC
                                                                               Start Output               INP       pB11:    AC(0-7)  INPR, FGI  0                Input char. to AC
                        Start Input
                                                                                                          OUT       pB10:    OUTR  AC(0-7), FGO  0                Output char. from AC
                          FGI  0                                                AC  Data                SKI       pB9:     if(FGI = 1) then (PC  PC + 1)         Skip on input flag
                                                                                                          SKO       pB8:     if(FGO = 1) then (PC  PC + 1)         Skip on output flag
                                                                         yes
                  yes
                           FGI=0                                                   FGO=0                  ION       pB7:     IEN  1                                Interrupt enable on
                                no                                                        no              IOF       pB6:     IEN  0                                Interrupt enable off
                         AC  INPR                                              OUTR  AC
                                                                                   FGO  0
                yes        More
                         Character                                    yes          More
                                no                                               Character
                            END                                                           no        27                                                                                               28
                                                                                        END
        INTERRUPT INITIATED INPUT/OUTPUT                                                        FLOWCHART FOR INTERRUPT CYCLE
                                                                                                                                                               R = Interrupt f/f
-Open communication only when some data has to be passed                                                Instruction cycle        =0
                                                                                                                                      R
                                                                                                                                          =1      Interrupt cycle
                                                                                                      Execute                    =0
                                                                                                                        IEN
- When the interface founds that the I/O device is ready for data                                   instructions
                                                                                                                           =1                  Branch to location 1
                                                                                                                                                    PC  1
transfer, it generates an interrupt request to the CPU.                                                            =1
                                                                                                                        FGI
                                                                                                                            =0
                                                                                                                   =1                               IEN  0
- Upon detecting an interrupt, the CPU stops momentarily the task it is                                                 FGO                           R 0
                                                                                                                          =0
doing, branches to the service routine to process the data transfer,                                         R1
                1120                                1120
                                  I/O                                 I/O
                                Program                             Program
1 BUN 0 1 BUN 0