cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Visitor
Visitor
246 Views
Registered: ‎11-24-2020

verilog

module paramod(a, b, cin, sum, cout);
parameter N=1;
input [N-1:0] a, b;
input cin;
output [N-1:0] sum;
output cout;
reg [N-1:0] sum;
reg [N-1:0] p;
reg [N:0] carry;
integer i;

always @ (a or b or cin) begin
carry[0] = cin
for (i=0; i<N; i=i+1) begin
p[i] = a[i] ^ b[i];
sum[i] = p[i] ^ cin;
case(p)
0: carry[i+1] = a[i];
1: carry[i+1] = cin;
endcase
end
end
assign cout = carry[N];
endmodule

 

module add_6b(a,b,sum,cout);
parameter N=6
input [5:0] a, b;
output [5:0] sum;
output cout;
paramod # (N) U0 paramod(.a(a), .b(b), .cin(1'b0), sum(sum), .cout(cout));

endmodule

 

red = error

 

Please let me know why the error occurred. With the code, if you can.

Thank you in advance. With your help.

0 Kudos
Reply
1 Reply
Contributor
Contributor
226 Views
Registered: ‎11-25-2019

Hi @jetleetop,

First problem is that you should change:

"module paramod(a, b, cin, sum, cout);
parameter N=1;"

Because if you want to say "paramod # (N) U0 paramod(.a(a), .b(b), .cin(1'b0), sum(sum), .cout(cout));", you should write:

"module paramod # (parameter N= 1) (a, b, cin, sum, cout);" and please name your port map without blank spaces like U0 paramod. You can name is as "U0_paramod". 

You should put ";" after "parameter N= 6". This is another problem.

For case selection part, you should add "default:" under "1: carry[i+1] = cin;".

 

Finally, you should not post your code like this, you should also write your errors in the message part. In this way, we can help you faster and better.

Good luck,

Yunus.