1

I'm trying to create a modules that simulates 4-bit multiplier without using multiplication (*) , need just to use Half and Full adders , so I succeeded to program the solution from some instance , this is the code :

module HA(sout,cout,a,b);
output sout,cout;
input a,b;
assign sout = a^b;
assign cout = (a&b);
endmodule

module FA(sout,cout,a,b,cin);
output sout,cout;
input a,b,cin;
assign sout =(a^b^cin);
assign cout = ((a&b)|(a&cin)|(b&cin));
endmodule

module multiply4bits(product,inp1,inp2,clock,reset,load);
output [7:0]product;
input [3:0]inp1;
input [3:0]inp2;
input clock;
input reset;
input load;

wire x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17;    
always @ (posedge clock )
begin
        if(reset == 1)
            begin
            // something to reset
            end
        else if (load == 1)
            begin
               product[0] = (inp1[0]&inp2[0]);
               HA HA1(product[1],x1,(inp1[1]&inp2[0]),(inp1[0]&inp2[1]));
                FA FA1(x2,x3,(inp1[1]&inp2[1]),(inp1[0]&inp2[2]),x1);
                FA FA2(x4,x5,(inp1[1]&inp2[2]),(inp1[0]&inp2[3]),x3);
                HA HA2(x6,x7,(inp1[1]&inp2[3]),x5);
                HA HA3(product[2],x15,x2,(inp1[2]&inp2[0]));
                FA FA5(x14,x16,x4,(inp1[2]&inp2[1]),x15);
                FA FA4(x13,x17,x6,(inp1[2]&inp2[2]),x16);
                FA FA3(x9,x8,x7,(inp1[2]&inp2[3]),x17);
                HA HA4(product[3],x12,x14,(inp1[3]&inp2[0]));
                FA FA8(product[4],x11,x13,(inp1[3]&inp2[1]),x12);
                FA FA7(product[5],x10,x9,(inp1[3]&inp2[2]),x11);
                FA FA6(product[6],product[7],x8,(inp1[3]&inp2[3]),x10); 
            end                 
end 

endmodule

The problem is that I get a lot of errors from the lines inside the condition if(load == 1) when I test the code. here are the errors :

Line 34: Procedural assignment to a non-register product is not permitted, left-hand side should be reg/integer/time/genvar

Line 35: Instantiation is not allowed in sequential area except checker instantiation
Line 36: Instantiation is not allowed in sequential area except checker instantiation 
Line 37: Instantiation is not allowed in sequential area except checker instantiation
.
.
Line 46: Instantiation is not allowed in sequential area except checker instantiation

If I remove the always @ .. and write the code outside of it the code works perfectly ! but i must use the clock in order to get this code work just on load = 1 .

If anyone can help me I'll be very thankful .

3
  • I'm not sure what you're trying to do now, but you want to do this: upload.wikimedia.org/wikipedia/commons/1/1e/… (the boxes say controllable adder, i.e. if m0 is false then the input bi are disabled and null)
    – dom0
    Dec 30, 2013 at 15:45
  • Okey lets say I won't put them inside the always block , but I want them to occur just when load = 1 , so how I do the condition ? this is my main problem ..
    – AmirM86
    Dec 30, 2013 at 15:54
  • Verilog is used to design hardware. Saying that you want them to "occur just when load = 1" is nonsense because it says you want the hardware to change while it's running. You must change your way of thinking about Verilog and hardware design.
    – user1619508
    Dec 30, 2013 at 18:25

1 Answer 1

1

You can also do this way:

module mul4(ans,aa,bb,clk,load,);

input [3:0]aa,bb;
input load,clk;
output [7:0]ans;

reg rst;

always @(posedge clk)  
    begin 
        if(load)
            rst=0; 
        else
            rst=1;
    end

multiply4bits mm(ans,aa,bb,cl,rst);

endmodule 


module multiply4bits(product,inp1,inp2,clock,reset);

output [7:0]product;
input [3:0]inp1;
input [3:0]inp2;
input clock;
input reset;

wire x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17;    

assign product[0]= (inp1[0]&inp2[0]);             
HA HA1(product[1],x1,(inp1[1]&inp2[0]),(inp1[0]&inp2[1]));
FA FA1(x2,x3,(inp1[1]&inp2[1]),(inp1[0]&inp2[2]),x1);
FA FA2(x4,x5,(inp1[1]&inp2[2]),(inp1[0]&inp2[3]),x3);
HA HA2(x6,x7,(inp1[1]&inp2[3]),x5);
HA HA3(product[2],x15,x2,(inp1[2]&inp2[0]));
FA FA5(x14,x16,x4,(inp1[2]&inp2[1]),x15);
FA FA4(x13,x17,x6,(inp1[2]&inp2[2]),x16);
FA FA3(x9,x8,x7,(inp1[2]&inp2[3]),x17);
HA HA4(product[3],x12,x14,(inp1[3]&inp2[0]));
FA FA8(product[4],x11,x13,(inp1[3]&inp2[1]),x12);
FA FA7(product[5],x10,x9,(inp1[3]&inp2[2]),x11);
FA FA6(product[6],product[7],x8,(inp1[3]&inp2[3]),x10); 

endmodule


module HA(sout,cout,a,b);

output sout,cout;
input a,b;

assign sout = a^b;
assign cout = (a&b);

endmodule


module FA(sout,cout,a,b,cin);

output sout,cout;
input a,b,cin;

assign sout =(a^b^cin);
assign cout = ((a&b)|(a&cin)|(b&cin));

endmodule

Hope it'll help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.