0% found this document useful (0 votes)
7 views

Program 2

The document describes an implementation of Booth's multiplication algorithm in C code. It includes the full source code to multiply two 8-bit integers using Booth's algorithm. The code displays the multiplicand, multiplier, and each step of the Booth's cycle in binary. It then prints the product in binary and decimal formats.

Uploaded by

Paresh Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Program 2

The document describes an implementation of Booth's multiplication algorithm in C code. It includes the full source code to multiply two 8-bit integers using Booth's algorithm. The code displays the multiplicand, multiplier, and each step of the Booth's cycle in binary. It then prints the product in binary and decimal formats.

Uploaded by

Paresh Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Computer Programming Lab - F.Y. B. Tech.

(Sem II)

Practical No.2

Implementation of Booth’s Algorithm

Program :
#include<stdio.h>
#include<conio.h>
void disp_binary(int x)
{
int masks[16]={0x8000,0x4000,0x2000,0x1000,
0x0800,0x0400,0x0200,0x0100,
int i;
for(i=0;i<16;i++)
if((x & masks[i])==0)
printf("0");
else
printf("1");
}
void main()
0x0080,0x0040,0x0020,0x0010,
0x0008,0x0004,0x0002,0x0001};
{
Computer Programming Lab - F.Y. B. Tech. (Sem II)

int acq,m,q_1,i,q_0;
printf("\nEnter multiplicant(-128 to 127): ");
scanf("%d",&m);
printf("Multiplicant in Binary: ");
disp_binary(m);
printf("\nEnter multiplier(-128 to 127): ");
scanf("%d",&acq);
printf("Multiplier in Binary: ");
disp_binary(acq);
acq=(acq & 0x00ff);
q_1=0;
printf("\n");
disp_binary(acq);
printf("%d",q_1);
printf("Booths Cycle:\n");
for(i=0;i<8;i++)
{
}
q_0=acq & 0x0001;
if(q_0==1 && q_1==0)
acq=acq - (m<<8);
else
Computer Programming Lab - F.Y. B. Tech. (Sem II)

if(q_0==0 && q_1==1)


acq=acq + (m<<8);
q_1=(acq & 0x0001);
acq=(acq>>1);
printf("\n");
disp_binary(acq);
printf("%d",q_1);
printf("\nProduct = %d",acq);
printf("\n");
disp_binary(acq);
}

Output :
Enter multiplicant(-128 to 127): -7
Multiplicant in Binary: 1111111111111001
Enter multiplier(-128 to 127): -3
Multiplier in Binary: 1111111111111101
00000000111111010Booths Cycle:
00000011111111101
Computer Programming Lab - F.Y. B. Tech. (Sem II)

11111110011111110
00000010101111111
00000001010111111
00000000101011111
00000000010101111
00000000001010111
00000000000101011
Product = 21
0000000000010101 --------------------------------
Process exited after 6.64 seconds with return value 49
Press any key to continue . . .

You might also like