Connaître et comprendreConnaître et comprendre … · 110011(2) / 1010(2) = 101(2) reste 1(2) (1)...

Post on 25-Sep-2018

216 views 0 download

Transcript of Connaître et comprendreConnaître et comprendre … · 110011(2) / 1010(2) = 101(2) reste 1(2) (1)...

Circuits LogiquesELE1300

Représentation des nombreset opérations

JP D idJP David

Objectifsj

• Connaître et comprendreConnaître et comprendreLa représentation d’un nombre dans une base quelconque et en particulier dans les formatsquelconque et en particulier dans les formats binaires.

• Être capable deÊtre capable deConvertir un nombre d’une base à une autreRéaliser des opérations sur les nombresRéaliser des opérations sur les nombres

• Addition – soustraction – multiplication – division

29 octobre 2010 Circuits logiques - JP David 2

Forme générale d’un nombreg

[ ] ( )1 2 1 0 1 2 , n n m ba a a a a a a− − − − −L L

partie entièren chiffres

partie fractionnairem chiffres

basen chiffres m chiffres

29 octobre 2010 Circuits logiques - JP David 3

Forme générale d’un nombre

[ ]

g(suite)

[ ] ( )1 2 1 0 1 2 , n n m ba a a a a a a− − − − −L L

1 2 1 0 1 2 n n mb b b b b b b− − − − −L L

1 21 2 1 0 n n

n na b a b a b a− −× + × + + × +L

Valeur :

1 2 1 0n n− −

-1 -2 --1 -2 - m

ma b a b a b+ × + × + + ×L

29 octobre 2010 Circuits logiques - JP David 4

Exemple 1p

51 = 1.25 + 1.24 + 0.23 + 0.22 + 1.21 + 1.2051 1.2 1.2 0.2 0.2 1.2 1.2= 32 + 16 + 0 + 0 +2 + 1

51 = (((((1).2+1).2+0).2+0).2+1).2+1

32 16 8 4 2 1

1 1 0 0 1 1

29 octobre 2010 Circuits logiques - JP David 5

Exemple 2p

64 32 16 8 4 2 1 1/2

1/4

1/8

1/16

1/32

1/64

Base10

0 1 1 0 0 1 1 0 0 0 0 0 0 510 0 0 0 1 0 1 0 0 1 0 0 0 5 1250 0 0 0 1 0 1 0 0 1 0 0 0 5,1250 0 0 0 0 0 0 0 1 0 1 0 1 1/3

29 octobre 2010 Circuits logiques - JP David 6

Quelques bases usitées

SYSTÈME BASE CHIFFRES

q

SYSTÈME BASE CHIFFRES

BINAIRE

OCTAL

2

8 { }0,1,2,3,4,5,6,7ia ∈

{ }0,1ia ∈

DÉCIMAL

HEXADÉCIMAL

10

16

{ }0,1,2,3, 4,5,6,7,8,9ia ∈

{ }0,1,2,3, 4,5,6,7,8,9, A,B,C,D, E,Fia ∈

Exemples :

( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )3 2 1 0 1 2 3

2 2 2 2 2 2 2 2 2 2 2 2 2 2 21011,101 1 10 0 10 1 10 1 10 1 10 0 10 1 10− − −= × + × + × + × + × + × + ×

1 0 1 2

( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )2 1 0 1

10 10 10 10 10 10 10 10 10243,6 2 10 4 10 3 10 6 10−= × + × + × + ×

2 1 0 112A 4 1 10 2 10 A 10 4 10−+ + +

( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )1 0 1 2

8 8 8 8 8 8 8 8 845,36 4 10 5 10 3 10 6 10− −= × + × + × + ×

29 octobre 2010 Circuits logiques - JP David 7

( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )2 1 0 1

16 16 16 16 16 16 16 16 1612A, 4 1 10 2 10 A 10 4 10= × + × + × + ×

Quelques bases usitées (suite)

BINAIRE OCTAL HEXADÉCIMALDÉCIMAL

q ( )

BINAIRE

0000000100100011

OCTAL

0123

HEXADÉCIMAL

0123

DÉCIMAL

01230011

01000101011001111000

3456710

345678

3456781000

1001101010111100

1011121314

89ABC

89101112

110111101111

10000

15161720

DEF10

13141516

29 octobre 2010 Circuits logiques - JP David 8

Conversion par multiplicationp p

• Exemples :Exemples :110011(2) = (((((1)x2+1)x2)x2)x2+1)x2+1

= 51= 5151 = (5) x 10 + 1

= 101(2) x 1010(2) + 1 = 110011(2) 101(2) x 1010(2) + 1 110011(2)

29 octobre 2010 Circuits logiques - JP David 9

Conversion par divisionp

• Exemples :Exemples :51 / 2 = 25 reste 1 (LSB)25 / 2 = 12 reste 112 / 2 = 6 reste 06 / 2 = 3 reste 03 / 2 = 1 reste 13 / 2 = 1 reste 11 / 2 = 0 reste 1 (MSB)

110011(2) / 1010(2) = 101(2) reste 1(2) (1)

101(2) / 1010(2) = 0(2) reste 101(2) (5)

29 octobre 2010 Circuits logiques - JP David 10

(2) (2) (2) (2) ( )

Binaire, octal et hexadécimal,

1001010101001111 binaire1001010101001111 binaire10010101010011111 1 2 5 1 7 octal10010101010011119 5 4 F hexa9 5 4 F hexa

Justification ? Conv. de base par division

29 octobre 2010 Circuits logiques - JP David 11

L’addition binaire : 207 + 120

128 64 32 16 8 4 2 1128 64 32 16 8 4 2 1

1 0 1 0 0 0 1 1 129 octobre 2010 Circuits logiques - JP David 12

1 0 1 0 0 0 1 1 1

Le décalageg

32 16 8 4 2 1 1/ 1/ 1/ 1/ 1/ 1/ Base32 16 8 4 2 1 1/2

1/4

1/8

1/16

1/32

1/64

Base10

1 1 0 0 1 1 0 0 0 0 0 0 511 1 0 0 1 1 0 0 0 0 0 0 510 1 1 0 0 1 1 0 0 0 0 0 25,5

0 1 1 0 0 1 1 0 0 0 0 12 750 1 1 0 0 1 1 0 0 0 0 12,750 1 1 0 0 1 1 0 0 0 6,375

0 1 1 0 0 1 1 0 0 3, …0 1 1 0 0 1 1 0 1, …

29 octobre 2010 Circuits logiques - JP David 13

La multiplicationp• 123 x 35 = (1 x 100 + 2 x 10 + 3) x 35

3 35 0105= 3 x 35 = 0105+ 2 x 35 x 10 = 0700+ 1 x 35 x 100 = 3500

= 4305= 4305

en base 2:101 110011 (1 100 + 0 10 + 1) 110011• 101(2) x 110011(2) = (1 x 100(2) + 0 x 10(2) + 1) x 110011(2)

= 1 x 110011(2) = 00110011(2)

+ 0 x 110011(2) x 10(2) = 00000000(2)+ 0 x 110011(2) x 10(2) = 00000000(2)

+ 1 x 110011(2) x 100(2) = 11001100(2)

= 11111111(2)

29 octobre 2010 Circuits logiques - JP David 14

(2)

La soustraction : 207 - 120

128 64 32 16 8 4 2 1128 64 32 16 8 4 2 1+

-

+

-

0 1 0 1 0 1 1 129 octobre 2010 Circuits logiques - JP David 15

0 1 0 1 0 1 1 1

La soustraction : 79 - 120

128 64 32 16 8 4 2 1128 64 32 16 8 4 2 1+

-

+

-

1 1 0 1 0 1 1 129 octobre 2010 Circuits logiques - JP David 16

1 1 0 1 0 1 1 1-256

Les nombres négatifsg

• Soit une architecture 8 bitsSoit une architecture 8 bits00000000(2) ≤ N ≤ 11111111(2) (soit 255)

11111111(2) + 1 = 1 00000000(2) → 00000000(2)(2) (2) (2)

Si (11111111(2) + 1) = 0, alors 11111111(2) = -1

• Toutes les opérations sont % (modulo) 256Les nombres négatifs sont en fait 256-n

• -1 → 255, -2 → 254, -3 → 253 … -255 → 1

• 3 – 1 = (3 + 255) % 256 = 2

• 255 -1 = (255 + 255) % 256 = 254

• 1 – 3 = (1 + 253) % 256 = 254 (=256-2)

29 octobre 2010 Circuits logiques - JP David 17

1 3 (1 + 253) % 256 254 ( 256 2)

La notation complément à 2p

• Soit un nombre V de N bits V[N-1 … 0]Soit un nombre V de N bits V[N 1 … 0]Comment savoir si sa valeur est :

• V[N-1..0] ou V[N-1..0] - 2N[ ] [ ]• 254 ou -2 (254-256)

• On définit que V[N-1] est le bit de signeSi V[n-1] = 0, alors V est positif

• V = V[N-1..0]En 8 bits on peutSi V[n-1] = 1, alors V est négatif

• V = V[N-1..0] - 2N

V = V[N 1] ( 2N-1) + V[N 2 0]

En 8 bits, on peut représenter les nombres entiers de -128 à +127

29 octobre 2010 Circuits logiques - JP David 18

V = V[N-1] (-2N 1) + V[N-2..0]

Le calcul du complément à 2p

• Par définition :Par définition :/2x = 2N – x

• Par soustraction :Par soustraction :0 – x

• Par complément à 1:p2N – x = (2N – 1) – x +1 = /x +1/2 (00000010(2)) = 11111111(2)– 00000010(2) + 1(2) (2) (2)

= 11111101(2) + 1

= 11111110(2)

29 octobre 2010 Circuits logiques - JP David 19

11111110(2)

Retour à la soustraction

128 64 32 16 8 4 2 1128 64 32 16 8 4 2 1+

-

+

-

1 1 1 0 1 0 1 1 129 octobre 2010 Circuits logiques - JP David 20

1 1 1 0 1 0 1 1 1-256

La division binaire1101001100(2) |1100(2) 844 | 12-1100000000(2) 1 -768 = 12 x 640001001100(2) 76

110000000(2) 0 384(2)

11000000(2) 0 1921100000(2) 0 96

110000 1 48 = 12 x 4-110000(2) 1 -48 = 12 x 411100(2) 28

-11000(2) 1 -24 = 12 x 2100(2) 4

1100(2) 0reste 100(2) 844 / 12 = 70,reste 4

29 octobre 2010 Circuits logiques - JP David 21

Virgule fixeg

• La représentation en virgule fixe signifie queLa représentation en virgule fixe signifie que l’on fixe le nombre de bits de la partie fractionnairefractionnaire

Ex : 5 bits d’entier + 3 bits après la virgulePour les additions soustractions• Pour les additions soustractions

Aucun changement• Pour les multiplications/divisions

Remettre la virgule au bon endroit

29 octobre 2010 Circuits logiques - JP David 22

Exemples en virgule fixep g

• En virgule fixe 5.3g9.375 + 20.875 = 1/8 (75 + 167)

01001.011(2) + 10100.111(2)

= 0.001(2) (01001011(2) + 10100111(2)) = 0.001(2) (11110010(2))

= 11110.010(2)

9.375 x 20.875 = (1/8)2 x (75 x 167)= 0.000001(2) (01001011(2) x 10100111(2))

= 0.000001(2) (11000011101101(2)) = 11000011.101101(2) (fixe 10.6)

• Convertir 37 69 en virgule fixe• Convertir 37.69 en virgule fixeDe 37, par /2 successives, on a : 100101(2)

De 0.69, par x2 successives, on a : 0.101100 …(2)

29 octobre 2010 Circuits logiques - JP David 23

37.69 = 100101.101100 …(2)

Le “demi” additionneur

Addi i d d bi A B l d lAddition de deux bits (demi-additionneur binaire)

A et B : cumulande et cumulateur

S : somme R : retenue) S : somme R : retenue

A B R SS A B= ⊕ R AB=

0 0 0 00 1 0 1

SAB0 1 0 1

1 0 0 11 1 1 0 R

29 octobre 2010 Circuits logiques - JP David 24

Additionner n bits1 3 2 1nr r r r−

1 3 2 1 0

1 3 2 1 0

n

n

a a a a ab b b b b

−+L

L

1 3 2 1 0n nr s s s s s− L

Additionneur binaire

l t

a0 b0a1 b1a2 b2bn-1an-1

r = 0r2 r1rn-1 r3

complet ΣΣΣΣr0 = 0

29 octobre 2010 Circuits logiques - JP David 25

s0s1s2sn-1rn

L’additionneur “complet”

r a b s r 0100aibi

1011

p

1

0 0 0 0 0

i i i i ir a b s r+

0 1

1 01

0100

0ri

0 1

1 0

1011

0 0 1 1 00 1 0 1 0 i i i i i i i i i i i i is r a b r a b r a b r a b= + + +

0 1 1 0 11 0 0 1 01 0 1 0 1 0 0

0100

0

aibi

1 0

1011

1 0 1 0 11 1 0 0 11 1 1 1 1

0 11ri

1 1

b b+ +

29 octobre 2010 Circuits logiques - JP David 26

1i i i i i i ir r a r b a b+ = + +

L’additionneur “complet” (suite)

s r a b r a b r a b r a b= + + +

L additionneur complet (suite)

i i i i i i i i i i i i is r a b r a b r a b r a b= + + +

( ) ( )i i i i i i i i i ir a b a b r a b a b= + + +

( ) ( ) ( )b b b⊕ ⊕ ⊕ ⊕

bbb

( ) ( ) ( )i i i i i i i i ir a b r a b r a b= ⊕ + ⊕ = ⊕ ⊕

a bb b ou ii ii ii i irr bbb a aa + +

0 0

0100

0

aibi

ri

1 0

1011

( )i i i i i i ir a b a b a b= + +

( )b b

1i i i i i i ir r a r b a b+ = + +

0 11i

1 1( )i i i i ir a b a b= ⊕ +

29 octobre 2010 Circuits logiques - JP David 27

L’additionneur “complet” (suite)L additionneur complet (suite)

ai

bi

( )b⊕ ⊕ri

( )i i i is r a b= ⊕ ⊕

( )1i i i i i ir r a b a b+ = ⊕ +( )1i i i i i ia b a b+ ⊕

29 octobre 2010 Circuits logiques - JP David 28

Ô temps … Inconvénient de l’additionneur itératif :

a0b0 s0r0

p

Délai de propagation des retenues

Cet additionneur à 3 bits a un chemin critique

0r0

(le plus long chemin de l’entrée à la sortie) de 7 portes.

L l d h i i i

a1b1

s1

La longueur du chemin critique est proportionnelle au nombre de bits et le délai qu’il engendre peut facilement devenir excessif q g ppour des additionneurs de large taille.

Solution : Circuit d’anticipation de retenues

a2b2 s2

29 octobre 2010 Circuits logiques - JP David 29r

Anticipation des retenues(en anglais : « Carry Lookahead Network »)

1 où (ou bien ) et i i i i i i i i i i i ir r p g p a b a b g a b+ = + = ⊕ + =

p

1 ( )i i i i i i i i i i i ip g p g+

1 0 0 0r r p g= +

( )2 1 1 1 0 0 0 1 1 0 0 1 0 1 1r r p g r p g p g r p p g p g= + = + + = + +

( )3 2 2 2 0 0 1 0 1 1 2 2 0 0 1 2 0 1 2 1 2 2r r p g r p p g p g p g r p p p g p p g p g= + = + + + = + + +

0 0 1 2 1 0 1 2 1 1 2 1 2 3 1

4 3 2 1 3 2 1 2 1 1

n n n n nr r p p p p g p p p g p p g p pg p p p g p p g p g

− − − −= + + + +

+ + + +

L L L L L

L 4 3 2 1 3 2 1 2 1 1 n n n n n n n n n ng p p p g p p g p g− − − − − − − − − −+ + + +

29 octobre 2010 Circuits logiques - JP David 30

Ex. sur un additionneur 4 bits

g0

r1g0p1g1p2

r2

g2p3g3

r3

Chemin de 2 portes

r4

29 octobre 2010 Circuits logiques - JP David 31

Exemple (suite)

s0a0 a1 a2

b2

a3bb b

Exemple (suite)

0

s1

b2 b3b0 b1

s2

s3

g0 p1 g1 p2 g2 p3 g3

r4Circuit d’anticipation des retenues

r1 r2 r3 r4

29 octobre 2010 Circuits logiques - JP David 32

Addition/soustraction

[ ] [ ]a a a a a b b b b b[ ] [ ]1 2 2 1 0 1 2 2 1 0n n n na a a a a b b b b b− − − −−L L

b0b1b2b 1

a0

b0

a1

b1

a2

b2bn-1

an-1

ΣΣΣΣr0 = 1

r2 r1rn-1 r3

s0s1s2sn-1rn

29 octobre 2010 Circuits logiques - JP David 33

Addition/soustraction (suite)

Unité arithmétique binaire avec commande de l’opération 0 , addition1 , soustraction

c ⎧= ⎨⎩

Addition/soustraction (suite)

b0b1b2bn-1

a0a1a2an-1

r2 r1r 1 r3

ΣΣΣΣ r0

r2 r1rn-1 r3

s0s1s2sn-1rn

d

29 octobre 2010 Circuits logiques - JP David 34

détection de débordement