Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Assigning values to an array in Verilog

Status
Not open for further replies.

bcdeforest

Newbie level 1
Joined
Oct 31, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,287
I have an output "SUM". I need to assign 4 values into its array. Here is my attempt.

Code:
module part4b(A,B,Cin,S,Cout,SUM,V);
input [3:0]A,B;
input [1:0]S;
input Cin;
output [3:0]SUM;
output Cout,V;
reg [3:0]SUM;
reg Cout,V;
wire w1,w2,x1,x2,y1,y2,z1,z2;//Connecting wires to module
 
part4a a0(.A(A[0]),.B(B[0]),.Cin(Cin),.S(S),.SUM(w1),.Cout(w2));//Wire w2 connects a0 and a1 C
part4a a1(.A(A[1]),.B(B[1]),.Cin(w2),.S(S),.SUM(x1),.Cout(x2));//Wire x2 connects a1 and a2 C
part4a a2(.A(A[2]),.B(B[2]),.Cin(x2),.S(S),.SUM(y1),.Cout(y2));//Wire y2 connects a2 and a3 C
part4a a3(.A(A[3]),.B(B[3]),.Cin(y2),.S(S),.SUM(z1),.Cout(z2));//Wire w2 is output Cout
assign SUM[0] = w1;//THESE RIGHT HERE<<
assign SUM[1] = x1;
assign SUM[2] = y1;
assign SUM[3] = z1;
endmodule

- - - Updated - - -

The error I get is, "Object "SUM" on left-hand side of assignment must have an net type"
 

assign can not be performed on a variable of type reg.
1. change the declaration of reg [3:0] SUM; to wire [3:0] SUM;
2. remove the reg declaration of SUM entirely as it's already declared by output [3:0] SUM;

Regards,
-alan
 

BTW, you are using a very old style of Verilog port declarations where you list the identifiers twice or even three times if you need to declare an output as reg. You should use this:

Code:
module part4b(
input [3:0]A,B,
input Cin,
input [1:0]S,
output reg Cout,
output [3:0]SUM,
output reg V
);
Any port declared without a data type is implicitly a wire.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top