Chap 2
Chap 2
Chapter 2
Main Components of Computer
2024-2025
PLAN
1. Arithmetic Logic Unit (ALU - UAL)
2. Buses
3. Registers
6. Memory hierarchy
Arithmetic Logic Unit (ALU - UAL)
The ALU is the only component in the computer responsible for
performing all instructions.
INSTRUCTION
Arithmetic Logic
(+, -, %, *…) (AND, OR, XOR, …)
Examples
Instruction1: A + B, (A,B): Operands, +: Binary Operator
Instruction2: NOT A, A: Operand, NOT: Unary Operator
Arithmetic Logic Unit (ALU)
1. UAL is composed of several combinational logic circuits
2. It has 2 inputs (on N bits) as operands, and one output as result
3. It also has a command input allowing to choose the operation to
be done (Multiplexer)
4. A table of codes of operations for the command input
associated with the UAL
5. Has Flags (flags) PSW = Program Status Word
Arithmetic Logic Unit (ALU)
C (Command Input)
A (Op1)
UAL S (Res)
B (Op2)
PSW (Flags)
Arithmetic Logic Unit (ALU)
C.C.ADD
A
C.C.SOUS
C.C.AND
B C.C.CMP
C.C.XOR
Arithmetic Logic Unit (ALU)
Half-Adder
It is a circuit that adds two binary numbers on one bit each and returns two outputs.
S: result of the addition
R: carry out of the addition
= ⊕
𝐴 0 𝐵 0𝑆 0 𝑅 0 =
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Arithmetic Logic Unit (ALU)
Full Adder
It is a circuit that adds two numbers on N bits and returns two outputs.
S: result of the addition
R: carry out of the addition
= ⊕
N bits
=( ) +
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
Arithmetic Logic Unit (ALU)
Full Adder – 4 bits
Arithmetic Logic Unit (ALU)
Full Adder – 4 bits
C.C.ADD
A
C.C.SOUS
C.C.AND MUX
B S
C.C.CMP
C.C.XOR
Arithmetic Logic Unit (ALU)
Table of codes & line commande C
S
C=011
0 0 0 Add
0 0 1 Sous
0 1 0 Multip
MUX
0 1 1 Div S=Div
1 0 0 Shift Right
1 0 1 Shift Left
1 1 0 (A or B) xor A
1 1 1 Not
Arithmetic Logic Unit (ALU)
𝑪𝟏𝑪𝟎
Multiplexer (4 vers 1)
S 𝑬𝟎
𝑬𝟏
0 0 MUX S
𝑬𝟐 4 vers 1
0 1 𝑬𝟑
1 0
S=
1 1
Arithmetic Logic Unit (ALU)
Multiplexer (4 vers 1)
S=
Arithmetic Logic Unit (ALU)
C
C.C.ADD
A
C.C.SOUS
C.C.AND
B MUX S
C.C.CMP
C.C.XOR
PSW (Flags) ZF SF CF OF …
Arithmetic Logic Unit (ALU)
N-bits C.C.OP1
A
C.C.OP2
N-bits
N-bits C.C.OP3
B MUX S
C.C.OP4
C.C.OPi !
i r
te n
Z S C O … Re
A
Arithmetic Logic Unit (ALU)
The Buses
A communication bus is a set of wires
1
0
1
1 10110100
0
1 8 fils bus 8-bits
0
0
The Buses
Depending on the nature of the information to be transported, there are three
types of information bus
Data bus
Address bus
Command (or control) bus
The Buses
The Buses
Address bus (addressing or memory bus): this is a unidirectional bus, it
allows to transport the addresses generated by the CPU for addressing the
Main Memory.
Size of B.A = n-bits Main memory size = bytes / byte = octet = 8 bits
NB: Size of data stored in main memory being the byte, or a multiple of bytes
IN AL, port_clavier 1 0 0
OUT port_ecran, BL 0 0 0
Mov X, AL 0 1 0
The registers
When the processor executes the instructions in progress, the data is
temporarily stored in small fast memories (8, 16, 32 or 64 bits) called
REGISTERS. Depending on the type of processor, the total number of
registers can vary from a dozen to several hundred (Ex: Intel-32bits contains
16 registers).
They can be of the address type (they then contain an address of the memory
word) or data (they then contain the content of a memory word). They can be
specific and have a very precise function (for example the “ordinal counter”
register) or general and serve mainly for intermediate calculations (for
example the “AX” accumulator register)
The registers
15 0
AX Accumulator Register
BX Base Register
CX Counter Register
DX Data Register
SP Stack Pointer
BP Base Pointer
DI Destination Index
SI Source Index
General register
Specific register
The registers
7 07 0
AH AL
BH BL H : High
CH CL
L : Low
DH DL
SP
BP
DI
SI
The registers
15 0
X X X X OF DF IF TF SF ZF X AF X PF X CF PSW
X X X X OF DF IF TF SF ZF X AF X PF X CF PSW
4 Segment Registers
DS (Data Segment) : contains DATA segment address, points to the data memory area
Main Secondary
Memory Memory
The central
RAM ROM
memory is RAM-
Volatil dominated Non volatil
Read/Write Read Only
Temporarily stores information Stores immutable information
in use on the computer (Ex:Bios)
Internal Memories
RAM (Random Access Memory)
Cell Address 0
0 0 0 1 1 1 1 0
Cell
Cell
Word memory = Number of bits
(8 bits) .
.
.
.
Size = Nb_cells × Word memory (en .
octets
Cell Address N-3
Nb_cell = 16, Word_Mem = 8 bits
Size_Mem = 16 × 8 bits (1 octet) Cell Address N-2
= 16 octets Cell Address N-1
Internal Memories
Communication between CPU & RAM
Cell
Cell
.
CPU .
.
Data .
10100110 b us : 1
010 0
110 .
10100110 Adresse 2
Cell Adresse 1
Cell
Cell
.
CPU Data bus : 00001111 .
.
.
00001111 .
Cell Adresse 2
00001111 Adresse 1
Cell 0000
Cell
Cell
If the address is on n-bits, then it is .
possible to reference memory cells (In .
the example it is 16 memory cells or
.
words)
.
.
Cell 1101
Cell 1110
Cell 1111
Internal Memories
Memory Segmentation
Segmentation is the subdivision
(logical, not physical) of RAM @Segment
into multiple equal-sized areas. 0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
It is done by cutting the bits of 0 1 0 0
the address bus 0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
Internal Memories
Memory Segmentation
@Segment @Offset
0 0 0 0
Ecriture Segment 11 0 0 0 1
Segment:Offset 0 0 1 0
0 0 1 1
0 1 0 0
00:01 Segment 10 0 1 0 1
0 1 1 0
0 1 1 1
01:01 1 0 0 0
Segment 01 1 0 0 1
1 0 1 0
11:10 1 0 1 1
1 1 0 0
1 1 0 1
Segment 00 1 1 1 0
1 1 1 1
Internal Memories
The Stack
The stack is a structure of central
memory
Uses the principle of LIFO (Last In
First Out) 0000
SP is a register that points to the top 0001
0010
of the stack 0011
Manipulated by PUSH and POP 0100
instructions 0101
0110
Saves return addresses when calling 0111
procedures 1000
SS=10 1001
1010 SP
xxxxx 1011
1100
1101
1110
1111
Internal Memories
The stack
10: offset1: Ins 1
10: offset2: Ins 2
10: offset3: CALL PROC
10: offset4: Ins 4
PROC 0000
10:offset: Inst 1 0001
10:offset: Inst 2 0010
RET
0011
0100
CS=10 0101
0110
0111
1000
SS=01 1001
1010 SP
xxxxx 1011
Procedure Near 1100
1. CALL : Empiler @_Retour (Sp=Sp-2) 1101
2. RET: Sp=Sp+2 1110
1111
Dépiler sommet vers Reg Ip
Internal Memories
10: offset1: Ins 1
The Stack
10: offset2: Ins 2
10: offset3: CALL PROC
10: offset4: Ins 4
0000
PROC 0001
00: offset1: Ins 1 0010
00: offset2: Ins 2 0011
RET 0100
CS=10 0101
0110
Procedure Far 0111
1. CALL : Empiler CS_Retour 1000
2. Sp=Sp-2 SS=01 1001
1010 SP
3. Empiler Ip_Retour xxxxx 1011
4. Sp=Sp-2 1100
5. RET: CS=00 1101
1110
Dépiler sommet vers Ip 1111
Dépiler CS
Internal Memories
RAM
SRAM DRAM
It does not need it needs to be
to be updated Random Access updated (55ms)
Read/Write Larger size
Small size
Consumes Consumes
less energy more energy
lot of money. Abordable
Internal Memories
Internal Memories
CENTRAL SECONDAR
1 jour MEMORY Y MEMORY
Cache Memory
INPUT OUTPUT
UNITS UNITS
CPU
2 1 1 4
Succès de cache Cache Memory Echec de cache
(Hit) (SRAM) (Miss)
2 3
CENTRAL
SECONDAR
MEMORY
Y MEMORY
Cache Memory
Principle of locality
The locality principle states that the information that the
processor will access has a high probability of being located
in a spatial window and a temporal window.
J Block M
Block M
(K mots)
@
Size of cell
(Ex : 1 octets)
Cache Memory
Mapping function
s+w
Tag Line Mot
s-r r w
Taille adresse mémoire = s+w
Partie Mot = w
Partie Line = r
Partie Tag = s-r
Cache Memory
Mapping function
Cache memory access (direct cache case)
s+w
Tag Line Mot
s-r r w
Nombre mots mémoire (Taille mémoire centrale ‘’MC’’) =
Nombre mots par block (Taille block, Taille line)=
Nombre blocks dans MC = =
Nombre de lines dans cache =
Taille mémoire cache =
Taille tag =
Cache Memory
Mapping function
Cache memory access (direct cache case)
Mémoire
Adresse
Centrale
W1
Tag Line W Mémoire Cache W2
Tag W1 W3
B1
W2 W4
L1
W3
W4
CMP ×
Tag W6
W7
L3 W10
W8
× W9 W11
B5
Hi W12
t W13
Miss
Instant t (Etat Init: L0 contient B2) (Inconvénient direct cache)
accès W1
Instant t+1
accès W7
C W1 W2 W3 B0 C W1 W2 W3 B0
L0 B2 L0 B0
P L1
W4 W5 W6 B1 P W4 W5 W6 B1
L1
U W7 W8 W9 B2 U W7 W8 W9 B2
C W1 W2 W3 B0 C W1 W2 W3 B0
L0 B2 L0 B0
P L1
W4 W5 W6 B1 P L1
W4 W5 W6 B1
U W7 W8 W9 B2 U W7 W8 W9 B2
Cache Memory
Mapping functions
s+w
Tag W
s w
Nombre de mots mémoire (On dit mots mémoire ou taille MC) =
Nombre mots par block (Taille block, Taille line)= (car taille bloc=taille line)
Nombre blocks dans MC = = (NB_Bloc= taille totale MC/taille d’un bloc)
Nombre de lines dans cache = Indéterminé
Taille tag =
Cache Memory
Mapping function
L’accès à la mémoire cache (Cas cache totalement associatif )
Mémoire
Adresse
Centrale
W1
Tag W Mémoire Cache W2
Tag W3
B1
L1 W4
CMP ×
Tag
L3 W10
W11
Hi × B5
W12
t W13
Miss
Cache Memory
Mapping functions
Correspondance associative par ensemble (set associative cache) :
separation of the cache memory into groups of blocks and complete
associativity within a group, i.e. block m of the main memory can be found in
any block of the group g = m % v of the cache memory, knowing that v is the
total number of groups of blocks in the cache memory
Nombre de lines dans ensemble = k (k-way: selon les archis actuelles k=2 ou 4)
Nombre d’ensembles = V =
Nombre de lines dans cache = k * V = k * (nb lignes par groupes * nb total groupe)
Taille cache = k* mots (nb lines total * taille une line)
Taille Tag = s – d
Cache Memory
Mapping function
L’accès à la mémoire cache (Cas cache associatif par ensemble)
Mémoire
Adresse
Centrale
W1
Tag v W Mémoire Cache W2
Tag W3
B1
Tag W4
g1
Tag
Tag
CMP ×
Tag
Tag
g3 W10
Tag
Tag W11
Hi × B5
W12
t W13
Miss
Cache Memory
Cache Memories
Levels
Registers
(CPU)
Le cache L1
Response (on chip) Cost
Time Les caches L2 & L3
(off chip)
Secondary Memory
Size