Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS231: Computer Architecture I Laxmikant Kale Fall 2002.

Similar presentations


Presentation on theme: "CS231: Computer Architecture I Laxmikant Kale Fall 2002."— Presentation transcript:

1 CS231: Computer Architecture I Laxmikant Kale Fall 2002

2 Introduction to CS231 1 Review There are 10 kinds of people in the world – Those who understand binary and those who don’t 00000 00011 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 257 68 120 45 27 32

3 Introduction to CS231 2 Binary addition example worked out Some terms are given here Exercise: what are these numbers equivalent to in decimal? 1110(Carries) 1011(Augend) +1110(Addend) 11001(Sum) The initial carry in is implicitly 0 most significant bit (MSB) least significant bit (LSB)

4 Introduction to CS231 3 Basic Gates There are three basic kinds of logic gates AND of two inputs OR of two inputs NOT (complement) on one input Operation: Logic gate: Two Questions: How can we implement such switches? What can we build with Gates? And How?

5 Introduction to CS231 4 Doing addition with gates Lets do simple stuff first: – Can we add two numbers each with just 1 bit? Bit: binary digit – 0+0 = 0, 0+1 = 1, 1+0 = 1, and 1+1 = ??? 2. But 2 is not a symbol. 10 (just as 5 + 5 is 10 in decimal) Result is 0 with 1 carried over to the next bit.. – Whats 1 and 0? High and low voltage respectively. Result Carry Half adder

6 Introduction to CS231 5 Half adder: result Result This circuit is so common, that it has a name an symbol as a gate by itself: Exclusive OR Exclusive OR Output is 1 iff exactly one of the 2 inputs is 1

7 Introduction to CS231 6 Adding two bits A half adder is used to add two bits. The result consists of two bits: a sum (the right bit) and a carry out (the left bit) Here is the circuit and its block symbol 0+ 0= 0 0+ 1= 1 1+ 0= 1 1+ 1= 10

8 Introduction to CS231 7 Adding three bits But what we really need to do is add three bits: the augend and addend, and the carry in from the right. 11101011+11101100111101011+111011001 0+ 0+ 0= 00 0+ 0+ 0= 01 0+ 1+ 0= 01 0+ 1+ 1= 10 1+ 0+ 0= 01 1+ 0+ 1= 10 1+ 1+ 0= 10 1+ 1+ 1= 11

9 Introduction to CS231 8 Full adder circuit Why are these things called half adders and full adders? You can build a full adder by putting together two half adders.

10 Introduction to CS231 9 A 4-bit adder Four full adders together can make a 4-bit adder There are nine total inputs to the 4-bit adder: – two 4-bit numbers, A3 A2 A1 A0 and B3 B2 B1 B0 – an initial carry in, CI The five outputs are: – a 4-bit sum, S3 S2 S1 S0 – a carry out, CO

11 Introduction to CS231 10 An example of 4-bit addition Let’s put our initial example into this circuit: A=1011, B=1110 Step 1:Fill in all the inputs, including CI=0 Step 2:The circuit produces C1 and S0 (1 + 0 + 0 = 01) Step 3:Use C1 to find C2 and S1 (1 + 1 + 0 = 10) Step 4:Use C2 to compute C3 and S2 (0 + 1 + 1 = 10) Step 5:Use C3 to compute CO and S3 (1 + 1 + 1 = 11) The final answer is 11001 1110110111101101 0 1100111001 0 11

12 Introduction to CS231 11 Now that we can add, how about some memory? We want to save results computed before, and recall them in a later calculation, for example Gates help us build memory How can a circuit “remember” anything on its own? – After all, the values on the wires are always changing, as outputs are generated in response to inputs. The basic idea is feedback: we make a “loop” in the circuit, so the circuit outputs are inputs as well When S and R are 0, Q is “stable”: whatever it was, it stays in that state. Ergo : memory. When S is 1 and R is 0, Q becomes 1 When R is 1 and S is 0, Q becomes 0 Set and Reset inputs…

13 Introduction to CS231 12 So, we have built a calculator It is not a computer yet… – We have to type each step into a calculator – We’d like to “program” standard steps E.g. Add 57 numbers sitting in memory in specific places – Also, support other operations (subtract..) Two new ideas and components are needed for this: – Addressable memory – Stored Program Addressable memory – Memory organized in a bunch of locations, such that contents of specified location can be brought back to the adder when needed. – Each memory location has an “address” (binary, of course) Stored Program: – The instructions for which numbers to operate on, what operation to do (add/subtract,..) and where to store the result – The instructions themselves can be represented in binary and stored in the memory! – The processor must have circuits to decode and “interpret” these instructions

14 Introduction to CS231 13 Components of a basic computer Memory ALU (Arithmetic/Logic Unit: Basic operations Data Program Control and Decoding

15 Introduction to CS231 14 Summary Controllable Switches are easy to make These switches can be used to put together “Logic Gates” Logic Gates can be put together to make half adder, full adders and multi-bit adders – So we can see they can be used for other such circtuits as well Logic Gates can be used to make circtuits that “remember” or store data A Computer includes, at its heart : – An ALU (Arithmetic Logic Unit) – Instruction Decoding and associated circuits – Memory – Stored Program

16 ©2000-2002 Howard Huang 15 Number systems To get started, we’ll discuss one of the fundamental concepts underlying digital computer design: 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 voltages into the discrete, or digital, values 1 and 0. But how can two lousy digits 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 1 0

17 Introduction to CS231 16 Rest of Today’s lecture Having seen an overview last week, – We will now start a more thorough study Number systems – Review of binary number representation – How to convert between binary and decimal representations – Octal and Hex representations Basic boolean operations – AND, OR and NOT – The idea of “Truth Table” – Boolean functions and expressions – Truth table for Boolean expressions

18 Introduction to CS231 17 Decimal review Numbers consist of a bunch of digits, each with a weight: The weights are all powers of the base, which is 10. We can rewrite the weights like this: To find the decimal value of a number, multiply each digit by its weight and sum the products. (1 x 10 2 ) + (6 x 10 1 ) + (2 x 10 0 ) + (3 x 10 -1 ) + (7 x 10 -2 ) + (5 x 10 -3 ) = 162.375

19 Introduction to CS231 18 Converting binary to decimal We can use the same trick to convert binary, or base 2, numbers to decimal. The only difference is that the weights are powers of 2. For example, here is 1101.01 in binary: The decimal value is: (1 x 2 3 ) + (1 x 2 2 ) + (0 x 2 1 ) + (1 x 2 0 ) + (0 x 2 -1 ) + (1 x 2 -2 ) = 8+ 4+ 0+ 1+ 0+ 0.25= 13.25

20 Introduction to CS231 19 Converting decimal to binary 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: So, 162.375 10 = 10100010.011 2 162 / 2= 81rem 0 81 / 2= 40rem 1 40 / 2= 20rem 0 20 / 2= 10rem 0 10 / 2= 5rem 0 5 / 2= 2rem 1 2 / 2= 1rem 0 1 / 2= 0rem 1 0.375 x 2 = 0.750 0.750 x 2 = 1.500 0.500 x 2 = 1.000

21 Introduction to CS231 20 Why does this work? This works for converting from decimal to any base Why? Think about converting 162.375 from decimal to decimal. 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. 162 / 10= 16rem 2 16 / 10= 1rem 6 1 / 10= 0rem 1 0.375 x 10 = 3.750 0.750 x 10 = 7.500 0.500 x 10 = 5.000

22 Introduction to CS231 21 Base 16 is useful too The hexadecimal system uses 16 digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F 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 = 2 4, 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.

23 Introduction to CS231 22 Binary and hexadecimal conversions Converting from hexadecimal to binary is easy: just replace each hex digit with its equivalent 4-bit binary sequence. 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. 261.35 16 = 2 6 1. 3 5 16 =001001100001.00110101 2 10110100.001011 2 =10110100.00101100 2 = B 4. 2 C 16

24 Introduction to CS231 23 Number Systems Summary 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. We’ve already seen some of the recurring themes of architecture: – 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.

25 ©2000-2002 Howard Huang 24 Boolean Operations 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: – How functions can be defined for expressing computations – How to build circuits that implement our functions in hardware

26 Introduction to CS231 25 Boolean values 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: – 1 is true – 0 is false We will use this interpretation along with special operations to design functions and hardware for doing arbitrary computations. Volts 1.8 0 True False

27 Introduction to CS231 26 Functions Computers take inputs and produce outputs, just like functions in math! Mathematical functions can be expressed in two ways: We can represent logical functions in two analogous ways too: – A finite, but non-unique Boolean expression. – A truth table, which will turn out to be unique and finite. f(x,y)= 2x + y = x + x + y = 2(x + y/2) =... An expression is finite but not unique A function table is unique but infinite

28 Introduction to CS231 27 Basic Boolean operations There are three basic operations for logical values. AND (product) of two inputs OR (sum) of two inputs NOT (complement) on one input xy, or x  yx + yx’ Operation: Expression: Truth table:

29 Introduction to CS231 28 Boolean expressions 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: f(x,y,z) = (((x +(y’))z) + x’)

30 Introduction to CS231 29 Truth tables 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. – A function with n variables has 2 n possible combinations of inputs. Inputs are listed in binary order—in this example, from 000 to 111. f(0,0,0)= (0 + 1)0 + 1= 1 f(0,0,1)= (0 + 1)1 + 1= 1 f(0,1,0)= (0 + 0)0 + 1= 1 f(0,1,1)= (0 + 0)1 + 1= 1 f(1,0,0)= (1 + 1)0 + 0= 0 f(1,0,1)= (1 + 1)1 + 0= 1 f(1,1,0)= (1 + 0)0 + 0= 0 f(1,1,1)= (1 + 0)1 + 0= 1 f(x,y,z) = (x + y’)z + x’

31 Introduction to CS231 30 Primitive logic gates Each of our basic operations can be implemented in hardware using a primitive logic gate. – Symbols for each of the logic gates are shown below. – These gates output the product, sum or complement of their inputs. Logic gate: AND (product) of two inputs OR (sum) of two inputs NOT (complement) on one input xy, or x  yx + yx’ Operation: Expression:

32 Introduction to CS231 31 Expressions and circuits 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! (x + y’)z + x’

33 Introduction to CS231 32 Boolean operations summary 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 time, we’ll look at how Boolean algebra can help simplify expressions, which in turn will lead to simpler circuits.


Download ppt "CS231: Computer Architecture I Laxmikant Kale Fall 2002."

Similar presentations


Ads by Google