题解 | ROM的简单实现

ROM的简单实现

https://www.nowcoder.com/practice/b76fdef7ffa747909b0ea46e0d13738a

`timescale 1ns/1ns
module rom(
	input clk,
	input rst_n,
	input [7:0]addr,
	
	output [3:0]data
);
//rom是组合逻辑访问
reg [3:0] mem[7:0];
reg [3:0] output_data;

assign data = output_data;

always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
        mem[0] <= 4'd0;
        mem[1] <= 4'd2;
        mem[2] <= 4'd4;
        mem[3] <= 4'd6;
        mem[4] <= 4'd8;
        mem[5] <= 4'd10;
        mem[6] <= 4'd12;
        mem[7] <= 4'd14;
		output_data <= 'd0;
    end
end
always @(*)begin
	output_data <= mem[addr];
end
endmodule

全部评论

相关推荐

阿武同学:基本信息保留前面三行,其他的可以全部删掉,邮箱最重要的你没写,主修课程精简到8个以内,实习里面2/3/4都是水内容的,非要写的话建议两到三句话,项目经历排版优化下,自我评价缩到三行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务