verilog - Verilog 数组偏移
问题描述
module inst_mem(inst_out, pc_addr_out, clk, rstb);
output reg [31:0] inst_out;
input clk, rstb;
input [7:0] pc_addr_out;
reg [31:0] array[7:0];
//integer n = 0;
initial begin
array[0] <= 32'b00001111000011110000111100001111;
array[1] <= 32'b00011111000011110000111100001111;
array[2] <= 32'b00101111000011110000111100001111;
array[3] <= 32'b00111111000011110000111100001111;
array[4] <= 32'b01001111000011110000111100001111;
array[5] <= 32'b01011111000011110000111100001111;
array[6] <= 32'b01101111000011110000111100001111;
array[7] <= 32'b01111111000011110000111100001111;
end
always @(posedge clk or negedge rstb)
if (!rstb)
inst_out <= 32'd0;
else begin
inst_out <= array[pc_addr_out];
// inst_out <= array[n];
end
endmodule
我为指令存储器编写代码,我发现当我访问具有这样的 reg 类型的数组时,第一个时钟被延迟
inst_out <= array[pc_addr_out];
但是当我使用整数类型'n'访问arry
inst_out <= array[n];
它工作正常。所以,我想访问整数类型的数组,但我不知道。我尝试像 C 语言一样进行转换,但它不起作用。有什么好方法可以将 reg 类型更改为 int 类型?
解决方案
问题在于输入和输出的时间,而不是类型。您的内存是 ROM,它应该只是组合逻辑,不需要时钟或复位。
module inst_mem(
output wire [31:0] inst_out,
input wire [7:0] pc_addr_out
);
reg [31:0] array[7:0];
initial begin
array[0] <= 32'b00001111000011110000111100001111;
array[1] <= 32'b00011111000011110000111100001111;
array[2] <= 32'b00101111000011110000111100001111;
array[3] <= 32'b00111111000011110000111100001111;
array[4] <= 32'b01001111000011110000111100001111;
array[5] <= 32'b01011111000011110000111100001111;
array[6] <= 32'b01101111000011110000111100001111;
array[7] <= 32'b01111111000011110000111100001111;
end
assign inst_out <= array[pc_addr_out];
end
endmodule
推荐阅读
- java - 手牌和扑克牌之间的 Dack/Card 阵列复制
- php - 如何将 PHP 类数据传递给 $this 中的另一个类?
- c# - 如何在等待 Web 响应时更新 Windows 窗体文本框值
- kubernetes - 无法在 gcp 入口中打开 swagger 文档
- sql-server - SQL Server SQLCMD 模式 :setvar 的大小限制是多少?
- python - 将字符串拆分为二维数组python
- c - 数组不打印其中的第一个字母
- linux - 在bash中删除具有条件的类似目录
- opengl - GLSL 阴影映射:shadow2DProj 导致渲染伪影
- azure - 无法使用 Azure CLI 模板创建 SendGrid 资源 - “提供的订阅标识符无效”