通过Verilog中的别名写入reg的位域

时间:2017-08-05 04:41:20

标签: verilog

我有一个注册:

reg [7:0] dout; //output of memory bus

dout中的位组表示有意义的内容,如:

  • dout [2:0]是州
  • dout [3]是一面旗帜
  • dout [7:4]是一些数据

我想从always语句中读取和写入这个寄存器dout。我想用这些标签来解决它。 这个例子传达了我的尝试:

reg [7:0] dout; //output of memory bus

wire [2:0] dout_state;
wire dout_flag;
wire [3:0] dout_data;

//alias labels
assign dout_state[2:0] = dout[2:0];
assign dout_flag = dout[3];
assign dout_data = dout[7:4];

always(@posedge clk) begin
    dout_state <= 3'b1;
    dout_flag <= 1'b1;
end

程序分配失败,因为dout_state和dout_flag是连线。

我希望这些标签能够作为代表dout总线部分的别名。

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

The always block already drives dout_state and dout_flag signals, so the other assignments should be reversed. Your current code never drives dout.

//alias labels
assign dout[2:0] = dout_state;
assign dout[3] = dout_flag;
assign dout[7:4] = dout_data;

Now the signal definitions also should be updated. If dout is a port, the reg definition should be removed. If not, it should be a wire.

wire [7:0] dout; //output of memory bus

Because of the always block, dout_state and dout_flag signals should be reg.

reg [2:0] dout_state;
reg dout_flag;