Download presentation

Presentation is loading. Please wait.

Published byFreddie Higbie Modified over 2 years ago

1
Rekenen en rekenschakelingen Ben Bruidegom AMSTEL Instituut FNWI UvA

2
Rekenen en rekenschakelingen b Binaire code b Hexadecimale code b Optellen b Two’s complement code b Aftrekken b Arithmetic Logic Unit b Sign extension b Look Ahead Carry Generation b Vermenigvuldigen

3
Decimale code b 235 = 2* 10 2 + 3* 10 1 + 5 * 10 0 b Grondtal is 10 Binaire code b 101 = 1* 2 2 + 0* 2 1 + 1 * 2 0 b Grondtal is 2

4
Binary code

5
Binary code (Unsigned Integer)

6
8 bit 0100 0000 = …. 1000 0111 = …. Range: 0.. n = 8 Range 0 … n = 16 Range 0 … 2 = 32 Range 0.. Unsigned Integer

7
8 bit 0100 0000 = 64 1000 0111 = Range: 0.. n = 8 Range 0.. n = 16 Range 0.. n = 32 Range 0.. Unsigned Integer

8
8 bit 0100 0000 = 64 1000 0111 = 135 Range: 0.. n = 8 Range 0.. n = 16 Range 0.. n = 32 Range 0.. Unsigned Integer

9
8 bit 0100 0000 = 64 1000 0111 = 135 Range: 0.. n = 8 Range 0.. 255 (256 –1) n = 16 Range 0.. n = 32 Range 0.. Unsigned Integer 1 2 4 8 16 32 64 128 255

10
8 bit 0100 0000 = 64 1000 0111 = 135 Range: 0.. n = 8 Range 0.. 255 n = 16 Range 0.. 65.536 n = 32 Range 0.. Unsigned Integer

11
8 bit 0100 0000 = 64 1000 0111 = 135 Range: 0.. n = 8 Range 0.. 255 n = 16 Range 0.. 65.535 n = 32 Range 0.. 4.294.967.295 Unsigned Integer

12
Hexadecimale code b Verkorte schrijfwijze binaire code b Grondtal 16

18
Optellen GetalDecimaalBinair A25 1 1 0 0 1 1 1 0 0 1 B29 1 1 1 0 1 1 1 1 0 1 A + B 54 1 1 0 1 1 0

19
Optellen GetalDecimaalBinair transport111001 A25 11001 11001 B29 11101 11101 A + B 54110110 1 onthouden

20
Optelschakeling GetalDecimaalBinair transport1 11001 A25 11001 11001 B29 11101 11101 A + B 54 110110 Half adder Full adder Sum bit Carry bit

21
Pauze b PIDAC-practicum opgaven 2.3.1 t/m 2.3.6

22
Negatieve getallen One’s complement code 1000........11001101111011110000000100100011........0111 -7..-3-2-00123..7

23
Negatieve getallen Two’s complement code 1000........11001101111011110000000100100011........0111 -8..-4-3-20123..7

24
Negatieve getallen Hoe genereer ik een negatief getal?

25
getal 0001 1001 25 complement 1110 0110 1 Two’s complement 1110 0111 -25 Controle: -128 + 64 + 32 + 4 + 2 + 1 = -25

26
Negatieve getallen

27
8 bit 0100 0000 = 64 1000 0111 = -121 Range: 0.. n = 8 Range –128.. 127 n = 16 Range -32768.. 32767 n = 32 Range –2147483648.. 2147483647 Signed Integer

28
Overflow in 4 bit systeem 10111010-5-6 10101 +5 antwoord 1001 + overflow antwoord –7 + 16 = +900110110361001-7 ++ Negeren 4 bit systeem antwoord 0101 + overflow antwoord 5 - 16 = -11

29
Two’s complement code

30
Aftrekken

31
Aftrekken : -3 – (+6) = -3 +(-6) 11010110-36 - + Negeren 4 bit systeem antwoord 0111 + overflow antwoord 7 - 16 = -911011010-3-6 10111 7 0110 bits inverteren 1001 1 bij optellen 1 1010

32
Arithmetic-Logic Unit Carry in i Carry out i

33
4 bits ALU

34
Overflow condities: b Boek bladz. 172 b 8 bit systeem b Overflow =

35
Bitwise operatoren 10101100 00111010 00101000 Bitwise AND-operator (&)

36
Bitwise operatoren: bittest 10101100 00001000 00001000 Bitwise AND-operator (&)1010010000001000 00000000

37
Bitwise operatoren: bit-reset 10101100 11110111 10100100 Bitwise AND-operator (&)

38
Opgaven b Opgaven: 2.4.1 tot en met 2.7.2 b Vervolg college: 13.30 uur b De hierna behandelde sheets behoren niet tot de stof die voor AI-studenten is bestemd.

39
Arithmetic Logic Unit 32 operation result a b ALU

40
b Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers b Binary numbers (base 2) 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001... decimal: 0...2 n -1 b Of course it gets more complicated: numbers are finite (overflow) fractions and real numbers negative numbers How do we represent negative numbers? i.e., which bit patterns will represent which numbers? Numbers

41
32 bit signed numbers: 0000 0000 0000 0000 0000 0000 0000 0000 two = 0 ten 0000 0000 0000 0000 0000 0000 0000 0001 two = + 1 ten 0000 0000 0000 0000 0000 0000 0000 0010 two = + 2 ten... 0111 1111 1111 1111 1111 1111 1111 1110 two = + 2,147,483,646 ten 0111 1111 1111 1111 1111 1111 1111 1111 two = + 2,147,483,647 ten 1000 0000 0000 0000 0000 0000 0000 0000 two = – 2,147,483,648 ten 1000 0000 0000 0000 0000 0000 0000 0001 two = – 2,147,483,647 ten 1000 0000 0000 0000 0000 0000 0000 0010 two = – 2,147,483,646 ten... 1111 1111 1111 1111 1111 1111 1111 1101 two = – 3 ten 1111 1111 1111 1111 1111 1111 1111 1110 two = – 2 ten 1111 1111 1111 1111 1111 1111 1111 1111 two = – 1 ten maxint minintMIPS

42
b Converting n bit numbers into numbers with more than n bits: MIPS 16 bit immediate gets converted to 32 bits for arithmeticMIPS 16 bit immediate gets converted to 32 bits for arithmetic copy the most significant bit (the sign bit) into the other bits 0011 0010 -> 0000 0000 0011 0010 1001 1010 -> 1111 1111 1001 1010copy the most significant bit (the sign bit) into the other bits 0011 0010 -> 0000 0000 0011 0010 1001 1010 -> 1111 1111 1001 1010 "sign extension"

43
Conclusion b We can build an ALU to support the MIPS instruction set key idea: use multiplexor to select the output we want (fig. 2.7.1)key idea: use multiplexor to select the output we want (fig. 2.7.1) we can efficiently perform subtraction using two’s complementwe can efficiently perform subtraction using two’s complement we can replicate a 1-bit ALU to produce a 32-bit ALUwe can replicate a 1-bit ALU to produce a 32-bit ALU b Important points about hardware all of the gates are always workingall of the gates are always working the speed of a gate is affected by the number of inputs to the gate???the speed of a gate is affected by the number of inputs to the gate??? the speed of a circuit is affected by the number of gates in series (on the “critical path” or the “deepest level of logic”)the speed of a circuit is affected by the number of gates in series (on the “critical path” or the “deepest level of logic”) b Our primary focus: comprehension, however, Clever changes to organization can improve performance (similar to using better algorithms in software)Clever changes to organization can improve performance (similar to using better algorithms in software) we’ll look at two examples for addition and multiplicationwe’ll look at two examples for addition and multiplication

44
b Is there more than one way to do addition? b Is a 32-bit ALU as fast as a 1-bit ALU? two extremes: ripple carry and sum-of-productstwo extremes: ripple carry and sum-of-products c 1 = b 0 c 0 + a 0 c 0 + a 0 b 0 c 2 = b 1 c 1 + a 1 c 1 + a 1 b 1 = = b 1 (b 0 c 0 + a 0 c 0 + a 0 b 0 )+ a 1 (b 0 c 0 + a 0 c 0 + a 0 b 0 )+ a 1 b 1 c 3 = b 2 c 2 + a 2 c 2 + a 2 b 2 c 3 = c 4 = b 3 c 3 + a 3 c 3 + a 3 b 3 c 4 = Not feasible! Why? Problem: ripple carry adder is slow

45
Can you see the ripple? How could you get rid of it?

46
b An approach in-between our two extremes b Motivation: If we didn't know the value of carry-in, what could we do? If we didn't know the value of carry-in, what could we do? When would we always generate a carry? g i = a i. b iWhen would we always generate a carry? g i = a i. b i When would we propagate the carry? p i = a i + b iWhen would we propagate the carry? p i = a i + b i b Did we get rid of the ripple? c 1 = a 0.b 0 + b 0 c 0 + a 0 c 0 = a 0.b 0 + c 0 (b 0 +a 0 ) c 1 = g 0 + p 0 c 0 c 2 = g 1 + p 1 c 1 c 2 = g 1 + p 1 (g 0 + p 0 c 0 ) c 3 = g 2 + p 2 c 2 c 3 = c 4 = g 3 + p 3 c 3 c 4 = Feasible! Why? Carry-lookahead adder

47
b Can’t build a 16 bit adder this way... (too big) b Could use ripple carry of 4-bit CLA adders b Better: use the CLA principle again! Use principle to build bigger adders

48
b More complicated than addition accomplished via shifting and additionaccomplished via shifting and addition b More time and more area Let's look at 3 versions based on gradeschool algorithm 0010 (multiplicand) __x_1011 (multiplier) b Negative numbers: convert and multiply there are better techniques, we won’t look at themthere are better techniques, we won’t look at them Multiplication

49
Multiplication Multiplier

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google