Thursday, December 29, 2011

MULTIPLICATION OF 2-SIGNED 8-BIT NUMBERS IN 2’S COMPLEMENT


MULTIPLICATION OF 2-SIGNED 8-BIT NUMBERS IN 2’S COMPLEMENT

AIM:
            To multiply two signed 8-bit numbers using 2’s complement.
APPARATUS REQUIRED:
·        PC
·        Xilinx ISE software.
PROCEDURE:
·        Assign the clock input to clock,and set  the values to multiplier and multiplicand.
·        Check the multiplier and multiplicand are positive then do the successive addition for product.
·        Otherwise multiplier is positive and multiplicand is negative then do the successive addition.MSB is replaced by 1 instead of zero.
·        If multiplier is negative and multiplicand is positive then take 2’s complement of multiplicand and do the successive addition for that multiplicand.
·        If both multiplier and multiplicand are negative then take 2’s complement of multiplicand and do successive addition but MSB is replaced by 1 instead of zero.
PROGRAM:
                        Module mul-8- bit (clk,mr,md,p);
                             input clk;
                             input [7:0] Mr.;
                             input [7:0] md;
                            Output [15:0] p;
                            Output [15:0] p;
                            Reg [4:0] sig=5’b 00000;
                              reg [8:0]md=9’b 000000000;
                             reg [16:0]qu=17’b00000000000000;
                             reg [16:0]pq=17’b00000000000000000;
                            always @ (posedge clk)
begin,
                            if (mr[7]=1’b0)+(md[7]=1’b0) begin
                            if (sig<= 5’b00000) begin
                            qo<={9’b000000000,mr};
end
                          else if (qo[0]=I’bo) begin
                          pq<=qo;
end
                         qo<={I’bo,pq[16:17]};
end
                       else begin
                       p<=qo [15:0];
                       sig <=5,b00000;
end
                       sig <=sig+1;
end
                      else if((mf[7]==ib0)+(md[7]==ib1))
begin
                     if (sig==5’b00000)begin
                     qo<={9’b000000000,mr};
end
                     else if (sig<=5’b10000)begin
                     if(qo[[0]==1’b1)begin
                    pq<=qo+{1’b1,md,8’b00000000};
end
                   else if(qo[0]==1’b0)begin
                   pq<=qo;
end
                  qo=<{1’bo,pq(16:1)};
end
                  else begin
                  p<=qo[15:0]+{md com [7:0];8’b 00000000};
                  sig<=5’b00000;
end
                  sig<=sig+1;
end
                  else begin
                 md com<=100000000-{1’bo,md};
                 if(sig==5’b 00000}begin
                 qo<={9’b 000000000,mr};
end
                 else if (sig<=5’b 10000) begin
                 if(qo[0]==1’b1)begin
                 pq<=qo+{1’b1,md,8’b 00000000};
end
                else if (qo[0]==1’bo) begin
                pq<=qo;
end
               qo<={1’b1,pq[16:1]};
end
               else begin
               p<=qo[15:0]+{md co [7:0],8’b 00000000};
               sig<=5’b 00000;
end
               sig<=sig+1;
end
end
end module

UCF:
NET “CLK”            LOC=”A8”;
NET”md<0>”       LOC=”J11”;
NET”md<1>”       LOC=”j12”;
NET” md<2>        LOC=”k4”;
NET” md<3>        LOC=”m3”;
NET” md<3>        LOC=”m7”;
NET”md<5>”       LOC=”m13”;
NET”md<6>”       LOC=”n3”;
NET”md<7>”       LOC=”n11”;
NET”mr<0>”        LOC=”r3”; 
NET”mr<1>”        LOC=”n1”;
NET”mr<2>”        LOC=”g12”;
NET”mr<3>”        LOC=”t2”;
NET”mr<4>”        LOC=”t7”;
NET”mr<5>”        LOC=”t9”;
NET”mr<6>”        LOC=”t12”;
NET”mr<7>”        LOC=”t14”;
NET”P<0>”           LOC=”p14”;
NET”P<1>”           LOC=”t13”;
NET”P<2>”           LOC=”r13”;
NET”P<3>”           LOC=”p13”;
NET”p<4>”          LOC=”n12”;
NET”P<5>”          LOC=”n9”;
NET”P<6>”          LOC=”P12”;
NET”P<7>”          LOC=”n10”;
NET”P<8>”          LOC=”r10”;
NET”P<9>”          LOC=”t8”;
NET”P<10>”        LOC=”r6”;
NET”P<11>”        LOC=”t5”;
NET”P<12>”        LOC=”t4”;
NET”P<13>”        LOC=”k3”;
NET”P<14>”        LOC=”r2”;
NET”P<15>”        LOC=”r1”;

RESULT: 
                 Thus the multiplication of 2 signed 8-bit numbers using 2’s complement is done and the output is verified.

No comments:

Post a Comment