* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download NumbersAndBooleanAlgebran
Survey
Document related concepts
Transcript
Computer Organization By Dr. M. Khamis Mrs. Dua’a Al Sinari Computer Organization The course is aimed at designing the different computer components (circuits) and connecting these components in a way to achieve the goals of a specific architectures. Computer (hardware) consists of processor, memory and I/O units. Processor itself consists of Arithmetic Logic Unit (ALU) and Control unit. All the above units are designed using primitive logic circuits. Course Objectives Understanding the basic Laws of Boolean algebra. Designing and using the basic logic devices. Understanding the operation of the main computer units and their design. Interconnecting the various computer units to achieve the specific architecture. Presenting the attributes of the different architectures. Programming specific architecture using its instruction set (machine instruction). Explaining the Interaction between Computer hardware and the operating system. Course outline The course will consist of two parts: The first part is Logic design: in which the primitive components, by which the different devices are designed, are presented. The second part is intended for interconnecting the components presented in first part in a way to build a logical system (computer organization). Part 1: Logic Design Introduction to number systems and arithmetic operations in binary system. Combinational circuits: Logic Gates (AND, OR, NOT, NOR, NAND and XOR), in this regards we will give the truth tables and symbols for each . Laws of Boolean algebra, deriving logical expression and simplification. Karnaugh maps and its use for simplification . half and full adders and binary coded decimal adders Part 1: Logic Design devices include: Decoder. Encoder. Multiplexers/ De-multiplexer. Comparator. Sequential circuits include : Flip/Flops and counter Design Mealy and MOORE machines. Part 2: Computer Organization chapter 3: computer system chapter 7: Input/output chapter 8: Operating System Support. chapter 9: Computer Arithmetic chapter 10: Instruction Sets. chapter 11: :Instruction Sets: Addressing Modes and Format. chapter 12: CPU structure chapter 16 : Control Unit chapter 17: Micro Programmed Control Unit. NUMBERS AND BOOLEAN ALGEBRA Author: Abhinav Bhatele Revised By: Dr. M. Khamis FAll 2008 June 10th, 2008 NUMBER SYSTEMS To get started, we’ll discuss one of the fundamental concepts underlying digital computer design: Number Systems and Boolean Algebra Deep down inside, computers work with just 1s and 0s. Computers use voltages to represent information. In modern CPUs the voltage is usually limited to 1.6-1.8V to minimize power consumption. It’s convenient for us to translate these analog 1 voltages into the discrete, or digital, values 1 and 0. But how can binary system be useful for anything? First, we’ll see how to represent numbers with just 1s and 0s. Then we’ll introduce special operations for computing with 1s and 0s, by treating them as the logical values “true” and “false.” Volts 1.8 0 0 8 June 10th, 2008 TODAY’S LECTURE Number systems Review of binary number representation How to convert between binary and decimal representations Octal and Hex representations Number Systems and Boolean Algebra Basic boolean operations AND, OR and NOT The idea of “Truth Table” Boolean functions and expressions Truth table for Boolean expressions 9 Numbers consist of a bunch of digits, each with a weight 2 1 . 3 1/10 7 1/100 5 1/1000 Digits Weights These weights are all powers of the base, which is 10. We can rewrite this: 1 102 6 10 6 101 2 100 . 3 10-1 7 10-2 5 10-3 Digits Weights To find the decimal value of a number, multiply each digit by its weight and sum the products. Number Systems and Boolean Algebra 1 100 June 10th, 2008 DECIMAL REVIEW (1 x 102) + (6 x 101) + (2 x 100) + (3 x 10-1) + (7 x 10-2) + (5 x 10-3) = 162.375 10 We can use the same trick to convert binary, or base 2, numbers to decimal. This time, the weights are powers of 2. Example: 1101.01 in binary 1 23 1 22 0 21 1 20 . 0 2-1 1 2-2 Binary digits, or bits Weights (in base 2) The decimal value is: (1 x 23) + (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2) = 8 + 4 + 0 + 1 + 0 + 0.25 Powers of 2: 20 = 1 24 = 16 21 = 2 25 = 32 22 = 4 26 = 64 23 = 8 27 = 128 28 = 256 29 = 512 210 = 1024 = 13.25 Useful abbreviations: K = 210 = 1,024 M = 220 = 1,048,576 G = 230 = 1,073,741,824 Number Systems and Boolean Algebra June 10th, 2008 CONVERTING BINARY TO DECIMAL 11 162 / 2 81 / 2 40 / 2 20 / 2 10 / 2 5/2 2/2 1/2 = 81 = 40 = 20 = 10 =5 =2 =1 =0 rem 0 rem 1 rem 0 rem 0 rem 0 rem 1 rem 0 rem 1 So, 162.37510 = 10100010.0112 0.375 x 2 = 0.750 0.750 x 2 = 1.500 0.500 x 2 = 1.000 Number Systems and Boolean Algebra To convert a decimal integer into binary, keep dividing by 2 until the quotient is 0. Collect the remainders in reverse order. To convert a fraction, keep multiplying the fractional part by 2 until it becomes 0. Collect the integer parts in forward order. Example: 162.375: June 10th, 2008 CONVERTING DECIMAL TO BINARY 12 162 / 10 = 16 16 / 10 = 1 1 / 10 = 0 rem 2 rem 6 rem 1 Each division strips off the rightmost digit (the remainder). The quotient represents the remaining digits in the number. Similarly, to convert fractions, each multiplication strips off the leftmost digit (the integer part). The fraction represents the remaining digits. 0.375 x 10 = 3.750 0.750 x 10 = 7.500 0.500 x 10 = 5.000 Number Systems and Boolean Algebra This works for converting from decimal to any base Why? Think about converting 162.375 from decimal to decimal. June 10th, 2008 WHY DOES THIS WORK? 13 The hexadecimal system uses 16 digits: 0123456789ABCDEF You can convert between base 10 and base 16 using techniques like the ones we just showed for converting between decimal and binary. For our purposes, base 16 is most useful as a “shorthand” notation for binary numbers. Since 16 = 24, one hexadecimal digit is equivalent to 4 binary digits. It’s often easier to work with a number like B4 instead of 10110100. Hex is frequently used to specify things like 32-bit IP addresses and 24-bit colors. Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Hex 0 1 2 3 4 5 6 7 8 9 A B C D E F Number Systems and Boolean Algebra Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 June 10th, 2008 BASE 16 IS USEFUL TOO 14 Converting from hexadecimal to binary is easy: just replace each hex digit with its equivalent 4-bit binary sequence. 261.3516 = 2 6 1 . 3 516 = 0010 0110 0001 . 0011 01012 To convert from binary to hex, make groups of 4 bits, starting from the binary point. Add 0s to the ends of the number if needed. Then, just convert each bit group to its corresponding hex digit. 10110100.0010112 = 1011 0100 = B 4 . 0010 . 2 11002 C16 Hex Binary Hex Binary Hex Binary Hex Binary 0 0000 4 0100 8 1000 C 1100 1 0001 5 0101 9 1001 D 1101 2 0010 6 0110 A 1010 E 1110 3 0011 7 0111 B 1011 F 1111 Number Systems and Boolean Algebra June 10th, 2008 BINARY AND HEXADECIMAL CONVERSIONS 15 2’s complement Binary number can be represented using sign and magnitude. If N bits are used to represent the number, then the last bit is used to hold the sign of the number while the other (N-1) bits are used to represent the value. 0 is used for +ve sign and 1 is used for -ve sign. To get the 2’s complement for any number follow the following two steps: Convert each bit in the value into its complement (1 to 0 and vice versa) 2. Add 1 to the result of step 1. 1. Binary addition & subtraction If the number is +ve keep it in sign and magnitude form, otherwise represent the number (magnitude only) using its 2’s complement. Add the binary numbers in the ordinary way as the decimal numbers. The addition in decimal makes carry 1 for the next digit for each 10 collected in the sum, and the reset which will be less than 10 is left as result of the addition of the corresponding bits. This operation continues until adding all bits with its corresponding bits in the other number. Binary addition & subtraction (Continued) The addition in binary is exactly the same as decimal with only one difference, which is, carry 1 is taken for the next digit for each 2 collected in the sum, and the reset which is less than 2 is left as result of the addition of the corresponding bit. The addition is continued for all bits including the sign bit, and in order to get correct answer the number must be represented in enough number of bits. Any carry after the sign bit is discarded. The value of the negative result is represented in the 2’s complement (i.e. the actual value is the 2’s complement of the result once again). Computers are binary devices. We’re forced to think in terms of base 2. Today we learned how to convert numbers between binary, decimal and hexadecimal. Also, we have seen: We use 0 and 1 as abstractions for analog voltages. We showed how to represent numbers using just these two signals. Next we’ll introduce special operations for binary values and show how those correspond to circuits. Number Systems and Boolean Algebra June 10th, 2008 NUMBER SYSTEMS SUMMARY 19 How logical functions can be defined for expressing computations How to build circuits that implement our functions in hardware Number Systems and Boolean Algebra So far, we’ve talked about how arbitrary numbers can be represented using just the two binary values 1 and 0. Now we’ll interpret voltages as the logical values “true” and “false” instead. We’ll show: June 10th, 2008 BOOLEAN OPERATIONS 20 Earlier, we used electrical voltages to represent two discrete values 1 and 0, from which binary numbers can be formed. It’s also possible to think of voltages as representing two logical values, true and false. For simplicity, we often still write digits instead: True June 10th, 2008 BOOLEAN VALUES Number Systems and Boolean Algebra 1 is true 0 is false Volts 1.8 False We will use this interpretation along with special operations to design functions and hardware for doing arbitrary computations. 0 21 Computers take inputs and produce outputs, just like functions in math! A function table is unique but infinite x y f(x,y) 0 … 2 … 23 … 0 … 2 … 41 … 0 … 6 … 87 … Logical functions can be expressed in two ways: Number Systems and Boolean Algebra An expression is finite but not unique f(x,y) = 2x + y =x+x+y = 2(x + y/2) = ... June 10th, 2008 FUNCTIONS A finite, but non-unique Boolean expression. A truth table, which will turn out to be unique and finite. 22 June 10th, 2008 BASIC BOOLEAN OPERATIONS There are three basic operations for logical values. AND (product) of two inputs Expression: xy, or xy Truth table: NOT (complement) on one input OR (sum) of two inputs x+y x’ x y xy x y x+y x x’ 0 0 0 0 0 0 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 1 1 1 1 1 1 Number Systems and Boolean Algebra Operation: 23 We can use these basic operations to form more complex expressions: f(x,y,z) = (x + y’)z + x’ Some terminology and notation: f is the name of the function. (x,y,z) are the input variables, each representing 1 or 0. Listing the inputs is optional, but sometimes helpful. A literal is any occurrence of an input variable or its complement. The function above has four literals: x, y’, z, and x’. Precedences are important, but not too difficult. NOT has the highest precedence, followed by AND, and then OR. Fully parenthesized, the function above would be kind of messy: Number Systems and Boolean Algebra June 10th, 2008 BOOLEAN EXPRESSIONS f(x,y,z) = (((x +(y’))z) + x’) 24 A truth table shows all possible inputs and outputs of a function. Remember that each input variable represents either 1 or 0. Because there are only a finite number of values (1 and 0), truth tables themselves are finite. n A function with n variables has 2 possible combinations of inputs. Inputs are listed in binary order—in this example, from 000 to 111. f(x,y,z) = (x + y’)z + x’ f(0,0,0) f(0,0,1) f(0,1,0) f(0,1,1) f(1,0,0) f(1,0,1) f(1,1,0) f(1,1,1) = (0 + 1)0 + 1 = (0 + 1)1 + 1 = (0 + 0)0 + 1 = (0 + 0)1 + 1 = (1 + 1)0 + 0 = (1 + 1)1 + 0 = (1 + 0)0 + 0 = (1 + 0)1 + 0 =1 =1 =1 =1 =0 =1 =0 =1 x y z f(x,y,z) 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 1 Number Systems and Boolean Algebra June 10th, 2008 TRUTH TABLES 25 June 10th, 2008 PRIMITIVE LOGIC GATES Each of our basic operations can be implemented in hardware using a primitive logic gate. Operation: AND (product) of two inputs Expression: xy, or xy Logic gate: OR (sum) of two inputs x+y NOT (complement) on one input x’ Number Systems and Boolean Algebra Symbols for each of the logic gates are shown below. These gates output the product, sum or complement of their inputs. 26 (x + y’)z + x’ Number Systems and Boolean Algebra Any Boolean expression can be converted into a circuit by combining basic gates in a relatively straightforward way. The diagram below shows the inputs and outputs of each gate. The precedences are explicit in a circuit. Clearly, we have to make sure that the hardware does operations in the right order! June 10th, 2008 EXPRESSIONS AND CIRCUITS 27 After finding the circuit inputs and outputs, you can come up with either an expression or a truth table to describe what the circuit does. You can easily convert between expressions and truth tables. Find the circuit’s inputs and outputs Find a Boolean expression for the circuit Number Systems and Boolean Algebra June 10th, 2008 CIRCUIT ANALYSIS SUMMARY Find a truth table for the circuit 28 We can interpret high or low voltage as representing true or false. A variable whose value can be either 1 or 0 is called a Boolean variable. AND, OR, and NOT are the basic Boolean operations. We can express Boolean functions with either an expression or a truth table. Every Boolean expression can be converted to a circuit. Next, we’ll look at how Boolean algebra can help simplify expressions, which in turn will lead to simpler circuits. Number Systems and Boolean Algebra June 10th, 2008 BOOLEAN OPERATIONS SUMMARY 29 Last time we talked about Boolean functions, Boolean expressions, and truth tables. Now we’ll learn how to how use Boolean algebra to simplify Booleans expressions. Last time, we saw this expression and converted it to a circuit: (x + y’)z + x’ Can we make this circuit “better”? • Cheaper: fewer gates • Faster: fewer delays from inputs to outputs Number Systems and Boolean Algebra June 10th, 2008 BOOLEAN ALGEBRA 30 Normal mathematical expressions can be simplified using the laws of algebra For binary systems, we can use Boolean algebra, which is superficially similar to regular algebra There are many differences, due to having only two values (0 and 1) to work with having a complement operation the OR operation is not the same as addition Number Systems and Boolean Algebra June 10th, 2008 EXPRESSION SIMPLIFICATION 31 1. 3. 5. 7. 9. 10. 12. 14. 16. x+0=x x+1=1 x+x=x x + x’ = 1 (x’)’ = x x+y=y+x x + (y + z) = (x + y) + z x(y + z) = xy + xz (x + y)’ = x’y’ 2. 4. 6. 8. 11. 13. 15. 17. x1=x x0=0 xx=x x x’ = 0 xy = yx x(yz) = (xy)z x + yz = (x + y)(x + z) (xy)’ = x’ + y’ Commutative Associative Distributive DeMorgan’s Number Systems and Boolean Algebra A Boolean algebra requires A set of elements B, which needs at least two elements (0 and 1) Two binary (two-argument) operations OR and AND A unary (one-argument) operation NOT The axioms below must always be true (textbook, p. 42) The magenta axioms deal with the complement operation Blue axioms (especially 15) are different from regular algebra June 10th, 2008 FORMAL DEFINITION OF BOOLEAN ALGEBRA 32 The associative laws show that there is no ambiguity about a term such as x + y + z or xyz, so we can introduce multiple-input primitive gates: The left and right columns of axioms are duals exchange all ANDs with ORs, and 0s with 1s The dual of any equation is always true 1. 3. 5. 7. 9. 10. 12. 14. 16. x+0=x x+1=1 x+x=x x + x’ = 1 (x’)’ = x x+y=y+x x + (y + z) = (x + y) + z x(y + z) = xy + xz (x + y)’ = x’y’ 2. 4. 6. 8. 11. 13. 15. 17. Number Systems and Boolean Algebra x1=x x0=0 xx=x x x’ = 0 xy = yx x(yz) = (xy)z x + yz = (x + y)(x + z) (xy)’ = x’ + y’ June 10th, 2008 COMMENTS ON THE AXIOMS Commutative Associative Distributive DeMorgan’s 33 We can show that these axioms are valid, given the definitions of AND, OR and NOT y 0 1 0 1 xy 0 0 0 1 x 0 0 1 1 y 0 1 0 1 x+y 0 1 1 1 x 0 1 x’ 1 0 The first 11 axioms are easy to see from these truth tables alone. For example, x + x’ = 1 because of the middle two lines below (where y = x’) x 0 0 1 1 y 0 1 0 1 x+y 0 1 1 1 Number Systems and Boolean Algebra x 0 0 1 1 June 10th, 2008 ARE THESE AXIOMS FOR REAL? 34 We can make up truth tables to prove (both parts of) DeMorgan’s law For (x + y)’ = x’y’, we can make truth tables for (x + y)’ and for x’y’ y 0 1 0 1 x+y 0 1 1 1 (x + y)’ 1 0 0 0 x 0 0 1 1 y 0 1 0 1 x’ 1 1 0 0 y’ 1 0 1 0 x’y’ 1 0 0 0 In each table, the columns on the left (x and y) are the inputs. The columns on the right are outputs. In this case, we only care about the columns in blue. The other “outputs” are just to help us find the blue columns. Since both of the columns in blue are the same, this shows that (x + y)’ and x’y’ are equivalent Number Systems and Boolean Algebra x 0 0 1 1 June 10th, 2008 PROVING THE REST OF THE AXIOMS 35 June 10th, 2008 SIMPLIFICATION WITH AXIOMS We can now start doing some simplifications 1. 3. 5. 7. 9. 10. 12. 14. 16. x+0=x x+1=1 x+x=x x + x’ = 1 (x’)’ = x x+y=y+x x + (y + z) = (x + y) + z x(y + z) = xy + xz (x + y)’ = x’y’ [ Distributive; x’y’ + x’y = x’(y’ + y) ] [ Axiom 7; y’ + y = 1 ] [ Axiom 2; x’1 = x’ ] [ Distributive ] [ Axiom 7; x’ + x = 1 ] [ Axiom 2 ] 2. 4. 6. 8. 11. 13. 15. 17. x1=x x0=0 xx=x x x’ = 0 xy = yx x(yz) = (xy)z x + yz = (x + y)(x + z) (xy)’ = x’ + y’ Commutative Associative Distributive DeMorgan’s Number Systems and Boolean Algebra x’y’ + xyz + x’y = x’(y’ + y) + xyz = x’1 + xyz = x’ + xyz = (x’ + x)(x’ + yz) = 1 (x’ + yz) = x’ + yz 36 Here are two different but equivalent circuits. In general the one with fewer gates is “better”: It costs less to build It requires less power But we had to do some work to find the second form Number Systems and Boolean Algebra June 10th, 2008 LET’S COMPARE THE RESULTING CIRCUITS 37 Here are some more useful laws. Notice the duals again! 4. x(x + y) = x 5. (x + y)(x + y’) = x 6. x(x’ + y) = xy (x + y)(x’ + z)(y + z) = (x + y)(x’ + z) We can prove these laws by either Making truth tables: x 0 0 1 1 Using the axioms: y 0 1 0 1 x’ x’y x + x’y x + x’y = (x + x’)(x + y) = 1 (x + y) =x+y x 0 0 1 1 y 0 1 0 1 x+y 0 1 1 1 [ Distributive ] [ x + x’ = 1 ] [ Axiom 3 ] Number Systems and Boolean Algebra 1. x + xy = x 2. xy + xy’ = x 3. x + x’y = x + y xy + x’z + yz = xy + x’z June 10th, 2008 SOME MORE LAWS 38 The complement of a function always outputs 0 where the original function outputted 1, and 1 where the original produced 0. In a truth table, we can just exchange 0s and 1s in the output column(s) f(x,y,z) x 0 0 0 0 1 1 1 1 y 0 0 1 1 0 0 1 1 = x(y’z’ + yz) z 0 1 0 1 0 1 0 1 f(x,y,z) 1 1 1 1 0 0 1 0 x 0 0 0 0 1 1 1 1 y 0 0 1 1 0 0 1 1 z 0 1 0 1 0 1 0 1 f’(x,y,z) 0 0 0 0 1 1 0 1 Number Systems and Boolean Algebra June 10th, 2008 THE COMPLEMENT OF A FUNCTION 39 f(x,y,z) = x(y’z’ + yz) f’(x,y,z) = ( x(y’z’ + yz) )’ = x’ + (y’z’ + yz)’ = x’ + (y’z’)’ (yz)’ = x’ + (y + z)(y’ + z’) [ complement both sides ] [ because (xy)’ = x’ + y’ ] [ because (x + y)’ = x’ y’ ] [ because (xy)’ = x’ + y’, twice] You can also take the dual of the function, and then complement each literal If f(x,y,z) = x(y’z’ + yz)… … the dual of f is x + (y’ + z’)(y + z)… … then complementing each literal gives x’ + (y + z)(y’ + z’)… … so f’(x,y,z) = x’ + (y + z)(y’ + z’) Number Systems and Boolean Algebra You can use DeMorgan’s law to keep “pushing” the complements inwards June 10th, 2008 COMPLEMENTING A FUNCTION ALGEBRAICALLY 40 So far: A bunch of Boolean algebra trickery for simplifying expressions and circuits The algebra guarantees us that the simplified circuit is equivalent to the original one Next: Introducing some standard forms and terminology An alternative simplification method We’ll start using all this stuff to build and analyze bigger, more useful, circuits Number Systems and Boolean Algebra June 10th, 2008 SUMMARY SO FAR 41