我正在Verilog设计一个加法器.它将有两个大小为N和两个输出的输入.第一个输出的大小为2N,第二个的大小为K.
这是我到目前为止:
module adder(
out,
CCR,
inA,
inB
);
parameter N=8,CCR_size=8;
parameter M=2*N;
input [N-1:0] inA,inB;
output [M-1:0] out;
output [CCR_size-1:0] CCR;
reg [N:0] temp;
always @(inA or inB)
begin
temp = inA+inB;
CCR[0] = temp[N];
out[N-1:0]= temp[N-1:0];
out[M-1:N]= 'b0;
end
endmodule
Run Code Online (Sandbox Code Playgroud)
从评论中移出: 但是这没有编译.我有错误
CCR[0],out[N-1:0] and out[M-1:N]
# Error: VCP2858 adder.v : (16, 20): CCR[0] is not a valid left-hand side of a procedural assignment.
# Error: VCP2858 adder.v : (17, 28): out[N-1:0] is not a valid left-hand side of a procedural assignment.
# Error: VCP2858 adder.v : (18, 20): out[M-1:N] is not a valid left-hand side of a procedural assignment.
Run Code Online (Sandbox Code Playgroud)
上面的代码有什么问题?
寄存器数据类型用作过程块中的变量.当信号位于程序分配的左侧时,必须使用寄存器数据类型.由于默认类型的端口是wire您收到错误.将输出端口更改为类型reg可以解决问题.
output reg[M-1:0] out;
output reg[CCR_size-1:0] CCR;
Run Code Online (Sandbox Code Playgroud)