vivado指令寄存器+取指模块(含测试代码)

本篇文章使用Verilog语言编写实现指令寄存器和取指模块,含有设计代码和测试代码。

一、接口描述/程序框图

指令寄存器接口描述表:
指令寄存器接口描述表

取指模块程序框图:
取指模块程序框图

二、设计代码

(1)程序计数器设计代码
见之前发的程序计数器模块
(2)指令寄存器设计代码inst_rom.v

`timescale 1ns / 1ps
//`include "define.v"

module inst_rom(
    input wire ce,
    input wire [`InstAddrBus]addr,
    output reg [`InstBus]inst
    );
    reg [`InstBus] inst_mem[0:127];
    initial begin
        $readmemh("E:/exper/inst_rom.data",inst_mem);//此处地址改为自己的指令.data文件
    end
    always@(*)begin
        if(ce==`CeDisable)begin
            inst<=`ZeroWord;
        end
        else begin
            inst<=inst_mem[addr[31:2]];
        end
    end
endmodule

(3)取值模块设计代码inst_fetch.v

`timescale 1ns / 1ps

module inst_fetch(
    input wire rst,
    input wire clk,
    output wire [`InstBus]inst_o
    );
    wire [`InstAddrBus]pc;
    wire ce;
    pc pc0(clk,rst,pc,ce);
    inst_rom inst_rom0(ce,pc,inst_o);
endmodule

(4)宏定义文件define.v

`define InstBus 31:0
`define InstAddrBus 31:0
`define CeDisable 0
`define CeEnable 1
`define ZeroWord 0
三、测试代码

inst_fetch_tb.v

`timescale 1ns / 1ps

module inst_fetch_tb();
    reg rst;
    reg clk;
    wire [`InstBus] inst_o;
    inst_fetch inst_fetch0(rst,clk,inst_o);
     initial begin
        clk=1;
        forever #10 clk=~clk;
     end
     initial begin
        rst=0;
        #10
        rst=1;
        #100
        rst=0;
        #500
        $finish;
     end
endmodule
四、仿真波形图

仿真波形图

由波形图可得,当复位信号rst无效时,在每个时钟上升沿,取指模块向指令寄存器中读入文件中的指令

仅供学习交流,如发现错误,欢迎大家指正。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HePingxxb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值