the von neumann architecture chapter 5.1-5.2 von neumann architecture

27
The Von Neumann The Von Neumann Architecture Architecture Chapter 5.1-5.2 Chapter 5.1-5.2 Von Neumann Von Neumann Architecture Architecture

Post on 21-Dec-2015

269 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

The Von Neumann The Von Neumann ArchitectureArchitecture

Chapter 5.1-5.2Chapter 5.1-5.2

Von NeumannVon NeumannArchitectureArchitecture

Page 2: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 2

Designing ComputersDesigning Computers

• All computers more or less based on the same All computers more or less based on the same basic design, the basic design, the Von Neumann ArchitectureVon Neumann Architecture!!

Page 3: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 3

The Von Neumann The Von Neumann ArchitectureArchitecture

• Model for designing and building computers, Model for designing and building computers, based on the following three characteristics:based on the following three characteristics:

1)1) The computer consists of four main sub-systems:The computer consists of four main sub-systems:• MemoryMemory• ALU (Arithmetic/Logic Unit)ALU (Arithmetic/Logic Unit)• Control UnitControl Unit• Input/Output System (I/O)Input/Output System (I/O)

2)2) Program is stored in memory during execution.Program is stored in memory during execution.3)3) Program instructions are executed sequentially.Program instructions are executed sequentially.

Page 4: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 4

The Von Neumann The Von Neumann ArchitectureArchitecture

Memory

Processor (CPU)

Input-OutputControl Unit

ALUStore data and programStore data and program

Execute programExecute program

Do arithmetic/logic operationsDo arithmetic/logic operationsrequested by programrequested by program

Communicate withCommunicate with"outside world", e.g. "outside world", e.g. • ScreenScreen• KeyboardKeyboard• Storage devices Storage devices • ......

Bus

Page 5: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 5

Memory SubsystemMemory Subsystem• Memory, also called Memory, also called RAMRAM ( (RRandom andom AAccess ccess MMemory), emory),

– Consists of many memory cells (storage units) of a fixed size. Consists of many memory cells (storage units) of a fixed size. Each cell has an address associated with it: 0, 1, …Each cell has an address associated with it: 0, 1, …

– All accesses to memory are to a specified address.All accesses to memory are to a specified address.A cell is the minimum unit of access (fetch/store a complete cell).A cell is the minimum unit of access (fetch/store a complete cell).

– The time it takes to fetch/store a cell is the same for all cells.The time it takes to fetch/store a cell is the same for all cells.• When the computer is running, bothWhen the computer is running, both

– ProgramProgram– Data (variables)Data (variables)

are stored in the memory.are stored in the memory.

Page 6: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 6

RAMRAM• Need to distinguish between Need to distinguish between

– the the addressaddress of a memory cell and of a memory cell and the the contentcontent of a memory cell of a memory cell

• Memory width (Memory width (WW):):– How many bits is each memory How many bits is each memory

cell, typically one cell, typically one bytebyte (=8 bits) (=8 bits)• Address width (Address width (NN):):

– How many bits used to represent How many bits used to represent each address, determines the each address, determines the maximum memory size = maximum memory size = address address spacespace

– If address width is If address width is NN-bits, then -bits, then address space is address space is 22NN (0,1,...,2 (0,1,...,2NN-1)-1)

...

00

11

22

22NN-1-1

1 bit1 bit

WW

00000000000000010000000000000001

NN

22NN

Page 7: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 7

Memory Size / SpeedMemory Size / Speed

• Typical memory in a personal computer (PC):Typical memory in a personal computer (PC):– 64MB - 256MB64MB - 256MB

• Memory sizes:Memory sizes:– Kilobyte Kilobyte (KB)(KB) = 2= 210 10 = = 1,024 bytes ~ 1 1,024 bytes ~ 1

thousandthousand– Megabyte(MB)Megabyte(MB) = 2= 22020 = = 1,048,576 bytes ~ 1 million 1,048,576 bytes ~ 1 million– GigabyteGigabyte (GB)(GB) = 2= 23030 = = 1,073,741,824 bytes ~ 1 billion 1,073,741,824 bytes ~ 1 billion

• Memory Access Time (read from/ write to memory)Memory Access Time (read from/ write to memory)– 50-75 nanoseconds (1 nsec. = 0.000000001 sec.)50-75 nanoseconds (1 nsec. = 0.000000001 sec.)

• RAM isRAM is– volatile (can only store when power is on)volatile (can only store when power is on)– relatively expensiverelatively expensive

Page 8: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 8

Operations on Memory Operations on Memory • Fetch (address):Fetch (address):

– Fetch a copy of the content of memory cell with the specified Fetch a copy of the content of memory cell with the specified address.address.

– Non-destructive, copies value in memory cell.Non-destructive, copies value in memory cell.• Store (address, value):Store (address, value):

– Store the specified value into the memory cell specified by address.Store the specified value into the memory cell specified by address.– Destructive, overwrites the previous value of the memory cell.Destructive, overwrites the previous value of the memory cell.

• The memory system is interfaced via:The memory system is interfaced via:– Memory Address Register (MAR)Memory Address Register (MAR)– Memory Data Register (MDR)Memory Data Register (MDR)– Fetch/Store signalFetch/Store signal

Page 9: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 9

Structure of the Memory Structure of the Memory SubsystemSubsystem

• Fetch(address)Fetch(address)– Load address into MAR.Load address into MAR.– Decode the address in MAR.Decode the address in MAR.– Copy the content of memory cell with Copy the content of memory cell with

specified address into MDR.specified address into MDR.• Store(address, value)Store(address, value)

– Load the address into MAR.Load the address into MAR.– Load the value into MDR.Load the value into MDR.– Decode the address in MARDecode the address in MAR– Copy the content of MDR into memory Copy the content of MDR into memory

cell with the specified address.cell with the specified address.

MAR MDR

...

Memorydecodercircuit

Fetch/Storecontroller

F/S

Page 10: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 10

Input/Output SubsystemInput/Output Subsystem• Handles devices that allow the computer system to:Handles devices that allow the computer system to:

– Communicate and interact with the outside worldCommunicate and interact with the outside world• Screen, keyboard, printer, ...Screen, keyboard, printer, ...

– Store information (mass-storage) Store information (mass-storage) • Hard-drives, floppies, CD, tapes, …Hard-drives, floppies, CD, tapes, …

• Mass-Storage Device Access Methods:Mass-Storage Device Access Methods:– Direct Access Storage Devices (DASDs)Direct Access Storage Devices (DASDs)

• Hard-drives, floppy-disks, CD-ROMs, ...Hard-drives, floppy-disks, CD-ROMs, ...– Sequential Access Storage Devices (SASDs)Sequential Access Storage Devices (SASDs)

• Tapes (for example, used as backup devices)Tapes (for example, used as backup devices)

Page 11: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 11

I/O ControllersI/O Controllers• Speed of I/O devices is slow compared to RAMSpeed of I/O devices is slow compared to RAM

– RAM ~ 50 nsec.RAM ~ 50 nsec.– Hard-Drive ~ 10msec. = (10,000,000 nsec)Hard-Drive ~ 10msec. = (10,000,000 nsec)

• Solution: Solution: – I/O Controller, a special purpose processor:I/O Controller, a special purpose processor:

• Has a small memory buffer, and a control logic to control I/O Has a small memory buffer, and a control logic to control I/O device (e.g. move disk arm).device (e.g. move disk arm).

• Sends an interrupt signal to CPU when done read/write.Sends an interrupt signal to CPU when done read/write.– Data transferred between RAM and memory buffer.Data transferred between RAM and memory buffer.– Processor free to do something else while I/O controller Processor free to do something else while I/O controller

reads/writes data from/to device into I/O buffer.reads/writes data from/to device into I/O buffer.

Page 12: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 12

I/O controller

Structure of the I/O Structure of the I/O SubsystemSubsystem

I/O Buffer

Control/Logic

I/O device

Data from/to memoryInterrupt signal (to processor)

Page 13: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 13

The ALU SubsystemThe ALU Subsystem• The ALU (Arithmetic/Logic Unit) performsThe ALU (Arithmetic/Logic Unit) performs

– mathematical operations (+, -, x, /, …)mathematical operations (+, -, x, /, …)– logic operations (=, <, >, and, or, not, ...)logic operations (=, <, >, and, or, not, ...)

• In today's computers integrated into the CPUIn today's computers integrated into the CPU• Consists of:Consists of:

– Circuits to do the arithmetic/logic operations. Circuits to do the arithmetic/logic operations. – Registers (fast storage units) to store intermediate Registers (fast storage units) to store intermediate

computational results.computational results.– Bus that connects the two.Bus that connects the two.

Page 14: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 14

Structure of the ALUStructure of the ALU• Registers:Registers:

– Very fast local memory cells, that Very fast local memory cells, that store operands of operations and store operands of operations and intermediate results.intermediate results.

– CCRCCR (condition code register), a (condition code register), a special purpose register that stores special purpose register that stores the result of <, = , > operationsthe result of <, = , > operations

• ALU circuitry:ALU circuitry:– Contains an array of circuits to do Contains an array of circuits to do

mathematical/logic operations.mathematical/logic operations.• Bus:Bus:

– Data path interconnecting the Data path interconnecting the registers to the ALU circuitry.registers to the ALU circuitry.

ALU circuitry

GT EQ LT

R0R1R2

Rn

Page 15: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 15

The Control UnitThe Control Unit• Program is stored in memory Program is stored in memory

– as machine language instructions, in binaryas machine language instructions, in binary• The task of the The task of the control unitcontrol unit is to execute programs is to execute programs

by repeatedly:by repeatedly:– FetchFetch from memory the next instruction to be executed. from memory the next instruction to be executed.– DecodeDecode it, that is, determine what is to be done. it, that is, determine what is to be done.– ExecuteExecute it by issuing the appropriate signals to the it by issuing the appropriate signals to the

ALU, memory, and I/O subsystems.ALU, memory, and I/O subsystems.– Continues until the HALT instructionContinues until the HALT instruction

Page 16: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 16

Machine Language Machine Language InstructionsInstructions

• A machine language instruction consists of:A machine language instruction consists of:– Operation codeOperation code, telling which operation to perform, telling which operation to perform– Address field(s)Address field(s), telling the memory addresses of the , telling the memory addresses of the

values on which the operation works.values on which the operation works.• Example: ADD X, Y Example: ADD X, Y (Add content of memory locations X (Add content of memory locations X

and Y, and store back in memory location Y).and Y, and store back in memory location Y).• Assume: opcode for ADD is 9, and addresses X=99, Y=100Assume: opcode for ADD is 9, and addresses X=99, Y=100

00001001 0000000001100011 0000000001100100Opcode (8 bits)Opcode (8 bits) Address 1 (16 bits)Address 1 (16 bits) Address 2 (16 bits)Address 2 (16 bits)

Page 17: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 17

Instruction Set DesignInstruction Set Design

• Two different approaches:Two different approaches:– Reduced Instruction Set Computers (RISC)Reduced Instruction Set Computers (RISC)

• Instruction set as small and simple as possible.Instruction set as small and simple as possible.• Minimizes amount of circuitry --> faster computersMinimizes amount of circuitry --> faster computers

– Complex Instruction Set Computers (CISC)Complex Instruction Set Computers (CISC)• More instructions, many very complexMore instructions, many very complex• Each instruction can do more work, but require more Each instruction can do more work, but require more

circuitry.circuitry.

Page 18: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 18

Typical Machine Typical Machine InstructionsInstructions

• Notation:Notation:– We use X, Y, Z to denote RAM cellsWe use X, Y, Z to denote RAM cells– Assume only one register R (for simplicity)Assume only one register R (for simplicity)– Use English-like descriptions (should be binary)Use English-like descriptions (should be binary)

• Data Transfer InstructionsData Transfer Instructions– LOAD LOAD X X Load content of memory location X to RLoad content of memory location X to R– STORE XSTORE X Load content of R to memory location XLoad content of R to memory location X– MOVE MOVE X, YX, Y Copy content of memory location X to Copy content of memory location X to

loc. Yloc. Y(not absolutely necessary)(not absolutely necessary)

Page 19: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 19

Machine Instructions Machine Instructions (cont.) (cont.)

• ArithmeticArithmetic– ADD X, Y, ZADD X, Y, Z CON(Z) = CON(X) + CON(Y)CON(Z) = CON(X) + CON(Y)– ADD X, YADD X, Y CON(Y) = CON(X) + CON(Y)CON(Y) = CON(X) + CON(Y)– ADD XADD X R = CON(X) + RR = CON(X) + R– similar instructions for other operators, e.g. SUBTR,OR, ...similar instructions for other operators, e.g. SUBTR,OR, ...

• CompareCompare– COMPARE X, YCOMPARE X, Y

Compare the content of memory cell X to the content of memory Compare the content of memory cell X to the content of memory cell Y and set the condition codes (CCR) accordingly.cell Y and set the condition codes (CCR) accordingly.

– E.g. E.g. If CON(X) = R then set EQ=1, GT=0, LT=0If CON(X) = R then set EQ=1, GT=0, LT=0

Page 20: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 20

Machine Instructions Machine Instructions (cont.)(cont.)

• BranchBranch– JUMP XJUMP X Load next instruction from memory loc. Load next instruction from memory loc.

XX– JUMPGT XJUMPGT X Load next instruction from memory loc. X Load next instruction from memory loc. X

only if GT flag in CCR is set, otherwise only if GT flag in CCR is set, otherwise load load statement from next sequence loc. as statement from next sequence loc. as

usual.usual.• JUMPEQ, JUMPLT, JUMPGE, JUMPLE,JUMPNEQJUMPEQ, JUMPLT, JUMPGE, JUMPLE,JUMPNEQ

• ControlControl– HALTHALT Stop program execution.Stop program execution.

Page 21: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 21

ExampleExample• Pseudo-code: Pseudo-code: Set A to B + CSet A to B + C• Assuming variable:Assuming variable:

– A stored in memory cell 100, B stored in memory cell A stored in memory cell 100, B stored in memory cell 150, C stored in memory cell 151150, C stored in memory cell 151

• Machine language (really in binary)Machine language (really in binary)– LOAD 150LOAD 150– ADDADD 151151– STORE 100STORE 100– oror– (ADD(ADD 150, 151, 100)150, 151, 100)

Page 22: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 22

Structure of the Control Structure of the Control UnitUnit• PC (Program Counter):PC (Program Counter):

– stores the address of next instruction to fetchstores the address of next instruction to fetch• IR (Instruction Register):IR (Instruction Register):

– stores the instruction fetched from memorystores the instruction fetched from memory• Instruction Decoder:Instruction Decoder:

– Decodes instruction and activates necessary circuitryDecodes instruction and activates necessary circuitry

Instruction Decoder

IR

+1

PC

Page 23: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 23

von Neumannvon Neumann

ArchitectureArchitecture

von Neumannvon Neumann

ArchitectureArchitecture

Page 24: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 24

How does this all work How does this all work together?together?

• Program Execution:Program Execution:– PC is set to the address where the first program PC is set to the address where the first program

instruction is stored in memory.instruction is stored in memory.– Repeat until HALT instruction or fatal errorRepeat until HALT instruction or fatal error

Fetch instructionFetch instruction Decode instructionDecode instruction Execute instructionExecute instruction

End of loopEnd of loop

Page 25: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 25

Program Execution (cont.)Program Execution (cont.)

• Fetch phaseFetch phase– PC --> MARPC --> MAR (put address in PC into MAR)(put address in PC into MAR)– Fetch signalFetch signal (signal memory to fetch value into MDR)(signal memory to fetch value into MDR)– MDR --> IRMDR --> IR (move value to Instruction Register)(move value to Instruction Register)– PC + 1 --> PC PC + 1 --> PC (Increase address in program counter)(Increase address in program counter)

• Decode PhaseDecode Phase– IR -> Instruction decoder IR -> Instruction decoder (decode instruction in IR)(decode instruction in IR)– Instruction decoder will then generate the signals to Instruction decoder will then generate the signals to

activate the circuitry to carry out the instructionactivate the circuitry to carry out the instruction

Page 26: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 26

Program Execution (cont.)Program Execution (cont.)

• Execute Phase Execute Phase – Differs from one instruction to the next.Differs from one instruction to the next.

• Example:Example:– LOAD X (load value in addr. X into register)LOAD X (load value in addr. X into register)

• IR_address -> MARIR_address -> MAR• Fetch signalFetch signal• MDR --> RMDR --> R

– ADD X ADD X • left as an exerciseleft as an exercise

Page 27: The Von Neumann Architecture Chapter 5.1-5.2 Von Neumann Architecture

CMPUT101 Introduction to Computing (c) Yngvi Bjornsson 27

Instruction Set for Our Von Instruction Set for Our Von Neumann MachineNeumann Machine

OpcodeOpcode OperationOperation MeaningMeaning0000 LOAD X CON(X) --> R0001 STORE X R --> CON(X)0010 CLEAR X 0 --> CON(X)0011 ADD X R + CON(X) --> R0100 INCREMENT X CON(X) + 1 --> CON(X)0101 SUBTRACT X R - CON(X) --> R0101 DECREMENT X CON(X) - 1 --> CON(X)

0111COMPARE X If CON(X) > R then GT = 1 else 0

If CON(X) = R then EQ = 1 else 0

If CON(X) < R then LT = 1 else 01000 JUMP X Get next instruction from memory location X1001 JUMPGT X Get next instruction from memory loc. X if GT=1... JUMPxx X xx = LT / EQ / NEQ1101 IN X Input an integer value and store in X1110 OUT X Output, in decimal notation, content of mem. loc. X1111 HALT Stop program execution