23
CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE UNIVERSITY, WILBERFORCE, OH 1

CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Embed Size (px)

Citation preview

Page 1: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

CPS3340 COMPUTER

ARCHITECTURE Fall Semester, 2013

CPS3340 COMPUTER

ARCHITECTURE Fall Semester, 2013

09/17/2013

Lecture 6: Binary Addition & Subtraction,

1-bit ALU

Instructor: Ashraf YaseenDEPARTMENT OF MATH & COMPUTER SCIENCECENTRAL STATE UNIVERSITY, WILBERFORCE, OH

1

Page 2: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Review

Last Class Integrated Circuits Decoder, Multiplexor PLA, ROM Don’t Care, Bus

This Class Assignemnt2 Representation of Integer Addition & Subtraction 1-bit ALU

Next Class Quiz2 32-bit ALU

2

Page 3: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Bit, Byte, and Word

1 Bit – 0 or 1 1 Byte – 8 bits 1 Word – N bytes (in general)

4 bytes in a word (in our book)

3

Page 4: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Most Significant Bit and Least Significant Bit

Most Significant Bit (High-Order Bit) The bit position having the greatest value Usually the left-most bit

Least Significant Bit (Low-Order Bit) The bit position having the smallest value Usually the right-most bit

4

Page 5: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Binary Representation of Decimal Number

Binary  1 0 0 1 0 1 0 1 1 0 1

Decimal 

1×210 + 0×29 + 0×28 + 1×27 + 0×26 + 1×25 + 0×24 + 1×23 + 1×22 + 0×21 + 1×20 = 1197

Using a binary number to represent a decimal number

Example

What is the maximum number a byte can represent?

5

Page 6: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Binary Representation of Integers Unsigned Integers

0 and positive integers only Signed Integers

0, negative, and positive integers Three ways

Sign-Magnitude 1’s Complement 2’s Complement

6

Page 7: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Unsigned Integers

Unsigned Integers Consider a word = 4 bytes Can represent numbers from 0 to 4294967295Decimal:

0 to 232-1Binary:

0 to 11111111111111111111111111111111 Example671210 = 00000000 00000000 00011010

001110002

7

Page 8: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Signed Integer – Sign Magnitude

Sign Magnitude Use the most significant bit of the word to represent

the sign 0 – Positive 1 – Negative

Rest of the number is encoded in magnitude part Example 671210 = 00000000 00000000 00011010 001110002

-671210 = 10000000 00000000 00011010 001110002

Two representations of 0 0 = 00000000 00000000 00000000 00000000

-0 = 10000000 00000000 00000000 00000000 Cumbersome in Arithmetic

8

Page 9: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

1’s Complement

1’s Complement Negative number is stored as bit-wise complement of

corresponding positive number Use the most significant bit of the word to represent the

sign 0 – Positive 1 – Negative

Example 671210 = 00000000 00000000 00011010 001110002

-671210 = 11111111 11111111 11100101 110001112

Still two representations of zero 0 = 00000000 00000000 00000000 00000000

-0 = 11111111 11111111 11111111 11111111

9

Page 10: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

2’s Complement

2’s Complement Positive number represented in the same way as

sign-magnitude and 1’s complement Negative number obtained by taking 1’s

complement of positive number and adding 1

671210 = 00000000 00000000 00011010 001110002

1’s comp: -671210 = 11111111 11111111 11100101 110001112

2’s comp: -671210 = 11111111 11111111 11100101 110010002

One version of 0 Convenient in arithmetic

10

Page 11: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Integer Addition

Example: 7 + 600000000 00000000 00000000 00000111

+ 00000000 00000000 00000000 0000011000000000 00000000 00000000 00001101

§3.2 Addition and S

ubtraction

11

Page 12: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Integer Subtraction

Subtraction is actually an addition Example: 7 – 6 = 7 + (-6) 2’s complement

00000000 00000000 00000000 00000111- 11111111 11111111 11111111 11111010

00000000 00000000 00000000 00000001

12

Page 13: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Overflow

Overflow if result out of range Adding +value and –value operands, no

overflow Adding two +value operands

Overflow if result sign is 1 Adding two –value operands

Overflow if result sign is 0

13

Page 14: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Arithmetic Logic Unit

Arithmetic Logic Unit (ALU) Heart of a CPU Operations

Arithmetic operations Addition Subtraction

Logical operations NOT AND OR

14

Page 15: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

1-bit Logical Unit for AND and OR

1-bit logical unit for AND and OR

15

Page 16: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

1-bit adder16

Page 17: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

1-bit adder truth table

can express the output functions Carry Out and Sum as logical equations, and these equations can in turn be implemented with logic gates

17

Page 18: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Simplifying 1-bit adder

If a and b and CarryIn are true, then the three other terms are true as well

can be simplified as

Values when CarryOut is true

18

Page 19: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Logic of CarryOut Bit19

Page 20: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Logic of Sum Bit20

Page 21: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Overall 1-bit ALU21

Page 22: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

Summary

Bit, Byte, Word Binary Representation of Integer Addition Subtraction Overflow 1-bit ALU

22

Page 23: CPS3340 COMPUTER ARCHITECTURE Fall Semester, 2013 09/17/2013 Lecture 6: Binary Addition & Subtraction, 1-bit ALU Instructor: Ashraf Yaseen DEPARTMENT OF

What I want you to do

Review Appendix C and Class Slides Work on Assignment 2 Prepare for Quiz 2

23