230 likes | 361 Views
CS231: Computer Architecture I. Review Session. Introduction. Contact TAs (people who you will be directly dealing with): Joshua Smith, Rajhans Samdani. Emails for tas: ta231@cs.uiuc.edu
E N D
CS231: Computer Architecture I Review Session
Introduction Contact TAs (people who you will be directly dealing with): Joshua Smith, Rajhans Samdani. Emails for tas: ta231@cs.uiuc.edu Homework Routine/Policy: Usually the homeworks will be released on Mondays and each homework will cover the portion taught on that Monday and the following Wednesday and will be due the next Monday by 5 pm. After that, you can submit till Tuesday 5pm with 10% penalty and till Wednesday 5pm with 20% penalty. Homeworks won’t be accepted after that and the solutions will be released on Wednesday evenings. How to submit homeworks: You should submit your homeworks in the TA office(0212 sc). DO NOT put your homework sheets on the box outside the room. If the room is closed then slide your homework sheets in. Overall: It’s a fairly chilled out course as far as the toughness level is concerned and is not very exacting either . So have fun and concentrate on the basics. Introduction to CS231
Today’s Agenda • Review of various number systems • Conversions between various number systems • Simple operations/functions and introduction to truth tables Introduction to CS231
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 102) + (6 x 101) + (2 x 100) + (3 x 10-1) + (7 x 10-2) + (5 x 10-3) = 162.375 Introduction to CS231
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 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 = 13.25 Introduction to CS231
Why choose certain number systems over others? • In routine life, we use decimal system. Any reason for doing so? Why not any other base x where x could be any integer or for that matter any real number!? • Why do computers use binary system? Introduction to CS231
162 / 2 = 81 rem 0 81 / 2 = 40 rem 1 40 / 2 = 20 rem 0 20 / 2 = 10 rem 0 10 / 2 = 5 rem 0 5 / 2 = 2 rem 1 2 / 2 = 1 rem 0 1 / 2 = 0 rem 1 0.375 x 2 = 0.750 0.750 x 2 = 1.500 0.500 x 2 = 1.000 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.37510 = 10100010.0112 Introduction to CS231
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 = 16 rem 2 16 / 10 = 1 rem 6 1 / 10 = 0 rem 1 0.375 x 10 = 3.750 0.750 x 10 = 7.500 0.500 x 10 = 5.000 Introduction to CS231
Simple questions • Convert 115.7510 into base 2. • Convert 113.3333310….. into base 3. • Convert 1101.0112 into base 10. Introduction to CS231
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 = 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. Introduction to CS231
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 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.3516 = 261 . 3516 = 001001100001 . 001101012 10110100.0010112 = 10110100 . 001011002 = B4 . 2C16 Introduction to CS231
The Binary, the Hex and the other bases.. • Convert 01101.11 into hex • Convert the same number into oct (base 8) Introduction to CS231
Does this work for any base which is a power of 2 • Convert 101102m = X2. Find X. Introduction to CS231
An expression is finite but not unique A function table is unique but infinite f(x,y) = 2x + y = x + x + y = 2(x + y/2) = ... 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. Introduction to CS231
Basic Boolean operations • There are three basic operations for logical values. NOT (complement) on one input AND (product) of two inputs OR (sum) of two inputs Operation: Expression: xy, or xy x + y x’ Truth table: Introduction to CS231
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’) Introduction to CS231
f(x,y,z) = (x + y’)z + x’ 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 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 2n possible combinations of inputs. • Inputs are listed in binary order—in this example, from 000 to 111. Introduction to CS231
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. NOT (complement) on one input AND (product) of two inputs OR (sum) of two inputs Operation: Expression: xy, or xy x + y x’ Logic gate: Introduction to CS231
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’ Introduction to CS231
Easy one • Consider the expression: xz’ + y’z+ (z+y)x’ • Identify the literals in the above expression • Write down its truth table • Draw a circuit implementing this function Introduction to CS231
Arithmetic Operations • Add these two number given in binary: 1101 + 0111 • Add these hexadecimal numbers: ab2 + cd1 Introduction to CS231
How about subtraction • Perform the following subtractions (try doing it without converting into decimal) 1 1 0 12 - 0 1 1 12 ------------------- a 2 5 - 3 b c --------------- Introduction to CS231
How about multiplication • Perform the following multiplications (try without converting into decimal)(hint: the idea of multiplication remains the same as decimal) 1 0 12 x 1 1 12 ------------------- a 2 5 x 3 b c --------------- Introduction to CS231