Presentation on theme: "EET 1131 Unit 7 Arithmetic Operations and Circuits Read Kleitz, Chapter 7, skipping Sections 7-4, 7-5, and 7-8. Homework #7 and Lab #7 due next week."— Presentation transcript:
EET 1131 Unit 7 Arithmetic Operations and Circuits Read Kleitz, Chapter 7, skipping Sections 7-4, 7-5, and 7-8. Homework #7 and Lab #7 due next week. Quiz next week.
Binary Subtraction, Multiplication, Division The textbook also gives rules for doing binary subtraction, multiplication, and division. From a practical standpoint, though, it’s easier to do one of the following: Either convert the numbers from binary to decimal, then perform the arithmetic operation, then convert back to binary. Or use Windows Calculator to perform these operations directly on binary numbers.
Convention for Writing Multi-Bit Numbers We’ll use subscripts to refer to the individual bits in a binary number. The bit on the right-hand end, or least significant bit (LSB), always gets the smallest subscript, which may be either 1 or 0. Example: In a four-bit number A, the bits are labeled either A 4 A 3 A 2 A 1 or A 3 A 2 A 1 A 0
Arithmetic Logic Unit (ALU) Central to any computer system is its ALU, which performs mathematical and logical operations on data. In modern systems, the ALU is contained on the computer’s microprocessor chip. In older systems, the ALU was a separate chip, such as the
How Many Logical Operations? You already know how to perform some logical operations on two input bits, A and B. Examples: X = AB X = A+B Question: How many possible logical operations are there on two input bits?
How Many Logical Ops? (Continued) Let’s list them all: AB
74181 ALU chip Can perform 16 logical operations (bit- by-bit) and 16 arithmetic operations on two 4-bit input numbers. Data Sheet: 74LS18174LS181 See next slide (Fig from textbook) for logic symbol and function table.
74181 ALU (Continued) Caution: In the “Arithmetic Operations” columns of the function tables, the + symbol always means logical OR, not addition. The word “PLUS” is used for addition.
74181 ALU (Continued) Fourteen Input Pins: A0 to A3 form one of the 4-bit inputs. B0 to B3 form the other 4-bit input. C N is the carry-in bit, used only during arithmetic ops (ignored during logic ops). M is the mode pin (arithmetic or logic). S0 to S3 select the operation performed.
74181 ALU (Continued) Eight Output Pins: F0 to F3 form the 4-bit output. C N+4 is carry-out bit, meaningful only for arithmetic ops. (Ignore it for logic ops.) A=B is comparison bit, meaningful only when performing “A MINUS B” operation. (We’ll ignore this.) P and G are carry-look-ahead bits for high-speed arithmetic, when is used in conjunction with chip. (We’ll ignore these.)
Terminology: One’s-Complement and Two’s-Complement The one’s-complement of a binary number is the binary number that you get when you invert each bit. Example: What is the one’s-complement of ? The two’s-complement of a binary number is the binary number that you get when you invert each bit and then add 1 to the result. Example: What is the two’s-complement of ?
Interpreting Strings of 1s and 0s Possible answers: The number 65. The letter A (in ASCII code). … In digital systems we have nothing but 1s and 0s to represent all kinds of info: text, numbers, images, music, etc. To interpret a string of 1s and 0s, you have to be told what kind of info it represents. Example: What does represent?
Unsigned versus Signed Binary Integers Up to now, whenever we’ve worked with binary numbers, we’ve assumed they were unsigned binary integers. In other words, we’ve assumed that the numbers were all positive. Sometimes we also need to be able to represent negative integers, in which case we’re dealing with signed binary integers. To do this, we’ll use one bit to indicate the number’s sign (positive or negative).
Range of Unsigned Binary Integers Arranging unsigned 8-bit integers in order from least to greatest would give you a list that starts and ends like this: Binary Decimal
Range of Unsigned Binary Integers For unsigned integers with a fixed number of bits n: The least integer we can represent is 0. The greatest integer we can represent is 2 n -1. Example: Using 8 bits, The least integer is , which is equal to decimal 0. The greatest integer is , which is equal to decimal 255 (=2 8 -1).
Representing Signed Binary Integers To represent both positive and negative integers, we use the leftmost bit as a sign bit, like this (for 8 bits): Binary Decimal Negative integers (sign bit = 1) Zero and positive integers (sign bit = 0)
Two’s-Complement Representation The scheme shown on the previous slides is called two’s-complement representation. This is how computers represent signed integers, because this scheme results in simple circuits for doing binary arithmetic. Other common names for it: two’s complement notation or two’s complement form.
Range of Signed Binary Integers For signed integers with a fixed number of bits n, the least integer we can represent is −2 n−1, and the greatest integer we can represent is 2 n−1 −1. Example: Using 8 bits, The least integer we can represent is , which is equal to decimal −128 (= −2 7 ). The greatest integer we can represent is , which is equal to decimal 127 (= ).
Steps for Converting from Decimal to Two’s-Complement Form 1. If the integer is positive, convert it to binary as we’ve always done. 2. If the integer is negative: a) Ignoring the sign, convert it to binary as we’ve always done. b) Invert each bit. (That is, change each 0 to 1, and change each 1 to 0.) c) Add 1 to the result. Examples Convert to two’s complement form using 8 bits. Convert −23 10 to two’s complement form using 8 bits.
Steps for Converting from Two’s- Complement Form to Decimal 1. If the sign bit = 0, the integer is positive. Convert to decimal as we’ve always done. 2. If the sign bit = 1, the integer is negative. Follow these steps: a) Invert each bit. b) Add 1. c) Convert the result to decimal as we’ve always done. d) Write a negative sign in front. Examples: Convert to decimal. Convert to decimal.
An Adder/Subtractor Circuit By combining parallel adder chips (such as the or the 4008) with a controlled inverter, we can make a circuit that either adds or subtracts, depending on the value of a control input. See next slide (Fig from textbook).