Chapter 3: part 3 Binary Subtraction

Similar documents
Chapter 4 Arithmetic Functions

ECE/Comp Sci 352 Digital Systems Fundamentals. Charles R. Kime Section 2 Fall Logic and Computer Design Fundamentals

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Chapter 4 Arithmetic

Number System. Introduction. Decimal Numbers

Chapter 10 Binary Arithmetics

World Inside a Computer is Binary

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

Chapter 3 Part 2 Combinational Logic Design

Binary Adders: Half Adders and Full Adders

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Principles of Computer Architecture. Chapter 3: Arithmetic

carry in carry 1101 carry carry

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

EE 109 Unit 6 Binary Arithmetic

Advanced Computer Architecture-CS501

COMPUTER ARITHMETIC (Part 1)

Computer Architecture and Organization: L04: Micro-operations

(+A) + ( B) + (A B) (B A) + (A B) ( A) + (+ B) (A B) + (B A) + (A B) (+ A) (+ B) + (A - B) (B A) + (A B) ( A) ( B) (A B) + (B A) + (A B)

Lecture (02) Operations on numbering systems

Digital Systems and Binary Numbers

*Instruction Matters: Purdue Academic Course Transformation. Introduction to Digital System Design. Module 4 Arithmetic and Computer Logic Circuits

Chap.3 3. Chap reduces the complexity required to represent the schematic diagram of a circuit Library

MC1601 Computer Organization

COMBINATIONAL LOGIC CIRCUITS

Number representations

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Chapter 1. Digital Systems and Binary Numbers

Arithmetic Processing

Chapter 2: Number Systems

60-265: Winter ANSWERS Exercise 4 Combinational Circuit Design

Experiment 7 Arithmetic Circuits Design and Implementation

CO212 Lecture 10: Arithmetic & Logical Unit

Chapter 10 - Computer Arithmetic

Computer Architecture and Organization

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Numeric Encodings Prof. James L. Frankel Harvard University

Arithmetic Logic Unit

COMP 122/L Lecture 2. Kyle Dewey

ECE468 Computer Organization & Architecture. The Design Process & ALU Design

Basic Arithmetic (adding and subtracting)

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

Module 2: Computer Arithmetic

Chapter 3 Part 2 Combinational Logic Design

UNIT-III REGISTER TRANSFER LANGUAGE AND DESIGN OF CONTROL UNIT

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

Learning Objectives. Binary over Decimal. In this chapter you will learn about:

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Number Systems Base r

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

Chapter 4. Combinational Logic

CHW 261: Logic Design

Binary Arithmetic. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T.

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-278: Digital Logic Design Fall Notes - Unit 4. hundreds.

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-2700: Digital Logic Design Winter Notes - Unit 4. hundreds.

CS 64 Week 1 Lecture 1. Kyle Dewey

Arithmetic Operations

Computer Organization

COMP2611: Computer Organization. Data Representation

CPE300: Digital System Architecture and Design

BINARY SYSTEM. Binary system is used in digital systems because it is:

INF2270 Spring Philipp Häfliger. Lecture 4: Signed Binaries and Arithmetic

Korea University of Technology and Education

1. Mark the correct statement(s)

CS101 Lecture 04: Binary Arithmetic

Arithmetic and Logical Operations

Digital Fundamentals

Real Digital Problem Set #6

Chapter 5 Design and Implementation of a Unified BCD/Binary Adder/Subtractor

CARLETON UNIVERSITY. Laboratory 2.0

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

Chapter 1 Review of Number Systems

Chapter 5: Computer Arithmetic

CO Computer Architecture and Programming Languages CAPL. Lecture 9

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

Number Systems. Readings: , Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs

Numerical Representations On The Computer: Negative And Rational Numbers

MYcsvtu Notes DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS Arithmetic (a) The four possible cases Carry (b) Truth table x y

EXPERIMENT #8: BINARY ARITHMETIC OPERATIONS

Chapter 4. Operations on Data

LOGIC CIRCUITS. Kirti P_Didital Design 1

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

UNIT IV: DATA PATH DESIGN

Register Transfer Language and Microoperations (Part 2)

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

Digital Circuit Design and Language. Datapath Design. Chang, Ik Joon Kyunghee University

Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

Chapter 5 : Computer Arithmetic

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

ALU Design. 1-bit Full Adder 4-bit Arithmetic circuits. Arithmetic and Logic Unit Flags. Add/Subtract/Increament/Decrement Circuit

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

Transcription:

Chapter 3: part 3 Binary Subtraction Iterative combinational circuits Binary adders Half and full adders Ripple carry and carry lookahead adders Binary subtraction Binary adder-subtractors Signed binary numbers Signed binary addition and subtraction Overflow Other Arithmetic Functions Chapter 4 1

Unsigned Subtraction Algorithm: Subtract the subtrahend N from the minuend M If no end borrow occurs, then M N, and the result is a non-negative number and correct. If an end borrow occurs, then N > M and the difference M N + 2 n is subtracted from 2 n, and a minus sign is appended to the result. 0 1 1001 0100 0111 0111 0010 1101 10000 1101 ( ) 0011 Examples: Chapter 4 2

Unsigned Subtraction (continued) The subtraction, 2 n N, is taking the 2 s complement of N To do both unsigned addition and unsigned A subtraction requires: Quite complex! Goal: Shared simpler logic for both addition and subtraction Introduce complements as an approach Binary adder Subtract/Add S Borrow Complement 0 1 Quadruple 2-to-1 multiplexer B Binary subtractor Selective 2's complementer Result Chapter 4 3

Complements Two complements: Diminished Radix Complement of N (r 1) s complement for radix r 1 s complement for radix 2 Defined as (r n 1) Ν Radix Complement r s complement for radix r 2 s complement in binary Defined as r n N Subtraction is done by adding the complement of the subtrahend If the result is negative, takes its 2 s complement Chapter 4 4

Binary 1's Complement For r = 2, N = 01110011 2, n = 8 (8 digits): (r n 1) = 256-1 = 255 10 or 11111111 2 The 1's complement of 01110011 2 is then: 11111111 01110011 10001100 Since the 2 n 1 factor consists of all 1's and since 1 0 = 1 and 1 1 = 0, the one's complement is obtained by complementing each individual bit (bitwise NOT). Chapter 4 5

Binary 2's Complement For r = 2, N = 01110011 2, n = 8 (8 digits), we have: (r n ) = 256 10 or 100000000 2 The 2's complement of 01110011 is then: 100000000 01110011 10001101 Note the result is the 1's complement plus 1, a fact that can be used in designing hardware Chapter 4 6

Subtraction with 2 s Complement For n-digit, unsigned numbers M and N, find M N in base 2: Add the 2's complement of the subtrahend N to the minuend M: M + (2 n N) = M N + 2 n If M > N, the sum produces end carry r n which is discarded; from above, M N remains. If M < N, the sum does not produce an end carry and, from above, is equal to 2 n ( N M ), the 2's complement of ( N M ). To obtain the result (N M), take the 2's complement of the sum and place a to its left. Chapter 4 7

Important Observation The complement of the complement restores the number to its original value. This is true for both 1 s complement and 2 s complement. Chapter 4 8

Unsigned 2 s Complement Subtraction Example 1 Find 01010100 2 01000011 2 01010100 1 01010100 01000011 2 s comp + 10111101 00010001 The carry of 1 indicates that no correction of the result is required. Chapter 4 9

Unsigned 2 s Complement Subtraction Example 2 Find 01000011 2 01010100 2 0 01000011 01000011 01010100 2 s comp + 10101100 11101111 00010001 The carry of 0 indicates that a correction of the result is required. Result = (00010001) 2 s comp Chapter 4 10

Signed Integers Positive numbers and zero can be represented by unsigned n-digit, radix r numbers. We need a representation for negative numbers. To represent a sign (+ or ) we need exactly one more bit of information (1 binary digit gives 2 1 = 2 elements which is exactly what is needed). Since computers use binary numbers, by convention, the most significant bit is interpreted as a sign bit: s a n 2 a 2 a 1 a 0 where: s = 0 for Positive numbers s = 1 for Negative numbers and a i = 0 or 1 represent the magnitude in some form. Chapter 4 11

Signed Integer Representations Signed-Magnitude the number consists of a magnitude and a symbol (0 for +, 1 for -). Signed-Complement a negative number is represented by its complement. There are two possibilities here: Signed 1's Complement Uses 1's Complement Arithmetic Signed 2's Complement Uses 2's Complement Arithmetic Chapter 4 12

Signed Integer Representation Example r =2, n=3 Number Sign - Mag. 1's Comp. 2's Comp. +3 011 011 011 +2 010 010 010 +1 001 001 001 +0 000 000 000 0 100 111 1 101 110 111 2 110 101 110 3 111 100 101 4 100 Chapter 4 13

Corresponding positive number? The two's complement of a negative number is the corresponding positive value. For example, inverting the bits of 5 (1111 1011) gives: 0000 0100 And adding one gives the final value: 0000 0101 (5) Chapter 4 14

Signed-Complement Arithmetic Addition: 1. Add the numbers including the sign bits, discarding a carry out of the sign bits (2's Complement) 2. If the sign bits were the same for both numbers and the sign of the result is different, an overflow has occurred. 3. The sign of the result is computed in step 1. Subtraction: Form the 2 s complement of the number you are subtracting and follow the rules for addition. Chapter 4 15

Signed 2 s Complement Examples Example 1: 1101 + 0011 Example 2: 1101 0011 Chapter 4 16

2 s Complement Adder/Subtractor Subtraction can be done by addition of the 2's Complement. 1. Complement each bit (1's Complement.) 2. Add 1 to the result. The circuit shown computes A + B and A B: For S = 1, subtract, the 2 s complement B 3 of B is formed by using XORs to form the 1 s comp and adding the 1 applied to C 0. For S = 0, add, B is C 3 passed through unchanged C 4 S 3 A 3 B 2 A 2 B 1 A 1 B 0 A 0 C 2 C 1 C 0 FA FA FA FA S 2 S 1 S 0 S Chapter 4 17

Overflow Detection Overflow occurs if n + 1 bits are required to contain the result from an n-bit addition or subtraction Overflow can occur for: Addition of two operands with the same sign Subtraction of operands with different signs Signed number overflow cases with correct result sign 0 0 1 1 + 0 1 0 + 1 0 0 1 1 Detection can be performed by examining the result signs which should match the signs of the top operand Chapter 4 18

Overflow Detection Signed number cases with carries C n and C n 1 shown for correct result signs: 0 0 0 0 1 1 1 1 0 0 1 1 + 0 1 0 + 1 0 0 1 1 Signed number cases with carries shown for erroneous result signs (indicating overflow): 0 1 0 1 1 0 1 0 0 0 1 1 + 0 1 0 + 1 1 1 0 0 Simplest way to implement overflow V = C n + C n 1 Chapter 4 19

Overflow Example (1) Carries: 0 1 +70 0 1000110 +80 0 1010000 +150 1 0010110 Chapter 4 20

Overflow Example (2) Carries: 1 0-70 1 0111010-80 1 0110000-150 0 1101010 A simple logic that provides overflow detection is shown in Figure 4-8 (see next slide) Chapter 4 21

Figure 4-8 Chapter 4 22

Class Exercises (1) Perform the indicated subtraction with the following unsigned binary numbers by taking the 2s complement of the subtrahend: (please see slide 9) a) 11010 10001 b) 11110-1110 Chapter 4 23

Class Exercises (2) Perform the arithmetic operations (+36) + (-24) and (-35) (-24) in binary using signed 2s complement representation for negative numbers. (see slide 17) Chapter 4 24

Other Arithmetic Functions Convenient to design the functional blocks by contraction - removal of redundancy from circuit to which input fixing has been applied Functions Incrementing Decrementing Multiplication by Constant Zero Fill and Extension Chapter 4 25

Design by Contraction Contraction is a technique for simplifying the logic in a functional block to implement a different function The new function must be realizable from the original function by applying rudimentary functions to its inputs Contraction is treated here only for application of 0s and 1s (not for X and X) After application of 0s and 1s, equations or the logic diagram are simplified by using rules given on page 168 of the text. Chapter 4 26

Design by Contraction Example Contraction of a ripple carry adder to incrementer for n = 3 Set B = 001 C 3 5 X X X A 2 0 0 A 1 A 1 0 0 0 4 1 5 2 C 1 3 C 0 5 0 S 2 S 1 S 0 (a) A 2 A 1 A 0 S 2 S 1 S 0 (b) The middle cell can be repeated to make an incrementer with n > 3. Chapter 4 27

Discussion Can we make the three cells identical? How? Chapter 4 28

Incrementing & Decrementing Incrementing Adding a fixed value to an arithmetic variable Fixed value is often 1, called counting (up) Examples: A + 1, B + 4 Functional block is called incrementer Decrementing Subtracting a fixed value from an arithmetic variable Fixed value is often 1, called counting (down) Examples: A 1, B 4 Functional block is called decrementer Chapter 4 29

Multiplication by a Constant Multiplication of B(3:0) by 101 See text Figure 4-10 (a) for contraction B 3 B 2 B 1 B 0 0 0 B 3 B 2 B 1 B 0 Carry output 4-bit Adder Sum C 6 C 5 C 4 C 3 C 2 C 1 C 0 Chapter 4 30

Zero Fill Zero fill - filling an m-bit operand with 0s to become an n-bit operand with n > m Filling usually is applied to the MSB end of the operand, but can also be done on the LSB end Example: 11110101 filled to 16 bits MSB end: 0000000011110101 LSB end: 1111010100000000 Chapter 4 31

Extension Extension - increase in the number of bits at the MSB end of an operand by using a complement representation Copies the MSB of the operand into the new positions Positive operand example - 01110101 extended to 16 bits: 0000000001110101 Negative operand example - 11110101 extended to 16 bits: 1111111111110101 Chapter 4 32

Extension Example 01101011 (107 in decimal) 0000000001101011 10010101 ( how much in 2 s complement?) 1111111110010101 Chapter 4 33

Weekly Exercise 4-2 4-3 4-4 (a) and (b) 4-5 (a) and (b) 4-6 4-7 (a) and (c) Chapter 4 34