You are on page 1of 81

Horia Cucu

Speech & Dialogue Research Laboratory


Faculty of Electronics, Telecommunications and Information Technology
University POLITEHNICA of Bucharest

2.1 Von Neumann Architecture Reminder and Example

Block Diagram of a Microcomputer

The CPU: executes instructions (processes data) and controls the system
The Memory: stores both the data and the instructions
The I/O Devices: interconnect the microcomputer with the outside world

03.03.2016

Microprocessors Architecture

Instruction Execution Example

Reset
Execute
instructions from
address 100h

The CPU is reset and starts executing instructions from a

predefined address in the memory (100h)

03.03.2016

Microprocessors Architecture

Instruction Execution Example

100h

MEM-READ

The CPU sends the address of this first instruction (100h)

through the Address Bus


The CPU sends a MEM-READ signal through the Control Bus
03.03.2016

Microprocessors Architecture

Instruction Execution Example

100h

MEM-READ

The Memory receives the MEM-READ signal and reads the

address from the Address Bus

03.03.2016

Microprocessors Architecture

Instruction Execution Example

The Memory finds the instruction (instruction #1) in the

memory location(s) with the corresponding address (100h)

03.03.2016

Microprocessors Architecture

Instruction Execution Example

instruction #1

ACK

The Memory sends the instruction through the Data Bus and

sends an ACK signal through the Control Bus

03.03.2016

Microprocessors Architecture

Instruction Execution Example

instruction #1

ACK

The CPU receives the ACK signal and reads the instruction

from the Data Bus

03.03.2016

Microprocessors Architecture

10

Instruction Execution Example

Decode
instruction

The CPU decodes the instruction to "understand" what it has

to do next
Let's suppose that it has to add the value 50h to the value
stored in the memory location with the address 2000h
03.03.2016

Microprocessors Architecture

11

Instruction Execution Example

2000h

MEM-READ

The CPU sends the address (2000h) on the Address Bus and

sends a MEM-READ signal through the Control Bus

03.03.2016

Microprocessors Architecture

12

Instruction Execution Example

2000h

MEM-READ

The Memory receives the MEM-READ signal and reads the

address from the Address Bus

03.03.2016

Microprocessors Architecture

13

Instruction Execution Example

The Memory finds the data (85h) in the memory location

with the corresponding address (2000h)

03.03.2016

Microprocessors Architecture

14

Instruction Execution Example

85h

ACK

The Memory sends the data (85h) through the Data Bus and

sends an ACK signal through the Control Bus

03.03.2016

Microprocessors Architecture

15

Instruction Execution Example

85h

ACK

The CPU receives the ACK signal and reads the data from the

Data Bus

03.03.2016

Microprocessors Architecture

16

Instruction Execution Example

The CPU temporarily stores the data in a register

03.03.2016

Microprocessors Architecture

17

Instruction Execution Example

The CPU adds the value 50h to the register (the result will be

D5h)

03.03.2016

Microprocessors Architecture

18

Instruction Execution Example

D5h

2000h

MEM-WRITE

The CPU sends


the result (D5h) through the Data Bus,
the address (2000h) through the Address Bus and

a MEM-WRITE signal through the Control Bus


03.03.2016

Microprocessors Architecture

19

Instruction Execution Example

D5h

2000h

MEM-WRITE

The Memory
receives the MEM-WRITE signal,
reads the address (2000h) from the Address Bus,
reads the result (D5h) from the Data Bus and
stores the result into the corresponding memory location
03.03.2016

Microprocessors Architecture

20

Instruction Execution Example

The CPU continues by executing the next instruction

03.03.2016

Microprocessors Architecture

21

2.2 The Set of General Purpose Registers

CPU Registers
Register a small amount of storage inside the CPU
Implemented as a set of N synchronized bistables
Stores N bits of data
Highest access speed among all storage options
Several types of registers:
General vs. special purpose (dedicated) registers
Physical vs. logical registers
User-accessible vs. non user-accessible registers

03.03.2016

Microprocessors Architecture

23

General Purpose Registers


General purpose registers (GPRs)
Set of equally-sized registers used to store temporary data
(operands/results) needed in the execution of the program
User-accessible (architectural attributes)
Implemented as physical or logical registers
May have implicit functions
The size of the GPRs performance criterion
Equal to the size of the Internal Data Bus
The number of GPRs performance criterion
A larger number of GPRs => faster, more compact programs,
ease of programming,
03.03.2016

Microprocessors Architecture

24

General Purpose Registers

MUX (multiplexer) outputs one of the data inputs

(depending on the address inputs)


Internal Data Bus extension of the External Data Bus
inside the CPU
03.03.2016

Microprocessors Architecture

25

Special Purpose Registers


Special purpose registers
Dedicated registers that can be used only for specific purposes
Size depends on the particular role of the register
Some are user-accessible (architectural attributes), some not
Examples:
Data register (DR) and Address register (AR)
Accumulator (A)
Status (Flags) register (F)
Instruction Pointer (IP)
Stack Pointer (SP)
03.03.2016

Microprocessors Architecture

26

2.3 The interface between the CPU and the System Bus

The Data Register


and the Address Register

DR (data register): the CPU Data Bus interface


The data in DR are available to all the hardware blocks

connected on the Data Bus


The size of DR is the size of the Data Bus
DR is not an architectural attribute
03.03.2016

Microprocessors Architecture

28

The Data Register


and the Address Register

AR (address register): the CPU Address Bus interface


The address in AR is available to all the hardware blocks

connected on the Address Bus; only the CPU writes in AR


The size of AR is the size of the Address Bus
AR is not an architectural attribute
03.03.2016

Microprocessors Architecture

29

2.4 The Arithmetic and Logic Unit (ALU)

The Arithmetic and Logic Unit


The Arithmetic and Logic Unit (ALU)
digital circuit that performs

integer arithmetic operations: add, subtract, increment, etc.


logical operations: and, or, xor, not, clear, shift, rotate, etc.

The inputs of the ALU


Data to be processed (one or two integer numbers)
The operation to be performed (specified by the Control Unit)
Possibly some status flags
The outputs of the ALU
The operation result(s) are placed in the Accumulator or on the
Internal Data Bus
The status flags are updated after each operation
03.03.2016

Microprocessors Architecture

31

The Arithmetic and Logic Unit

03.03.2016

Microprocessors Architecture

32

The Status Register


The Status Register (also called Flags Register)
A collection of flag bits, which store information regarding
the state of the processor
Arithmetic and logic flags
Bits encoding the status of the previous arithmetic/logic
operation
Used and updated by the ALU
Other types of flags
Interrupt enable flag
Supervisor flag
Direction flag
03.03.2016

Microprocessors Architecture

33

Typical Arithmetic and Logic Flags


Carry flag (CF): signals an arithmetic carry or borrow for

unsigned numbers
Parity flag (PF): signals that the number of ones in the least

significant byte of the result is even


Zero flag (ZF): signals that the result is 0
Sign flag (SF): signals that the most significant bit of the N-bit

result is set (the sign bit in twos complement representation)


Overflow flag (OF): signals an arithmetic overflow for signed

numbers
03.03.2016

Microprocessors Architecture

34

The Accumulator and the Shift Register


The Accumulator special purpose register
Stores one of the operands before the operation
Stores the result of the operation
Size equal to the size of the general purpose registers
Is user-accessible (architecture attribute)
The Shift Register special purpose register
Used by the ALU to make shift and rotation operations
Size double than the size of the general purpose registers
Is not user-accessible

03.03.2016

Microprocessors Architecture

35

2.5 The Memory Addressing Control Unit (MACU)

The Memory Addressing Control Unit


The Memory Addressing Control Unit
Hardware block that computes the physical address needed to
identify information in the Memory or I/O Ports
Receives input from the Internal Data Bus
Places its output (a physical address) in the Address Register
Functionality classification
Instruction addressing (in the program memory)

Sequentially, instruction after instruction


Non-sequentially, through jumps

Data addressing (in the data memory)

03.03.2016

Elementary data addressing


Stack addressing
Data arrays addressing

Microprocessors Architecture

37

The Memory Addressing Control Unit

03.03.2016

Microprocessors Architecture

38

Memory Management Techniques


Linear Memory Organization
The memory is regarded as a single block of memory locations
The memory is addressed using directly a physical address
Memory Segmentation
The memory is logically divided into segments (non equal-sized,
possibly overlapping sections)
The memory is addressed using a segment address and an offset
Memory Paging
The memory is logically divided into pages (equal sized, nonoverlapping, strictly concatenated sections)
The memory is addressed using a page address and an offset
03.03.2016

Microprocessors Architecture

39

Sequential Instructions Addressing


Sequential Instructions Addressing
The main principle of the von Neumann architecture
Achieved through the means of a counter register
The Program Counter (PC) special purpose register
Stores the physical address of the current instruction
Incremented after the execution of each instruction
Size equal to the size of a physical address
In some architectures is user-accessible

Other hardware blocks involved: MUX2 and MUX5


03.03.2016

Microprocessors Architecture

40

Sequential Instructions Addressing

The program is executed instruction after instruction


The Instruction Register stores the instruction before

decoding
03.03.2016

Microprocessors Architecture

41

The Memory Addressing Control Unit

03.03.2016

Microprocessors Architecture

42

Non-Sequential Instructions Addressing


Exceptions to the normal, sequential execution of a program:

jumps, loops or subprogram calls


The jump address can be:
An absolute address: a complete physical address

The address is provided by another hardware block through the


Internal Data Bus

An offset relative to the address of the current instruction

The offset provided by another hardware block through the Internal


Data Bus is added to the address in PC

The Program Counter is also updated


Other hardware blocks involved: MUX2, MUX4, MUX5, Adder
03.03.2016

Microprocessors Architecture

43

Elementary Data Addressing


The data can potentially reside anywhere in the memory
The address required to identify the data can be:
An absolute address: a complete physical address

The address is provided by another hardware block through the


Internal Data Bus

An offset relative to the address of the current instruction

The offset provided by another hardware block through the


Internal Data Bus is added to the address in PC

Other hardware blocks involved: MUX4, MUX5, Adder


03.03.2016

Microprocessors Architecture

44

Stack Addressing
The Stack: LIFO data structure
Accessed through the means of a pointer register
Pushing an element in the Stack -> decrementing the pointer
Popping an element out of the Stack -> incrementing the pointer
Software vs. hardware Stack
The Stack Pointer (SP ) special purpose register
Stores the physical address of the top element
Size equal to the size of a physical address
User-accessible (architecture attribute)

Other hardware blocks involved: MUX3 and MUX5


03.03.2016

Microprocessors Architecture

45

Stack Addressing

03.03.2016

Microprocessors Architecture

46

Data Arrays Addressing


The Memory can accommodate arrays of data
Accessed through the means of index registers, which store the
physical address of the first element in the array
The address of a random element is obtained by adding a relative
offset to the index register

Offset size => max number of elements in the array

The Index Registers (IX) special purpose registers


Store the physical addresses of various data arrays
Size equal to the size of a physical address
User-accessible (architecture attribute)
Other hardware blocks involved: MUX1, MUX4, MUX5, Adder
03.03.2016

Microprocessors Architecture

47

The Memory Addressing Control Unit

03.03.2016

Microprocessors Architecture

48

2.6 The Timing and Control Unit

The Timing and Control Unit


The Timing and Control Unit (TCU)
Hardware block inside the CPU that:

fetches, decodes and manages the execution of instructions


controls the flow of data through the processor
coordinates the activities of the other hardware blocks within the
CPU and also outside the CPU
achieves the above through timing and control signals

Design: hardwired vs. micro-programmed

The inputs to the TCU


The instruction in the Instruction Register (IR)
Internal control signals (the status flags)
The outputs of the TCU
Internal control signals (for the blocks within the CPU)
External control signals (for the blocks outside the CPU)
03.03.2016

Microprocessors Architecture

50

The Timing and Control Unit

03.03.2016

Microprocessors Architecture

51

The Instruction Register and


the Instruction Decoder
The Instruction Register (IR) special purpose register
Stores the instruction code fetched from the memory
Receives input only from the Data Register
Size equal to the smallest instruction code
Is not user-accessible (not an architecture attribute)
The Instruction Decoder
Hardware block that decodes instruction codes

Each code has an associated, unique output line


Only one of the output lines will be 1 at any moment in time

Receives input from the Instruction Register

Sends its output to the Timing and Control Unit


03.03.2016

Microprocessors Architecture

52

The Typical CISC Instruction Format


The instructions are stored in the memory in one or several

memory locations (depending on the type of instruction)


Instruction format all the information required by the CPU to

execute an instruction
Comprises at least one byte: the instruction code (the semantic)
The instruction code may require additional bytes
May comprise operands, addresses, offsets on one or several bytes
1-6 bytes for 16-bit x86 microprocessors
1-15 bytes for 32-bit x86 microprocessors
Example:

03.03.2016

code

[code]

[data or
address]

[data or
address]

Microprocessors Architecture

[data or
address]

53

Instruction Execution Timing


Typically, the execution of an instruction has several stages:
Fetch the instruction code is read from the memory
Decode the instruction code is decoded
Execute the instruction is executed (might comprise operands fetch)
Write the result is written in a register or a memory location
The instruction execution stages are called machine cycles
Any instruction is executed in one or several machine cycles (depending on
its complexity)
In a machine cycle the CPU executes sequentially several elementary
actions accomplishing a clear, well-defined task
Elementary actions are executed once every clock cycle
An internal clock signal is generated based on an external quartz oscillator
A CPU state is a physical time period equal to the duration of a clock cycle
In a state, the CPU executes one elementary action or two independent
elementary actions (in the same time)
03.03.2016

Microprocessors Architecture

54

Instruction Execution Timing Example


Instruction example: (2000h) <- (2000h) + 50h

Instruction format:

code

addrlow
(00h)

6 machine cycles:
M1. Fetch and Decode
M2. Read address (least significant byte)
M3. Read address (most significant byte)
M4. Read operand 1
M5. Read operand 2 and Execute
M6. Write result

03.03.2016

Microprocessors Architecture

addrhigh
(20h)

data
(50h)

55

Machine Cycle 1: Fetch


Instruction example: (2000h) <- (2000h) + 50h
Instruction format:
addrlow
addrhigh

code
(00h)
(20h)
6 machine cycles:
M1. Fetch and Decode

data
(50h)

T1. (AR) <- (PC), MEM-READ


T2. (PC) <- (PC) + 1, (DR) <- ((AR))
T3. (IR) <- (DR)
T4. decode instruction code

M2. Read address (least significant byte)


M3. Read address (most significant byte)
M4. Read operand 1
M5. Read operand 2 and Execute
M6. Write result
03.03.2016

Microprocessors Architecture

56

Machine Cycle 1: Fetch

T1. (AR) <- (PC), MEM-READ

03.03.2016

Microprocessors Architecture

57

Machine Cycle 1: Fetch

T2. (PC) <- (PC) + 1, (DR) <- ((AR))

03.03.2016

Microprocessors Architecture

58

Machine Cycle 1: Fetch

T3. (IR) <- (DR)

03.03.2016

Microprocessors Architecture

59

Machine Cycle 1: Fetch

T4. decode instruction code

03.03.2016

Microprocessors Architecture

60

Machine Cycle 2: Read Address


Instruction example: (2000h) <- (2000h) + 50h

Instruction format:

code

addrlow
(00h)

6 machine cycles:
M1. Fetch and Decode
M2. Read address (least significant byte)

addrhigh
(20h)

data
(50h)

T1. (AR) <- (PC), MEM-READ


T2. (PC) <- (PC) + 1, (DR) <- ((AR))
T3. (AUX2) <- (DR)

M3. Read address (most significant byte)


M4. Read operand 1
M5. Read operand 2 and Execute

M6. Write result


03.03.2016

Microprocessors Architecture

61

Machine Cycle 2: Read Address

T1. (AR) <- (PC), MEM-READ

03.03.2016

Microprocessors Architecture

62

Machine Cycle 2: Read Address

T2. (PC) <- (PC) + 1, (DR) <- ((AR))

03.03.2016

Microprocessors Architecture

63

Machine Cycle 2: Read Address

T3. (AUX2) <- (DR)

03.03.2016

Microprocessors Architecture

64

Machine Cycle 3: Read Address


Instruction example: (2000h) <- (2000h) + 50h

Instruction format:

code

addrlow
(00h)

6 machine cycles:
M1. Fetch and Decode
M2. Read address (least significant byte)
M3. Read address (most significant byte)

addrhigh
(20h)

data
(50h)

T1. (AR) <- (PC), MEM-READ


T2. (PC) <- (PC) + 1, (DR) <- ((AR))
T3. (AUX1) <- (DR)

M4. Read operand 1


M5. Read operand 2 and Execute

M6. Write result


03.03.2016

Microprocessors Architecture

65

Machine Cycle 3: Read Address

T1. (AR) <- (PC), MEM-READ

03.03.2016

Microprocessors Architecture

66

Machine Cycle 3: Read Address

T2. (PC) <- (PC) + 1, (DR) <- ((AR))

03.03.2016

Microprocessors Architecture

67

Machine Cycle 3: Read Address

T3. (AUX1) <- (DR)

03.03.2016

Microprocessors Architecture

68

Machine Cycle 4: Read Operand 1


Instruction example: (2000h) <- (2000h) + 50h

Instruction format:

code

addrlow
(00h)

6 machine cycles:
M1. Fetch and Decode
M2. Read address (least significant byte)
M3. Read address (most significant byte)
M4. Read operand 1

addrhigh
(20h)

data
(50h)

T1. (AR) <- (PC), MEM-READ


T2. (PC) <- (PC) + 1, (DR) <- ((AR))
T3. (A) <- (DR)

M5. Read operand 2 and Execute

M6. Write result


03.03.2016

Microprocessors Architecture

69

Machine Cycle 4: Read Operand 1

T1. (AR) <- (PC), MEM-READ

03.03.2016

Microprocessors Architecture

70

Machine Cycle 4: Read Operand 1

T2. (PC) <- (PC) + 1, (DR) <- ((AR))

03.03.2016

Microprocessors Architecture

71

Machine Cycle 4: Read Operand 1

T3. (A) <- (DR)

03.03.2016

Microprocessors Architecture

72

Machine cycle 5: Read operand 2 and Execute


Instruction example: (2000h) <- (2000h) + 50h

Instruction format:

code

addrlow
(00h)

6 machine cycles:
M1. Fetch and Decode
M2. Read address (least significant byte)
M3. Read address (most significant byte)
M4. Read operand 1
M5. Read operand 2 and Execute

addrhigh
(20h)

data
(50h)

T1. (AR) <- (AUX1, AUX2), MEM-READ


T2. (DR) <- ((AR))
T3. (A) <- (A) + (DR)

M6. Write result


03.03.2016

Microprocessors Architecture

73

Machine cycle 5: Read operand 2 and Execute

T1. (AR) <- (AUX1, AUX2), MEM-READ

03.03.2016

Microprocessors Architecture

74

Machine cycle 5: Read operand 2 and Execute

T2. (DR) <- ((AR))

03.03.2016

Microprocessors Architecture

75

Machine cycle 5: Read operand 2 and Execute

T3. (A) <- (A) + (DR)

03.03.2016

Microprocessors Architecture

76

Machine Cycle 6: Write Result


Instruction example: (2000h) <- (2000h) + 50h

Instruction format:

code

addrlow
(00h)

6 machine cycles:
M1. Fetch and Decode
M2. Read address (least significant byte)
M3. Read address (most significant byte)
M4. Read operand 1
M5. Read operand 2 and Execute
M6. Write result

03.03.2016

addrhigh
(20h)

data
(50h)

T1. (DR) <- (A)


T2. (AR) <- (AUX1, AUX2), MEM-WRITE

Microprocessors Architecture

77

Machine Cycle 6: Write Result

T1. (DR) <- (A)

03.03.2016

Microprocessors Architecture

78

Machine Cycle 6: Write Result

T2. (AR) <- (AUX1, AUX2), MEM-WRITE

03.03.2016

Microprocessors Architecture

79

2.7 Summary

Summary

General Purpose Registers (GPRs)


Memory Data Register (DR)
Memory Address Register (AR)
03.03.2016

Arithmetic and Logic Unit (ALU)


Memory Addressing Control Unit
Timing and Control Unit (TCU)

Microprocessors Architecture

81

You might also like