I was implementing a basic binary adder in Verilog. From my limited understanding, the following should add two 16-bit values:
module ADD(X, Y, Z);
input[15:0] X;
input[15:0] Y;
output Z[15:0];
wire C[15:0];
assign C[0] = 0;
integer i;
for(i=1; i<16; i=i+1) begin
assign C[i]=(X[i-1]&Y[i-1])|(X[i-1]&C[i-1])|(Y[i-1]&C[i-1]);
end
for(i=0; i<16; i=i+1) begin
assign Z[i]=X[i]^Y[i]^C[i];
end
endmodule
However, I get an error when I try to synthesize the above.
Error (10170): Verilog HDL syntax error at add.v(10) near text "for"; expecting "endmodule"
I'm not sure what is wrong with the code.
output [15:0] Z; wire [15:0] C = { (X&Y)|(X&C)|(Y&C) , 1'b0}; assign Z=X^Y^C;. If you don't need to demonstrate the full adder operations, then just sayassign Z=X+Y;wire C [15:0], should bewire [15:0] C. They have different meanings. Working example [here]( edaplayground.com/x/U8) (ModelSim10.1d/Icarus0.10)