1Ben Bruidegom Hoe rekent een computer II? Ben Bruidegom AMSTEL Instituut Universiteit van Amsterdam
2Ben Bruidegom Rekenen en rekenschakelingen Binaire code Hexadecimale code Optellen Two’s complement code Aftrekken Arithmetic Logic Unit Sign extension Look Ahead Carry Generation Vermenigvuldigen
3Ben Bruidegom Negatieve getallen One’s complement code Waarom is deze code minder geschikt?
4Ben Bruidegom Negatieve getallen Two’s complement code bit: Bereik
5Ben Bruidegom Negatieve getallen Hoe genereer ik een negatief getal?
6Ben Bruidegom Negatieve getallen Hoe genereer ik een negatief getal? getal complement Two’s complement Controle: = -25
7Ben Bruidegom Negatieve getallen
8Ben Bruidegom 8 bit = = -121 Range: 0.. n = 8 Range – n = 16 Range n = 32 Range – Signed Integer
9Ben Bruidegom Overflow (in 4 bit systeem) antwoord overflow antwoord – = Negeren 4 bit systeem antwoord overflow antwoord = -11
10Ben Bruidegom Two’s complement code
11Ben Bruidegom Hoe werkt de hardware? Schakeling die kan aftrekken
12Ben Bruidegom Aftrekken : -3 – (+6) = -3 +(-6) Negeren 4 bit systeem antwoord overflow antwoord = bits inverteren bij optellen
13Ben Bruidegom 4 bits ALU
14Ben Bruidegom Overflow condities: Zie boek bladz. 172 Voor 16 bit systeem: Twee positieve getallen: antwoord negatief
15Ben Bruidegom Opgaven Opgaven: Hoofdstuk 4: Vervolg college: uur De hierna behandelde sheets behoren niet tot de stof die voor AI-studenten is bestemd.
16Ben Bruidegom Arithmetic Logic Unit 32 operation result a b ALU
17Ben Bruidegom Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2) decimal: n -1 Of course it gets more complicated: numbers are finite (carry) fractions and real numbers negative numbers How do we represent negative numbers? i.e., which bit patterns will represent which numbers? Numbers
18Ben Bruidegom two = 0 ten two = + 1 ten two = + 2 ten two = + 2,147,483,646 ten two = + 2,147,483,647 ten two = – 2,147,483,648 ten two = – 2,147,483,647 ten two = – 2,147,483,646 ten two = – 3 ten two = – 2 ten two = – 1 ten maxint minint 32 bit signed numbers:
19Ben Bruidegom Converting n bit numbers into numbers with more than n bits: MIPS 16 bit immediate gets converted to 32 bits for arithmetic copy the most significant bit (the sign bit) into the other bits > > "sign extension"
20Ben Bruidegom Conclusion We can build an ALU to support the MIPS instruction set key idea: use multiplexor to select the output we want (fig ) we can efficiently perform subtraction using two’s complement we can replicate a 1-bit ALU to produce a 32-bit ALU Important points about hardware all 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 circuit is affected by the number of gates in series (on the “critical path” or the “deepest level of logic”) Our primary focus: comprehension, however, Clever changes to organization can improve performance (similar to using better algorithms in software) we’ll look at two examples for addition and multiplication
21Ben Bruidegom Is there more than one way to do addition? Is a 32-bit ALU as fast as a 1-bit ALU? two 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
22Ben Bruidegom Can you see the ripple? How could you get rid of it?
23Ben Bruidegom An approach in-between our two extremes Motivation: 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 i When would we propagate the carry? p i = a i + b i 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 = Carry-lookahead adder
24Ben Bruidegom Use principle to build bigger adders
25Ben Bruidegom 1. Shift and ADD 2. Hardware Multiplication
26Ben Bruidegom Vermenigvuldigen op de basisschool
27Ben Bruidegom Multiplication: Shift and ADD Multiplier
28Ben Bruidegom Hardware vermenigvuldiger