71
Computer Architecture Deepak John Department Of Computer Applicaions SJCET-Pala

Computer organization basics

Embed Size (px)

DESCRIPTION

Lecture Notes,PPT Presentation,

Citation preview

Page 1: Computer organization  basics

Computer Architecture

Deepak John Department Of Computer Applicaions

SJCET-Pala

Page 2: Computer organization  basics

COMPUTER TYPES

Computers are classified based on the parameters like

• Speed of operation• Cost• Computational power• Type of application

Page 3: Computer organization  basics

DESK TOP COMPUTER

• Processing &storage units, visual display &audio uits,keyboards

• Storage media-Hard disks, CD-ROMs• Eg: Personal computers which is used in homes and offices• Advantage: Cost effective, easy to operate, suitable for general

purpose educational or business application

NOTEBOOK COMPUTER

• Compact form of personal computer (laptop)• Advantage is portability

Page 4: Computer organization  basics

WORK STATIONS• More computational power than PC•Costlier•Used to solve complex problems which arises in engineering application (graphics, CAD/CAM etc)

ENTERPRISE SYSTEM (MAINFRAME)•More computational power•Larger storage capacity•Used for business data processing in large organization•Commonly referred as servers or super computers

Page 5: Computer organization  basics

SERVER SYSTEM

• Supports large volumes of data which frequently need to be accessed or to be modified•Supports request response operation

SUPER COMPUTERS

•Faster than mainframes•Helps in calculating large scale numerical and algorithm calculation in short span of time•Used for aircraft design and testing, military application and weather forecasting

Page 6: Computer organization  basics

Basic Terminology• Computer

– A device that acceptsinput, processes data,stores data, and producesoutput, all according to aseries of storedinstructions.

• Hardware– Includes the electronic and

mechanical devices thatprocess the data; refers tothe computer as well asperipheral devices.

• Software– A computer program that

tells the computer how toperform particular tasks.

• Network– Two or more computers and

other devices that areconnected, for the purposeof sharing data andprograms.

• Peripheral devices– Used to expand the

computer’s input, outputand storage capabilities.

Page 7: Computer organization  basics

Basic Terminology• Input

– Whatever is put into a computer system.• Data

– Refers to the symbols that represent facts, objects, or ideas.• Output

– Consists of the processing results produced by a computer.• Processing

– Manipulation of the data in many ways.• Memory

– Area of the computer that temporarily holds data waiting to beprocessed, stored, or output.

• Storage– Area of the computer that holds data on a permanent basis when

it is not immediately needed for processing.

Page 8: Computer organization  basics

Basic Terminology

•Assembly language program (ALP) – Programs are written using mnemonics

•Mnemonic – Instruction will be in the form of English like form

•Assembler – is a software which converts ALP to MLL (Machine Level Language)

•HLL (High Level Language) – Programs are written using English like statements

•Compiler - Convert HLL to MLL, does this job by reading source program at once

Page 9: Computer organization  basics

Basic Terminology

•Interpreter – Converts HLL to MLL, does this job statement by statement

•System software – Program routines which aid the user in the execution of programs eg: Assemblers, Compilers

•Operating system – Collection of routines responsible for controlling and coordinating all the activities in a computer system

Page 10: Computer organization  basics

FUNCTIONAL UNITS OF COMPUTER• Input Unit• Output Unit• Central processing Unit (ALU and Control Units)• Memory• Bus Structure

Control

ALU

Memory

Processor

Input

Output

Page 11: Computer organization  basics

INPUT UNIT:•Converts the external world data to a binary format, which can beunderstood by CPU•Eg: Keyboard, Mouse, Joystick etcOUTPUT UNIT:•Converts the binary format data to a format that a common man canunderstand•Eg: Monitor, Printer, LCD, LED etcCPU•The “brain” of the machine•Responsible for carrying out computational task•Contains ALU, CU, Registers•ALU Performs Arithmetic and logical operations•CU Provides control signals in accordance with some timings which inturn controls the execution process•Register Stores data and result and speeds up the operation

Page 12: Computer organization  basics

MEMORY•Stores data, results, programs•Two class of storage(i) Primary (ii) Secondary•Two types are RAM or R/W memory and ROM read only memory•ROM is used to store data and program which is not going to change.•Secondary storage is used for bulk storage or mass storage

Page 13: Computer organization  basics

Basic Operational ConceptsBasic Function of Computer

• To Execute a given task as per the appropriate program• Program consists of list of instructions stored in memory

Interconnection between Processor and Memory

Page 14: Computer organization  basics

RegistersRegisters are fast stand-alone storage locations that hold datatemporarily. Multiple registers are needed to facilitate theoperation of the CPU. Some of these registers are

Two registers-MAR (Memory Address Register) and MDR(Memory Data Register) : To handle the data transferbetween main memory and processor. MAR-Holds addresses,MDR-Holds data

Instruction register (IR) : Hold the Instructions that iscurrently being executed

Program counter: Points to the next instructions that is tobe fetched from memory

Page 15: Computer organization  basics

Typical Operating Steps

• Programs reside in the memory through inputdevices

• PC is set to point to the first instruction• The contents of PC are transferred to MAR• A Read signal is sent to the memory• The first instruction is read out and loaded

into MDR• The contents of MDR are transferred to IR• Decode and execute the instruction

Page 16: Computer organization  basics

Typical Operating Steps (Cont’)

• Get operands for ALUGeneral-purpose registerMemory (address to MAR – Read – MDR to ALU)

• Perform operation in ALU• Store the result backTo general-purpose registerTo memory (address to MAR, result to MDR – Write)

• During the execution, PC is incremented to the next instruction

Page 17: Computer organization  basics

BUS STRUCTUREConnecting CPU and memory

The CPU and memory are normally connected by threegroups of connections, each called a bus: data bus, addressbus and control bus

Connecting CPU and memory using three buses

Page 18: Computer organization  basics

Bus Structure• Single-bus

Speed Issue• Different devices have different transfer/operate speed.• If the speed of bus is bounded by the slowest device

connected to it, the efficiency will be very low.• A common approach – use buffers.

Page 19: Computer organization  basics

Memory Locations, Addresses, and Operations

Page 20: Computer organization  basics

• Memory consists ofmany millions ofstorage cells, each ofwhich can store 1 bit.

• Data is usuallyaccessed in n-bitgroups. n is calledword length.

second word

first word

Figure Memory words.

n bits

last word

i th word

•••

•••

Page 21: Computer organization  basics

• A k-bit address memory has 2k memory locations, namely0 – 2k-1, called memory space.

24-bit memory: 224 = 16,777,216 = 16M (1M=220)32-bit memory: 232 = 4G (1G=230)

• byte-addressable memory.• Byte locations have addresses 0, 1, 2, … If word length is

32 bits, the successive words are located at addresses 0,4, 8,…

Page 22: Computer organization  basics

Big-Endian and Little-Endian Assignments

2k

4- 2k

3- 2k

2- 2k

1- 2k

4-2k

4-

0 1 2 3

4 5 6 7

00

4

2k

1- 2k

2- 2k

3- 2k

4-

3 2 1 0

7 6 5 4

Byte addressByte address

(a) Big-endian assignment (b) Little-endian assignment

4

W ordaddress

•••

•••

Figure . Byte and word addressing.

Big-Endian: lower byte addresses are used for the most significant bytes of theword

Little-Endian: opposite ordering. lower byte addresses are used for the lesssignificant bytes of the word

Page 23: Computer organization  basics

• Address ordering of bytes• Word alignment

– Words are said to be aligned in memory if theybegin at a byte address. that is a multiple of thenum of bytes in a word.

• 16-bit word: word addresses: 0, 2, 4,….• 32-bit word: word addresses: 0, 4, 8,….• 64-bit word: word addresses: 0, 8,16,….

Page 24: Computer organization  basics

Instruction and Instruction Sequencing

Page 25: Computer organization  basics

“Must-Perform” Operations

• Data transfers between the memory and theprocessor registers

• Arithmetic and logic operations on data• Program sequencing and control• I/O transfers

Page 26: Computer organization  basics

Register Transfer Notation• Identify a location by a symbolic name standing

for its hardware binary address (LOC, R0,…)• Contents of a location are denoted by placing

square brackets around the name of the location(R1←[LOC], R3 ←[R1]+[R2])

Assembly Language Notation Represent machine instructions and programs. Move LOC, R1 = R1←[LOC] Add R1, R2, R3 = R3 ←[R1]+[R2]

Page 27: Computer organization  basics

CPU Organization

• Single Accumulator– Result usually goes to the Accumulator– Accumulator has to be saved to memory quite often

• General Register– Registers hold operands thus reduce memory traffic– Register bookkeeping

• Stack– Operands and result are always in the stack

Page 28: Computer organization  basics

Instruction Formats

• Three-Address Instructions– ADD R1, R2, R3 R1 ← R2 + R3

• Two-Address Instructions– ADD R1, R2 R1 ← R1 + R2

• One-Address Instructions– ADD M AC ← AC + M

• Zero-Address Instructions– ADD TOS ← TOS + (TOS – 1)

Opcode Operand(s) or Address(es)

Page 29: Computer organization  basics

Instruction Formats

Example: Evaluate (A+B) ∗ (C+D)• Three-Address

1. ADD R1, A, B ; R1 ← M[A] + M[B]2. ADD R2, C, D ; R2 ← M[C] + M[D]3. MUL X, R1, R2 ; M[X] ← R1 ∗ R2

Page 30: Computer organization  basics

Instruction FormatsExample: Evaluate (A+B) ∗ (C+D)• Two-Address

1. MOV R1, A ; R1 ← M[A]2. ADD R1, B ; R1 ← R1 + M[B]3. MOV R2, C ; R2 ← M[C]4. ADD R2, D ; R2 ← R2 + M[D]5. MUL R1, R2 ; R1 ← R1 ∗ R26. MOV X, R1 ; M[X] ← R1

Page 31: Computer organization  basics

Instruction Execution and Straight-Line Sequencing

R0,C

B,R0

A,R0

Movei + 8

Begin execution here Movei

ContentsAddress

C

B

A

the programData for

segmentprogram3-instruction

Addi + 4

Figure A program for C ← [Α] + [Β].

For executing the pgm,address offirst instruction placed in PC andthe processor control circuits usethe information in the PC to fetchand execute instructions, one at atime ,in the order of increasingaddresses is called straight linesequencing

Three-phase procedure-Instruction fetch-Instruction decode-Instruction execute

Page 32: Computer organization  basics

Instruction ExecutionInstruction execution is a 3-phase process:instr fetch:select an instr. from MM based on the current value ofthe PC & place it in the IR.instr decode:decode and fetch the operand values.instr execute:perform the appropriate data transformations andstore the results. In the case of sequencing/branchinstructions, update the PC if necessary.

Page 33: Computer organization  basics

BRANCHING

A straight line program for adding n numbers Using a loop to add n numbers

Page 34: Computer organization  basics

BRANCHING• Branch instruction are those which changes the normal

sequence of execution.• Sequence can be changed either conditionally or

unconditionally.• Accordingly we have conditional branch instructions and

unconditional branch instruction.• Conditional branch instruction changes the sequence

only when certain conditions are met.• Unconditional branch instruction changes the sequence

of execution irrespective of condition of the results.

Page 35: Computer organization  basics

Condition Codes

• Condition code flags• Condition code register / status register• N (negative)• Z (zero)• V (overflow)• C (carry)• Different instructions affect different flags

Page 36: Computer organization  basics

Addressing Modes

Page 37: Computer organization  basics

Addressing Modes

• Immediate• Direct• Indirect• Register• Register Indirect• Displacement (Indexed) • Stack

Page 38: Computer organization  basics

Immediate Addressing• Operand is part of instruction• Operand = address field• e.g. ADD 5

– Add 5 to contents of accumulator– 5 is operand

• No memory reference to fetch data• Fast,Limited range

OperandOpcode

Instruction

Page 39: Computer organization  basics

Direct Addressing• Address field contains address of operand• Effective address (EA) = address field (A)• e.g. ADD A

– Add contents of cell A to accumulator– Look in memory at address A for operand

• Single memory reference to access data• No additional calculations to work out effective address• Limited address space

Page 40: Computer organization  basics

Direct Addressing Diagram

Address AOpcode

Instruction

Memory

Operand

Page 41: Computer organization  basics

Indirect Addressing• Memory cell pointed to by address field contains the address of

(pointer to) the operand• EA = (A)

– Look in A, find address (A) and look there for operand• e.g. ADD (A)

– Add contents of cell pointed to by contents of A to accumulator• Large address space• Multiple memory accesses to find operand• Hence slower

Page 42: Computer organization  basics

Indirect Addressing Diagram

Address AOpcode

Instruction

Memory

Operand

Pointer to operand

Page 43: Computer organization  basics

Register Addressing • Operand is held in register named in address filed• EA = R• Ex:add a,b• The contents of register B are added to the accumulator ,a += b;• Limited number of registers• Very small address field needed

– Shorter instructions– Faster instruction fetch

• No memory access• Very fast execution• Very limited address space

Page 44: Computer organization  basics

Register Addressing Diagram

Register Address ROpcode

Instruction

Registers

Operand

Page 45: Computer organization  basics

Register Indirect Addressing• EA = (R)• Operand is in memory cell pointed to by contents of register R.• One fewer memory access than indirect addressing.• Mov (R1),A

Register Address ROpcode

Instruction

Memory

OperandPointer to Operand

Registers

Page 46: Computer organization  basics

Displacement Addressing• EA = A + (R)• Address field hold two values

– A = base value– R = register that holds displacement– or vice versa

Page 47: Computer organization  basics

Register ROpcode

Instruction

Memory

OperandPointer to Operand

Registers

Address A

+

Page 48: Computer organization  basics

Relative Addressing• A version of displacement addressing• R = Program counter, PC• EA = A + (PC)• i.e. get operand from A cells from current location pointed to by PC• c.f locality of reference & cache usage

Page 49: Computer organization  basics

Base-Register Addressing• A holds displacement• R holds pointer to base address• R may be explicit or implicit• e.g. segment registers in 80x86

Page 50: Computer organization  basics

Indexed Addressing• A = base• R = displacement• EA = A + (R)• Good for accessing arrays

– EA = A + (R)– R++

Page 51: Computer organization  basics

Stack Addressing• Operand is (implicitly) on top of stack• e.g.

– ADD Pop top two items from stackand add

Page 52: Computer organization  basics

• The different ways in which the location of an operand is specified inan instruction are referred to as addressing modes.

Name Assem bler syntax Addressing function

Immediate #V alue Op erand = Value

Register R i EA = R i

Absolute(Direct) LOC EA = LOC

Indirect (Ri) EA = [Ri](LOC) EA = [LOC]

Index X(R i) EA = [Ri]+ X

Base with index (Ri,Rj) EA = [Ri]+ [Rj]

Base with index X(R i,Rj) EA = [Ri]+ [Rj] + Xand offset

Relative X(PC) EA = [PC] + X

Autoincrement (Ri)+ EA = [Ri];Increment R i

Autodecrement (Ri) Decremen t R i ;EA = [Ri]

Register Mode-Operand is the contents of a processor registerAbsolute Mode -Operand is in a memory LocationEffective Address:is any operand to an instruction which references memory.

Page 53: Computer organization  basics

Assembly Language

Page 54: Computer organization  basics

Assembly Language Instructions• Built from two pieces

Add R1, R3, 3

OpcodeWhat to do with the data

(ALU operation)

OperandsWhere to get data and

put the results• An instruction has the following format:

Page 55: Computer organization  basics

Types of Instructions• Data Transfer

InstructionsName MnemonicLoad LDStore STMove MOV

Exchange XCHInput IN

Output OUTPush PUSHPop POP

Arithmetic

Name MnemonicIncrement INCDecrement DEC

Add ADDSubtract SUBMultiply MULDivide DIV

Add with carry ADDCSubtract with borrow SUBB

Negate NEG

Page 56: Computer organization  basics

Data Manipulation Instructions• Logical & Bit Manipulation• Shift

Name MnemonicClear CLR

Complement COMAND ANDOR OR

Exclusive-OR XORClear carry CLRCSet carry SETC

Complement carry COMCEnable interrupt EIDisable interrupt DI

Name MnemonicLogical shift right SHRLogical shift left SHL

Arithmetic shift right SHRAArithmetic shift left SHLA

Rotate right RORRotate left ROL

Rotate right through carry RORCRotate left through carry ROLC

Page 57: Computer organization  basics

Program Control InstructionsName Mnemonic

Branch BR

Jump JMP

Skip SKP

Call CALL

Return RETCompare (Subtract) CMP

Test (AND) TST

Conditional Branch Instructions

Mnemonic Branch Condition Tested

ConditionBZ Branch if zero Z = 1

BNZ Branch if not zero Z = 0BC Branch if carry C = 1

BNC Branch if no carry C = 0BP Branch if plus S = 0BM Branch if minus S = 1BV Branch if overflow V = 1

BNV Branch if no overflow V = 0

Page 58: Computer organization  basics

Assembly Directive

• For an assembler to produce an object code, it has to know the following:

1. How to interpret the name (sum = 200)2. Where to place the instructions in the memory 3. Where to place the data operands in the memory

Page 59: Computer organization  basics

• Assembler DirectivesAllows the programmer to specify other information needed translate the source program into the object program

• EQU-simply equates a symbolic name to a numeric value. • ORIGIN-tells the assembler where to load instructions and data

into memory.• DATAWORD- states that the data value 100, is to be placed in the

memory (at address 204).• RESERVE- declares that a memory block of 400 bytes, is to be

reserved for data.• RETURN -directive indicates where the execution of the program

should be terminated.• END -directive tells the assembler where is the end of the source

program.

Page 60: Computer organization  basics
Page 61: Computer organization  basics

Assembler

• The assembler is a program that replaces all symbols inthe source code with the binary codes.

• The assembler also replaces names and labels with theactual values.

• The assembler scans through a source program, keeptracks of all names and the numerical values in a symboltable. When names appear, they are replaced withvalues from this table.

• Normally use two pass assembler

Page 62: Computer organization  basics
Page 63: Computer organization  basics

Stacks

Page 64: Computer organization  basics

• Stack is a list of dataelements that can beadded or removed atone end only (top). Itis LIFO ( Last in firstout)

• Stack is usually usedto handle controlbetween a mainprogram andsubroutines

• SP-Stack pointer is aprocessor registerused to keep track ofthe address of theelement of the stackthat is at the Top

.

.

.-28

17

739

.

.

.43

.

.

.

Current

Top element

Bottomelement

SP

Stack

Pointerregister

BOTTOM

0

2k-1

Stack

PUSH: inserting an ElementPOP: removing an element

Page 65: Computer organization  basics

19

-28

17

739

.

.

.43

19

-28

17

739

.

.

.43

-28

Stack

SP

SP

NEWITEM ITEM

(a) After push from NEWITEM (b) After pop into ITEM

Page 66: Computer organization  basics

Subroutines• Only one copy of subroutine is store in a memory to save space.

Any program that want to use a subroutine simply branches to itsstarting location.

• When a subroutine returns, the assembler has to make sure that itreturns to the appropriate location. The simplest way is to use a linkregister to save the content of the PC when a subroutine is called.

MemoryLocation

Calling Program MemoryLocation

Subroutine SUB

.

.

.

200 Call SUB 1000 first instruction204 next instruction .

.

.

.

.

. Return

Page 67: Computer organization  basics

204

204

1000

Link

PC

Call Return

Page 68: Computer organization  basics

• The link register cannot support the nested subroutine calls (asubroutine calling another subroutine).

• Using a stack concept, nested subroutine calls can be carried out atany depth.– Call instruction : pushes the content of the PC to the stack and

loads the beginning of subroutine address to the PC.– Return instruction : pops the return address from a stack and

copy it to a PC.• Parameter passing

1. Can be done using registers. The called program can place aset of parameters in a set of registers before calling asubroutine. The subroutine then uses those values and returnsthe result via another register.

2. Can also be done by placing parameters in the stack togetherwith the return address.

Page 69: Computer organization  basics

Interrupt• An interrupt is a request from I/O device for service by

processor• Processor provides requested service by executing interrupt

service routine (ISR)• Contents of PC, general registers, and some control

information are stored in memory .• When ISR completed, processor restored, so that interrupted

program may continue

Page 70: Computer organization  basics

PERFORMANCE

•Time taken by the system to execute a program•Parameters which influence the performance are

•Clock speed•Type and number of instructions available•Average time required to execute an instruction•Memory access time•Power dissipation in the system•Number of I/O devices and types of I/O devices connected•The data transfer capacity of the bus

Page 71: Computer organization  basics

Basic Instruction Cycle• Basic computer operation cycle

– Fetch the instruction from memory into a control register(PC)

– Decode the instruction– Locate the operands used by the instruction– Fetch operands from memory (if necessary)– Execute the operation in processor registers– Store the results in the proper place– Go back to step 1 to fetch the next instruction