C OMPUTER A RITHMETIC. I NTRODUCTION A processor has an separate unit that is known as ALU that executes arithmetic operations. Negative numbers may be.

Slides:



Advertisements
Similar presentations
Chapter 7 Henry Hexmoor Registers and RTL
Advertisements

1 Register Transfer &  -operations Computer Organization Computer Architectures Lab REGISTER TRANSFER AND MICROOPERATIONS Register Transfer Language Register.
King Fahd University of Petroleum and Minerals
Wakerly Section 2.4 and further Addition and Subtraction of Nondecimal Numbers.
Fixed-Point Arithmetics: Part I
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
Logic and Computer Design Dr. Sanjay P. Ahuja, Ph.D. FIS Distinguished Professor of CIS ( ) School of Computing, UNF.
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 4.
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.
Addition and Subtraction with Signed- Magnitude Data (Mano, Section 10-2) Basics Seminar, CSc 8215 High Performance Computing (2005 Fall) Mary R. Hudachek-Buswell.
Shift Micro operations
Lecture 12: Computer Arithmetic Today’s topic –Numerical representations –Addition / Subtraction –Multiplication / Division 1.
Arithmetic for Computers
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
Computer Arithmetic Nizamettin AYDIN
Chapter 6-2 Multiplier Multiplier Next Lecture Divider
Computer Architecture Lecture 3: Logical circuits, computer arithmetics Piotr Bilski.
Conversion Between Lengths Positive number pack with leading zeros +18 = = Negative numbers pack with leading ones -18 =
BINARY ARITHMETIC Binary arithmetic is essential in all digital computers and in many other types of digital systems.
MICRO OPERATIONS Department of Computer Engineering, M.S.P.V.L. Polytechnic College, Pavoorchatram.
Computer Arithmetic.
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 Register Transfer and Micro -operations
Operations on Bits Arithmetic Operations Logic Operations
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
Topics covered: Arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Number Systems & Operations
Chapter 4 Register Transfer and Microoperations Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Number Representation and Arithmetic Circuits
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
1 CS 151 : Digital Design Chapter 4: Arithmetic Functions and Circuits 4-3 : Binary Subtraction.
COMPUTER ARITHMETIC Arithmetic with Signed-2's Complement Numbers
Integer Operations Computer Organization and Assembly Language: Module 5.
Chapter 8 Computer Arithmetic. 8.1 Unsigned Notation Non-negative notation  It treats every number as either zero or a positive value  Range: 0 to 2.
Chapter 6. Digital Arithmetic: Operations and Circuits
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
William Stallings Computer Organization and Architecture 8th Edition
REGISTER TRANSFER AND MICROOPERATIONS
COMPUTER ARITHMETIC Arithmetic with Signed-2's Complement Numbers
Addition and Subtraction
Prof. Sin-Min Lee Department of Computer Science
Chapter 4 Operations on Bits.
REGISTER TRANSFER AND MICROOPERATIONS
Chapter 4 Register Transfer and Microoperations
Digital Arithmetic Wen-Hung Liao, Ph.D..
Chap 7. Register Transfers and Datapaths
Unit -2 ARITHMETIC.
Wakerly Section 2.4 and further
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
King Fahd University of Petroleum and Minerals
Computer Organization and Design
Multiprocessor & Multicomputer
EE207: Digital Systems I, Semester I 2003/2004
ECEG-3202 Computer Architecture and Organization
By: A. H. Abdul Hafez CAO, by Dr. A.H. Abdul Hafez, CE Dept. HKU
Arithmetic Logic Unit A.R. Hurson Electrical and Computer Engineering Missouri University of Science & Technology A.R. Hurson.
Chapter3 Fixed Point Representation
Instruction execution and ALU
Computer Architecture
Presentation transcript:

C OMPUTER A RITHMETIC

I NTRODUCTION A processor has an separate unit that is known as ALU that executes arithmetic operations. Negative numbers may be in a signed magnitude or signed complement representation. There are three ways of representing negative fixed point – binary numbers signed magnitude, signed 1’s complement or signed 2’s complement Most computers use the signed magnitude representation for the mantissa.

A DDITION AND S UBTRACTION WITH S IGNED –M AGNITUDE D ATA If we designate the magnitude of the two numbers by A and B. Where the signed numbers are added or subtracted, then there are eight different conditions to consider, and depending on the sign of the numbers the operation performed. These conditions are-

A DDITION AND S UBTRACTION WITH S IGNED –M AGNITUDE D ATA Operation Add magnitude Subtract Magnitude When A>BWhen A<BWhen A=B (+A) + (+B)+(A + B) (+A) + (-B)+ (A – B)- ( B – A)+ (A – B) (-A) + ( +B)- (A – B)+ ( B – A)+ ( A – B) (-A) + (-B)-(A + B) (+A) - (+B)+ ( A – B)- (B – A)+ ( A – B) (+A) - (-B)+( A + B) (-A) - ( +B)- (A + B) (-A) - (-B)-( A – B)+ (B – A) + (A – B)

A LGORITHM : A DDITION AND S UBTRACTION WITH S IGNED -M AGNITUDE D ATA - When the signs of A and B are same, add the two magnitudes and attach the sign of result is that of A. When the signs of A and B are not same, compare the magnitudes and subtract the smaller number from the larger. Choose the sign of the result to be the same as A, if A > B or the complement of the sign of A if A < B. If the two magnitudes are equal, subtract B from A and make the sign of the result will be positive.

H ARDWARE I MPLEMENTATION Let A and B be two registers that hold the magnitudes of the numbers, and As and Bs be two flip flops that hold the corresponding signs. The result of the operation may be transferred to a third register. The hardware implementation of above algorithm requires following- A parallel ADDER to performs micro operation A+B. A comparator circuit to establish A>B, A=B or A<B. Two parallel-subtractor circuits to perform the micro operation A-B and B-A. The sign relationship can be determined from an XOR gate with As and Bs as input.

A DDITION AND S UBTRACTION WITH S IGNED -M AGNITUDE D ATA The signs use an exclusive OR gate where if the output is 0, then the signs are the same. Hence, add the magnitudes of the same signed numbers. If the sum is an overflow, then a carry is stored in E where E = 1 and transferred to the flip- flop AVF, add-overflow. Otherwise, the signs are opposite and subtraction is initiated and stored in A. No overflow can occur with subtraction so the AVF is cleared. If E = 1, then A > B. However, if A = 0, then A = B and the sign is made positive. If E = 0, then A < B and sign for A is complemented.

H ARDWARE I MPLEMENTATION FOR SIGNED MAGNITUDE ADDITION AND SUBTRACTION B Register Complementer Parallel Adder A Register Bs AVF E As M (Mode control) Input carry Load sum Output Carry

F LOW C HART FOR A DD S UBTRACT

E XAMPLE : SIGNED MAGNITUDE A= +7  B= +8  As=0Bs =0 For Addition A+B As Ex-OR Bs 0 Ex-OR 0=0 EA=A+ B EA=1111 AVF=0 As= 0 A=1111  15

E XAMPLE : A DDITION A= +10  B= -12  As=0Bs=1 As Ex-OR Bs=1 If we are adding A + B and sigs are different then it will be subtraction A-B So we will convert the subtrahend in 2’s comp form 1100  0100 E=0 No carry A<B 1010As=comp of As= A=2’s comp of A=

S UBTRACTION 7-5=2 Binary of 7= To subtract 5 from 7 we have to convert it into 2’s comp form Binary of 5= ’s comp  = if an end carry is produced it means A>=B and we are subtracting a smaller no. from a bigger no. 1’s comp of (0101)  = 1011

A NOTHER EXAMPLE 5-7 Binary of 5= To subtract 7 from 5 we have to convert it into 2’s complement form Binary of 7 = ’s comp of 7  If we are performing A-B and A<B then no carry will be produced.

A DD AND SUBTRACT USING 2’ S COMPLEMENT Register BR Complementer and parallel adder Register A V

A LGORITHM FOR ADDING AND SUBTRACTING NUMBERS IN SIGNED -2’ S C OMPLEMENT REPRESENTATION

Addition of two numbers in 2’s complement from consists of adding the number with sign bit treated the same as other bits of a number. A carry over of the sign bit position is discarded. In subtraction first take the 2’s complement of second number and added to the first number. when two numbers of n digits each are added and sum occupies n+1,we say that an overflow occurred. An overflow can be detected by inspecting the last two carries out of the addition. The over flow flip flop V is set to 1 if there is an over flow.the output carry in this case is discarded.

M ULTIPLICATION ALGORITHM

The process consists of looking at successive bits of the multiplier, LSB first. If the multiplier bit is 1, the multiplicand is copied down otherwise, zeros are copied down. The copied down in successive lines are shifted on position to the left from the previous number. Finally the numbers are added and their sum forms the product. The sign of the product is determined from the signs of the multiplicand and multiplier. If they are same the sign of the product is positive. If they are unlike, the sign of the product is negative.

Instead of as many number of registers as there are bits in multiplier, it is convenient to provide an adder for the summation of only two successive binary numbers. Instead of shifting the multiplicand to the left, the partial product will be shifted to the right. When the corresponding bit of multiplier is 0, there is no need to add all zeros to the partial product.

E XAMPLE X  shifting the bits of multiplicand left OR first right shift the partial product  partial product is shifted to the left 10011

A RITHMETIC SHIFT OPERATION An arithmetic shift is a micro-operation that shifts a signed binary number to the left or right. An arithmetic shift-left multiplies a signed number by 2 and an arithmetic shift-right divides the number by 2. Arithmetic shift must leave the sign bit unchanged because the sign of the number remains the same when it is multiplied or divided. The left most bit in a register holds the sign bit and remaining bits hold the number.

T HE HARDWARE IMPLEMENTATION FOR MULTIPLY OPERATION

A LGORITHM -  The multiplicand is in register B and multiplier is in Q. The SC is initially set a number equal to the number of bits in multiplier.  The counter is decremented by 1 after forming each partial product.  The sum of A and B forms a partial product which is transferred to the EA register.  Both the partial product and multiplier are shifted to the right. shrEAQ.  The LSB of A is shifted into MSB of Q, The bit from E is shifted into MSB of A, and 0 is shifted into E.  In this manner the right most bit of the multiplier will be the one which must be inspected next.

E XAMPLE - Problem: Find the multiplication of and Solution: Let us consider that the value of multiplicand in B is = and value of multiplier in Q is = Then; initially we take the value for the following: register, E=0 register, A=00000 sequence counter, SC = n = 5 = where, n is the number of digits of the binary numbers.

S OLUTION - Multiplicand B=11001 EAQSC Multiplier in Q (5) Qn=1; Add B11001 Partial product Shift Right EAQ (4) Qn=1; Add B11001 Partial product Shift Right EAQ (3) Qn=0; ShR EAQ (2) Qn=0; ShR EAQ (1) Qn=1; Add B11001 Partial product Shift Right EAQ (0) Final Product in AQ=

A NOTHER EXAMPLE FOR BINARY MULTIPLIER -

B OOTH M ULTIPLICATION  Employs 2’s complement scheme to represent ALL signed binary integers. Means, works on both positive and negative numbers.  Reduces number of multiplication steps.  Uses both ADD & Subtract as well as right shift arithmetic.  It operates on the fact that strings of 0’s in the multiplier require no addition but just shifting, and a string of 1’s in the multiplier from bit weight 2 k to weight 2 m can be treated as 2 k m

A LGORITHM -  Booth algorithm needs examination of the multiplier bits and shifting of the partial product.  Prior to the shifting, the multiplicand added to the partial product, subtracted from the partial product, or left unchanged by the following rules-  The multiplicand is subtracted from the partial product when we get the first least significant 1 in a string of 1's in the multiplier.  The multiplicand is added to the partial product when we get the first Q (provided that there was a previous 1) in a string of 0's in the multiplier.  The partial product does not change when the multiplier bit is the same as the previous multiplier bit.

H ARDWARE IMPLEMENTATION FOR BOOTH MULTIPLICATION BR Register Complementer and parallel Adder AC RegisterQR Register Qn Sequence Counter (SC) Qn +1

F LOW C HART OF BOOTH MULTIPLICATION

E XAMPLE - Problem: Find the multiplication of and using booth multiplication. Solution: Lets BR=11001 and QR=10011 Then; initially Qn+1=0 AC=00000 SC=5(no of digits)=101

S OLUTION - QnQn Q n+1 BR=10111 BR’+1=01001 ACQRQ n+1 SC Initial (5) 10Sub BR01001 ashr (4) 11ashr (3) 01Add BR ashr (2) 00ashr (1) 10Sub BR ashr (0)