编译错误:Verilog 中的复制运算符
Error in compilation: Replication operator in Verilog
我正在为 16 位 ALU 编写 verilog 代码(行为)。我面临编译错误:
module alu_16bit(out,a,b,op);
output reg [15:0] out;
input [15:0] a,b;
input [2:0] op;
reg [15:0] e ;
reg [15:0] d ;
parameter op_add = 3'b000 ;
parameter op_sub = 3'b001 ;
parameter op_sl = 3'b010 ; // shift left
parameter op_sr = 3'b011 ; // shift right
parameter op_sar = 3'b100 ; // shift arithmetic right
parameter op_nand = 3'b101 ;
parameter op_or = 3'b110 ;
always @(*)
begin
case(op)
op_add : out <= a+b ;
op_sub : out <= a-b ;
op_nand : out <= ~(a&b) ;
op_or : out <= a|b ;
op_sr : out <= a >> b ;
op_sl : out <= a << b ;
op_sar : begin
if(b>16'd15)
out <= {16{a[15]}} ;
else
out <= {b{a[15]},a[15:b]} ;
end
default: out <= 4'bzzzz ;
endcase
end
endmodule
我在 op_sar 的这一行遇到编译错误:
out <= {b{a[15]},a[15:b]} ;
这是我收到的错误:
alu_16bit.v:65: error: Syntax error between internal '}' and closing '}' of repeat concatenation.
这一行
out <= {b{a[15]},a[15:b]} ;
不好有两个原因:
i) 我想你的意思是
out <= {{b{a[15]}},a[15:b]};
和
ii) {b{a[15]}}
和 [15:b]
都是非法的,因为 b
不是常量。
所以,正如您似乎想要 sign-extension 和 有符号算术 ,为什么不让 out
有符号并使用 >>>
(算术右移)运算符,它将为您处理 sign-extension?
我正在为 16 位 ALU 编写 verilog 代码(行为)。我面临编译错误:
module alu_16bit(out,a,b,op);
output reg [15:0] out;
input [15:0] a,b;
input [2:0] op;
reg [15:0] e ;
reg [15:0] d ;
parameter op_add = 3'b000 ;
parameter op_sub = 3'b001 ;
parameter op_sl = 3'b010 ; // shift left
parameter op_sr = 3'b011 ; // shift right
parameter op_sar = 3'b100 ; // shift arithmetic right
parameter op_nand = 3'b101 ;
parameter op_or = 3'b110 ;
always @(*)
begin
case(op)
op_add : out <= a+b ;
op_sub : out <= a-b ;
op_nand : out <= ~(a&b) ;
op_or : out <= a|b ;
op_sr : out <= a >> b ;
op_sl : out <= a << b ;
op_sar : begin
if(b>16'd15)
out <= {16{a[15]}} ;
else
out <= {b{a[15]},a[15:b]} ;
end
default: out <= 4'bzzzz ;
endcase
end
endmodule
我在 op_sar 的这一行遇到编译错误:
out <= {b{a[15]},a[15:b]} ;
这是我收到的错误:
alu_16bit.v:65: error: Syntax error between internal '}' and closing '}' of repeat concatenation.
这一行
out <= {b{a[15]},a[15:b]} ;
不好有两个原因:
i) 我想你的意思是
out <= {{b{a[15]}},a[15:b]};
和
ii) {b{a[15]}}
和 [15:b]
都是非法的,因为 b
不是常量。
所以,正如您似乎想要 sign-extension 和 有符号算术 ,为什么不让 out
有符号并使用 >>>
(算术右移)运算符,它将为您处理 sign-extension?