Binary Arithmetic Stephen Boyd March 14, 2011. Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.

Slides:



Advertisements
Similar presentations
Combinational Circuits. Analysis Diagram Designing Combinational Circuits In general we have to do following steps: 1. Problem description 2. Input/output.
Advertisements

Arithmetic Functions and Circuits
Mohamed Younis CMCS 411, Computer Architecture 1 CMCS Computer Architecture Lecture 7 Arithmetic Logic Unit February 19,
ELEC353 S. al Zahir UBC Sign-Magnitude Representation High order bit is sign: 0 = positive (or zero), 1 = negative Low order bits represent the magnitude:
Arithmetic Operations and Circuits
Parallel Adder Recap To add two n-bit numbers together, n full-adders should be cascaded. Each full-adder represents a column in the long addition. The.
Henry Hexmoor1 Chapter 5 Arithmetic Functions Arithmetic functions –Operate on binary vectors –Use the same subfunction in each bit position Can design.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Assembly Language and Computer Architecture Using C++ and Java
Fixed-Point Arithmetics: Part I
Computer Structure - The ALU Goal: Build an ALU  The Arithmetic Logic Unit or ALU is the device that performs arithmetic and logical operations in the.
Chapter 6 Arithmetic. Addition Carry in Carry out
Assembly Language and Computer Architecture Using C++ and Java
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
1 COMP541 Arithmetic Circuits Montek Singh Mar 20, 2007.
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
ECE 301 – Digital Electronics
Copyright 2008 Koren ECE666/Koren Part.6a.1 Israel Koren Spring 2008 UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer.
COE 308: Computer Architecture (T041) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Arithmetic Operations and Circuits
 Arithmetic circuit  Addition  Subtraction  Division  Multiplication.
CS 105 Digital Logic Design
Lecture 12: Computer Arithmetic Today’s topic –Numerical representations –Addition / Subtraction –Multiplication / Division 1.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Data Representation – Binary Numbers
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
Computer Arithmetic Nizamettin AYDIN
Chapter 6-2 Multiplier Multiplier Next Lecture Divider
Chapter 7 Arithmetic Operations and Circuits Binary Arithmetic Addition –When the sum exceeds 1, carry a 1 over to the next-more-significant column.
Logical Circuit Design Week 8: Arithmetic Circuits Mentor Hamiti, MSc Office ,
Basic Arithmetic (adding and subtracting)
CS1Q Computer Systems Lecture 9 Simon Gay. Lecture 9CS1Q Computer Systems - Simon Gay2 Addition We want to be able to do arithmetic on computers and therefore.
Digital Arithmetic and Arithmetic Circuits
Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-1 The ALU.
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
Chapter 6-1 ALU, Adder and Subtractor
June 19, 2002Addition and multiplication1 Delays in the ripple carry adder The diagram below shows a 4-bit adder completely drawn out. This is called a.
Topic: Arithmetic Circuits Course: Digital Systems Slide no. 1 Chapter # 5: Arithmetic Circuits.
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
Basic Arithmetic (adding and subtracting)
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Logic and Computer Design.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow.
COMP541 Arithmetic Circuits
Combinational Circuits
Topics covered: Arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
MIPS ALU. Building from the adder to ALU ALU – Arithmetic Logic Unit, does the major calculations in the computer, including – Add – And – Or – Sub –
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
ECE 331 – Digital System Design Multi-bit Adder Circuits, Adder/Subtractor Circuit, and Multiplier Circuit (Lecture #12)
Computer Architecture
Addition, Subtraction, Logic Operations and ALU Design
1 Fundamentals of Computer Science Combinational Circuits.
Number Representation (Part 2) Computer Architecture (Fall 2006)
ECE DIGITAL LOGIC LECTURE 15: COMBINATIONAL CIRCUITS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2015, 10/20/2015.
MIPS ALU. Exercise – Design a selector? I need a circuit that takes two input bits, a and b, and a selector bit s. The function is that if s=0, f=a. if.
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Gunjeet Kaur Dronacharya Group of Institutions. Binary Adder-Subtractor A combinational circuit that performs the addition of two bits is called a half.
Addition and Subtraction
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
King Fahd University of Petroleum and Minerals
Number Representation
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Presentation transcript:

Binary Arithmetic Stephen Boyd March 14, 2011

Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave exactly like unsigned integers. Negative numbers are added to the negative value of the most significant bit = (-8) + 5 = = (-128) + 27 = = (-128) = -1

Two's Complement To convert between negative and positive, invert every bit and add (-3) → = (3) (3) → = (-3) For n number of bits, an integer has a possible range of -2 n-1 to 2 n to for a 4-bit integer, or -8 to 7

Binary Addition and Subtraction Similar to decimal addition → carry = 5 Subtraction can be achieved by adding a negative. 3 – 5 = 3 + (-5)

Overflow Overflow occurs when the result is beyond the possible range allowed by the number of bits → carry = -7 (WRONG!) Typically only occurs when the two left-most carries are either 10 or produces no problems. Can be detected with a simple XOR of the last two carries.

Half Adders A simple addition of 1-bit operands (A and B) produces two values: The summation S = A XOR B The carry C = A AND B This type of circuit is called a half adder:

Full Adders The drawback of half adders is that they do not account for the carry-in from a previous bit addition. For that, there are full adders: S = A XOR B XOR C in C = (A AND B) OR (C in AND (A XOR B))

Ripple Adders Multiple full adders can be strung together to create a ripple adder, with the carry-out from each going into the carry-in of the next.

Carry Lookahead Adders A problem with the ripple adder is that each 1-bit adder must wait for the previous adder to determine if there will be a carry before completing the summation. Lookahead adders are able to determine simultaneously for each 1-bit adder if there will be an incoming carry, and then allow each adder to perform the summation without waiting.

Carry Lookahead Adders In lookahead adders each 1-bit adder first informs the look ahead logic of two values: G – If the bit will generate a carry. This will happen regardless of an incoming carry if both A and B are 1. (G = A AND B) P – If the bit will propagate an incoming carry into the next bit adder. This will happen if either A or B is at least 1. (P = A OR B) Once P and G are known for all bit adders, it is possible to determine incoming carries without waiting for the full summation.

Carry Lookahead Adders

Subtraction As stated, a two's complement integer can be negated by inverting each bit and adding 1. X XOR Y will return Y if X = 0, and Y' if X = 1. With that in mind, any adder can be adapted to subtract instead with a toggle input XOR'd with each of the input bits and carried in to the first 1-bit adder.

Multiplication of Unsigned Integers Again, similar to decimal. Multiplying integers with x and y number of bits will yield a product of bits x+y. (at most) Example w/4-bit integers: 12 * 5 = Multiply the numbers as usual for decimal, then add them. Because binary only uses 1s and 0s, a shortcut is to simply repeat the multiplicand for each 1 in the multiplier, shifted left. Multiplicand Multiplier Product

Multiplication of Unsigned Integers

Fast Multiplication: Booth's Algorithm Multiplying integers M * N of lengths m and n respectively, need the following values: A = M followed by n+1 0's. B = M' followed by n+1 0's. P = m 0's followed by N and a 0. Start with P and examine 2 rightmost bits. 10 → P = P+B, shift right 01 → P = P+A, shift right 00 or 11 → shift right Do this n times, then drop the right most bit. P is now the product in two's complement. Example: -5 * 7 → 1011 * 0111 A = B = P = ) P=P+B shift ) shift ) shift ) P=P+A shift Product =