Download presentation

Presentation is loading. Please wait.

Published byKatelyn O'Connell Modified over 2 years ago

1
1 A Simple ALU Binary Logic

2
2 Outline l Binary Logic l Representation of Logic Gates l Constructing a 1-bit adder l Constructing an n-bit adder

3
3 Binary Logic l A computer works using digital electronics. l There are only High and Low voltages l All computer logic is based on the manipulation of these l Abstractly, » High is interpreted as 1 (true) » Low is interpreted as 0 (false)

4
4 Logic Circuit l A logic circuit takes in a number of input lines (A, B, C,...) » and has a number of output lines (X,Y,Z,...) A B C X Y Z

5
5 Logic Basics l Every expression evaluates to 1 or 0 l NOT » ~A (A bar) – is the complement of A, i.e. 1-A l OR » A + B – is 1 if and only if at least one of A or B is 1, else 0 l AND » A.B – is 1 if and only if both A and B are 1, else 0

6
6 Truth Tables ABA+BA.B A~A ABCA.BA.CB+CA.(B+C) A.B+A.C A.(B+C)=A.B+A.C

7
7 Gates A B A.BAND Gate A B A+B OR Gate A ~AInverter (NOT)

8
8 Representations of Integers l Positive integers are represented by strings of binary digits - of fixed length given by the word length (eg, 32 bits). l Numbers in the range 0 to can be represented LSBMSB

9
9 Negative Numbers l We have to have a way to represent negative numbers and 0. » If the word length is n, then there are 2 n bit-patterns possible - there cannot be an equal number of positive and negative numbers represented. l Suppose n=3, and consider the following: » 000 two = 0 ten 100 two = -4 ten » 001 two = 1 ten 101 two = -3 ten » 010 two = 2 ten 110 two = -2 ten » 011 two = 3 ten 111 two = -1 ten

10
10 Twos Complement l For an n-bit word, the MSB is called the sign bit, which if 1 determines a negative number. l An n-bit word: (b n-1 b n-2...b 1 b 0 ) two represents the decimal number: l Eg, if n=4, 1101 = = -3. l Eg, if n=5, = = -10

11
11 Negating a Number l A simple technique for negating a number: » Invert each bit, and then add 1. l Convert:- » = = 2 ten +8 ten = 10 ten » = 0011 = 1 ten + 2 ten = 3 ten » = 1101 = -8 ten +4 ten +1 ten = -3 ten

12
12 Arithmetic l Binary arithmetic, addition and subtraction are similar to decimal: » work from least significant bit to most significant bit – using carries where necessary. l A fundamental issue on a computer is the fixed word size » The operands and result is dependent on the word length, and sometimes the result will be too small (negative) or too large (positive) to be represented.

13
13 Addition and Subtraction l Examples, n=4 (OVERFLOW) ten ten = = -3 ten l Subtraction = (twos complement) = 0001 = 1 ten

14
Overflow (Patterson) °Examples: = 10 but = - 9 but... 2s ComplementBinaryDecimal Decimal

15
Overflow Detection (Patterson) °Overflow: the result is too large (or too small) to represent properly Example: - 8 < = 4-bit binary number <= 7 °When adding operands with different signs, overflow cannot occur! °Overflow occurs when adding: 2 positive numbers and the sum is negative 2 negative numbers and the sum is positive

16
16 Designing a 1-bit Adder l A 1-bit adder must follow the following rules:- » abRC » 0000 » 0110 » 1010 » 1101 l a, b inputs, R result, C carry.

17
17 Logic Circuit for 1-bit Adder l Notice that » R = (~a).b + a.(~b) » C = a.b a b r c

18
18 n-bit Adder l Problem with previous circuit is that there is no way to combine a sequence of adders together » the carry of one addition must be passed to the next. l Need a structure as: carryin a b r carryout

19
19 Truth Table Cout = a.(~b).c + a.b.(~c) + (~a).b.c + a.b.c = a.c+b.c+a.b Result = (~a).(~b).c + (~a).b.(~c) + a.(~b).(~c) + a.b.c Logic diagrams can be constructed for each of carryout and Result, using the results below.

20
Logic Diagrams for CarryOut and Sum (Patterson) °CarryOut = B & CarryIn | A & CarryIn | A & B °Result = A XOR B XOR CarryIn CarryIn CarryOut A B A B CarryIn Result

21
21 Link 1-bit adders for n-bit carryin a b r0 carryout/carry in a b r1 carryout A chain of 1-bit adders is formed where the carryout of each becomes the carryin of the next. The result is the sequence of results from LSB to MSB.

22
A0 B0 1-bit ALU Result0 CarryIn0 CarryOut0 A1 B1 1-bit ALU Result1 CarryIn1 CarryOut1 A2 B2 1-bit ALU Result2 CarryIn2 CarryOut2 A3 B3 1-bit ALU Result3 CarryIn3 CarryOut3 (Patterson) Notice how the 1-bit adders are cascaded together.

23
23 Summary l Binary logic l Number representations » twos complement l Binary arithmetic l Constructing a 1-bit adder l Constructing an n-bit adder l...next time --- floating point.

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google