0% found this document useful (0 votes)
47 views13 pages

Booth's Algorithm for Signed Multiplication

This document is a project report submitted by 5 students for their Master of Computer Application degree. It discusses signed magnitude multiplication using Booth's algorithm. The algorithm is presented through pseudocode and examples. It multiplies two signed binary numbers in two's complement form through a series of additions and shifts.

Uploaded by

anandan0
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views13 pages

Booth's Algorithm for Signed Multiplication

This document is a project report submitted by 5 students for their Master of Computer Application degree. It discusses signed magnitude multiplication using Booth's algorithm. The algorithm is presented through pseudocode and examples. It multiplies two signed binary numbers in two's complement form through a series of additions and shifts.

Uploaded by

anandan0
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Signed Magnitude Multiplication

A PROJECT REPORT

Submitted By

SESHADRI.A (10MCA0001) ABINAYA.E (10MCA0004) ADITI KOCHHAR (`10MCA0005) AISHWARYA.V (10MCA0006) ANANDAN.E (10MCA0008)

In partial fulfillment for the award of the degree of

MASTER OF COMPUTER APPLICATION

School Of Information Technology & Engineering April 2010

Sign-magnitude representation The sign-magnitude method is the simplest way of handling negative numbers - at least from a human the point view. The idea is to set aside one bit to store the sign of the integer (either + or -) and use the remaining N-1 bits to store the magnitude of the number. With 12 bits, this method allows representing integers from -(211-1) to +(211-1), that is, from -2047 to +2047. By convention, the leftmost bit is the sign bit, and a sign bit of 1 signifies a negative number. So in a 12-bit sign-magnitude system, 111111111111 represents -2047 100000000001 represents -1 100000000000 represents 0 (so-called negative 0) 000000000000 represents 0 (so-called positive 0) 000000000001 represents +1 011111111111 represents +2047 Note that there are two different representations for the number zero! These representations are called positive zero and negative zero, but it is important to remember that they represent the same number (they are mathematically equal) and that in mathematics, zero is neither positive nor negative. The problem of overflow persists. For example, 1400 + 1500 cannot be done correctly. Neither can (1400) + (-1500).

The sign-magnitude method is convenient for human users of data, but it presents a more difficult problem for the electrical engineers who must design the electronic circuits to do arithmetic computations. To add two numbers, two cases must be distinguished: the summands are of the same sign or of different signs. In the first case, the magnitudes must be added, and the result given the sign of the summands. In the second case, the smaller magnitude must be subtracted from the larger magnitude, and the result given the sign of the summand having the larger magnitude. So the engineer must incorporate in his circuit both an adder and a subtractor, and circuits to distinguish the various [Link] process is, of course, exactly the method taught in school for adding signed numbers by hand.

Multiply

Multiplicand in BR Multiplier in QR

AC Qn+1 SC

0 0 n

=10

Qn Qn+1

=01

AC

AC-BR+1

=00 =11

AC

AC+BR

ashr(AC & QR) SC SC - 1

=0

SC

END
FIG: Booths algorithms for multiplication of signed -2s complement numbers

Source Code:
#include<iostream.h> #include<math.h> #include<stdlib.h> void showmenu(); class ALU; class Operand { friend class ALU; int length; int bits[20]; public: Operand(int l) { length=l; for(int i=0;i<length;i++) bits[i]=0; } void setBits(int *p) { for(int i=0;i<length;i++) bits[i]=*(p+i); } void setBits(int *p,int k) { for(int i=0;i<length;i++) bits[i]=*(p+i+k); } void setBits() { cout<<"\nInsert bits of length "<<length<<":"; for(int i=0;i<length;i++) { if(getchar()-48==1) bits[i]=1; else if(getchar()-48==1) bits[i]=0; else {cout<<"\nInvalid data format!\n";break;} } } void dispBits() { for(int i=0;i<length;i++) cout<<bits[i]; }

int shr()// shift right, adding 0 from left { int pop=bits[length-1];

for(int i=length-1;i>0;i--) { bits[i]=bits[i-1]; } bits[0]=0; return pop; } int shl()// shift left, adding 0 from right { int pop=bits[0]; for(int i=0;i<length-1;i++) { bits[i]=bits[i+1]; } bits[length-1]=0; return pop; } int ashr()// shift right, maintaining leftmost bit { int pop=bits[length-1]; for(int i=length-1;i>0;i--) { bits[i]=bits[i-1]; } return pop; } int ashl()// shift left, maintaining rightmost bit { int pop=bits[0]; for(int i=0;i<length-1;i++) { bits[i]=bits[i+1]; } return pop; } int shr(int j)// shift right, with given first bit { int pop=bits[length-1]; for(int i=length-1;i>0;i--) { bits[i]=bits[i-1]; } bits[0]=j; return pop; } int shl(int j)// shift left, with given first bit { int pop=bits[0]; for(int i=0;i<length-1;i++) { bits[i]=bits[i+1];

} bits[length-1]=j; return pop; } void dtb(int n)//Decimal to Binary { if(n==0) for(int i=0;i<length;i++) bits[i]=0; else if(n==1) { for(int i=0;i<length;i++) bits[i]=0; bits[length-1]=1; } else if(n>(int)pow(2,length)||n*(-1)>(int)pow(2,length)) { cout<<"\nData Overflow!\n"; return; } else if(n>0) { int i=length-1; while(n!=0) { bits[i]=n%2; i--; n=n/2; } } else if(n<0) { n=n*-1; int i=length-1; while(n!=0) { bits[i]=n%2; i--; n=n/2; } for(int k=0;k<length;k++) { bits[k]=bits[k]==1?0:1; } int c=0; if(bits[length-1]==1) { bits[length-1]=0; c=1; } else

{ bits[length-1]=1; c=0; } for(k=length-2;k>0;k--) { if(bits[k]==1&&c==1) bits[k]=0; else { bits[k]+=c; c=0; } } } } void toComplement()//convert to 2's complement form { for(int k=0;k<length;k++) { bits[k]=bits[k]==1?0:1; } int c=0; if(bits[length-1]==1) { bits[length-1]=0; c=1; } else { bits[length-1]=1; c=0; } for(k=length-2;k>0;k--) { if(bits[k]==1&&c==1) bits[k]=0; else { bits[k]+=c; c=0; } } }

}; class ALU { public:

int adder(Operand *op1,Operand *op2) { int carry=0; for(int i=op1->length;i>=0;i--) { if(op1->bits[i]==1&&op2->bits[i]==1&&carry==0) { op1->bits[i]=0; carry=1; } else if(op1->bits[i]==1&&op2->bits[i]==0&&carry==1) { op1->bits[i]=0; carry=1; } else if(op1->bits[i]==0&&op2->bits[i]==1&&carry==1) { op1->bits[i]=0; carry=1; } else if(op1->bits[i]==1&&op2->bits[i]==1&&carry==1) { } else { op1->bits[i]=op1->bits[i]+op2->bits[i]+carry; carry=0; } } return carry; }

void multiplier(Operand *br,Operand *qr) { Operand *brc=new Operand(br->length);//2's complement of br brc->setBits(&(br->bits[0])); brc->toComplement(); Operand *ac=new Operand(br->length); int q=0; int sc=qr->length; cout<<"\nQn Qn+1 Operation "; for(int i=1;i<=(br->length-2)/2;i++) cout<<" "; cout<<"AC"; for(i=1;i<=(br->length+1);i++)

cout<<" "; cout<<"QR"; for(i=1;i<=(br->length)/2+1;i++) cout<<" "; cout<<"Qn+1 Sc"; cout<<"\n"<<qr->bits[qr->length-1]<<" "<<q<<" Initialization "; ac->dispBits(); cout<<" "; qr->dispBits(); cout<<" "<<q<<" "<<sc; while(sc!=0) { if(qr->bits[qr->length-1]==1&&q==0) { adder(ac,brc); cout<<"\n"<<qr->bits[qr->length-1]<<" "<<q<<" AC<-AC+(BR 2's comlement) "; ac->dispBits(); cout<<" "; qr->dispBits(); cout<<" "<<q<<" "<<sc; } else if(qr->bits[qr->length-1]==0&&q==1) { adder(ac,br); cout<<"\n"<<qr->bits[qr->length-1]<<" "<<q<<" AC<-AC+BR ac->dispBits(); cout<<" "; qr->dispBits(); cout<<" "<<q<<" "<<sc; } q=qr->shr(ac->ashr()); cout<<"\n"<<qr->bits[qr->length-1]<<" "<<q<<" shr(AC QR) ac->dispBits(); cout<<" "; qr->dispBits(); cout<<" "<<q<<" "<<sc; sc--; }cout<<"\n";

";

";

};

int main() {

ALU *alu1=new ALU(); int len,o1,o2; char as='y'; while(as=='y') { system("cls"); cout<<"\nEnter bit size:"; cin>>len; Operand *op1=new Operand(len); Operand *op2=new Operand(len); cout<<"\nEnter decimal value of operand1:"; cin>>o1; op1->dtb(o1); cout<<"\nEnter decimal value of operand1:"; cin>>o2; op2->dtb(o2); system("cls"); alu1->multiplier(op1,op2); system("pause"); cout<<"do you want do mulitiplication again? y / n"; cin>>as; } system("pause"); }

SCREEN SHOT:

Common questions

Powered by AI

Shifting operations in binary arithmetic are significant because they allow efficient multiplication or division by powers of two. A left shift operation is equivalent to multiplying the number by two for each shift, whereas a right shift divides the number by two. In terms of signed numbers, arithmetic shifts preserve the sign, making them particularly useful in scaling operations without altering the sign bit, thus maintaining the number's sign correctness throughout the operation. This use is crucial in optimizing algorithms like Booth's for multiplication .

Sign-magnitude representation handles negative numbers by using the left-most bit as the sign bit — where 1 indicates a negative number and 0 indicates a positive one. The remaining bits represent the magnitude of the number, allowing the representation of integers from -2047 to +2047 with 12 bits. This method presents challenges for arithmetic computations, particularly in adding numbers with different signs. It requires the use of both an adder and a subtractor circuit and cannot handle overflow correctly .

The key steps in converting a negative decimal integer to a 2's complement binary form involve: converting the absolute value of the integer to binary, inverting the bits (turning 0s to 1s and vice-versa), and adding 1 to the resulting binary number. This representation is preferred in computer systems because it simplifies arithmetic operations, particularly subtraction and addition, by using the same binary addition logic without requiring separate subtraction logic. It also has a unique representation for zero, avoiding the dual zero problem present in sign-magnitude representation .

Potential pitfalls of implementing Booth's algorithm in a hardware system include increased circuit complexity due to the need for control logic that accurately interprets bit patterns to select operations like addition, subtraction, or shift. It can also be susceptible to errors if bit pattern interpretation is not precisely managed. These issues can be mitigated by designing robust state machines that simplify control processes, ensure precise timing of operations, and incorporate redundancy checks to minimize the risk of misinterpretation or operational errors .

The pros of using sign-magnitude representation include simplicity for human users as it directly mirrors the way humans write negative and positive signs. However, it has significant cons, such as the existence of two representations for zero (positive and negative zero) and the complexity added to the electronic circuits for handling arithmetic operations, especially dealing with overflow .

Sign-magnitude representation poses a challenge for arithmetic operations because it requires circuits to handle both addition and subtraction, depending on the signs of the operands. This dual requirement increases circuit complexity as it must incorporate logic for determining the operation based on the sign and magnitude of operands. Moreover, handling two representations of zero adds to the complexity, as different logic paths might be necessary .

The multiplexer logic simplifies operations in the ALU's multiplier function by allowing the selection between different operations (addition, subtraction, no operation) based on the two current least significant bits of the multiplier and the carry or previous operation result stored in an additional bit. This logic reduces the number of operations needed, as it allows for successive arithmetic shifts and conditional additions, optimizing the process according to Booth's algorithm, which is implemented in this project through specific logical pathways in the ALU design .

Designing electronic circuits for arithmetic computations with sign-magnitude numbers is challenging because it requires distinguishing between cases where the numbers have the same sign and where they have different signs. This necessitates the inclusion of both an adder and subtractor in the circuit. Moreover, the designer must implement logic to determine whether to add or subtract based on the sign of the numbers, which increases the complexity of the circuitry .

The arithmetic right shift (ashr) involves shifting all bits of a binary number to the right while maintaining the leftmost bit. This is crucial for binary representations of signed numbers, as it preserves the sign during the shift. With signed numbers, the leftmost bit is the sign bit, and maintaining it ensures that negative numbers remain negative. This operation is integral in operations like multiplication by powers of two in signed numbers without changing their sign .

Booth's algorithm modifies the process of signed number multiplication by using a technique that simplifies and speeds up calculations. It handles multiplication by observing two-bit patterns to determine the operation that needs to be performed. These operations could include addition, subtraction, or shifting based on specific patterns in the multiplier bits. The primary advantage is the efficient handling of consecutive 1s, reducing the number of addition operations compared to standard binary multiplication, and implementing shifts which are less computationally intensive .

You might also like