当前位置:网站首页>verilog独热码实现译码MIPS指令集
verilog独热码实现译码MIPS指令集
2022-08-09 08:55:00 【面向01编程】
译码器端口说明
| 序号 | 接口名 | 宽度 | 输入/输出 | 作用 |
|---|---|---|---|---|
| 1 | rst | 1 | 输入 | 复位信号 |
| 2 | inst_i | 32 | 输入 | 译码阶段的指令 |
| 3 | reg1_data_i | 32 | 输入 | 从regfile读入数据1 |
| 4 | reg2_data_i | 32 | 输入 | 从regfile读入数据2 |
| 5 | aluop_o | 4 | 输出 | 译码阶段运算类型 |
| 6 | reg1_o | 32 | 输出 | 译码阶段源操作数1 |
| 7 | reg2_o | 32 | 输出 | 译码阶段源操作数2 |
| 8 | wd_o | 5 | 输出 | 目的寄存器地址,inst_i[15:11] |
| 9 | wreg_o | 1 | 输出 | 是否要写入目的寄存器 |
| 10 | reg2_addr_o | 5 | 输出 | 第二个寄存器地址,inst_i[20:16] |
| 11 | reg2_read_o | 1 | 输出 | regfile第二个寄存器读使能信号 |
| 12 | reg1_addr_o | 5 | 输出 | 第一个寄存器地址,inst_i[25:21] |
| 13 | reg1_read_o | 1 | 输出 | regfile第一个寄存器读使能信号 |
表2.2 译码器内部信号说明
| 序号 | 接口名 | 宽度 | 作用 |
|---|---|---|---|
| 1 | op | 6 | 对应inst_i[31:26],用于译码 |
| 2 | op2 | 5 | 对应inst_i[10:6],用于译码 |
| 3 | op3 | 6 | 对应inst_i[5:0],用于译码 |
| 4 | op4 | 5 | 对应inst_i[20:16] |
| 5 | imm | 32 | 立即数 |
| 6 | instvalid | 1 | 指令是否有效 |
表2.3译码阶段需要的信息
| 序号 | 信号 | 功能 |
|---|---|---|
| 1 | wreg_o | 是否要写寄存器 |
| 2 | aluop_o | 运算类型 |
| 3 | reg1_read_o | 是否读寄存器1 |
| 4 | reg2_read_o | 是否读寄存器2 |
| 5 | instvalid | 指令是否合法 |
| 6 | reg1_addr_o | 读寄存器地址1 |
| 7 | reg2_addr_o | 读寄存器地址2 |
`define FOURBYTE 31:0
`define ONEBYTE 3:0
`define ADD_OP 4'b0000
`define SUB_OP 4'b0001
`define SLT_OP 4'b0010
`define SLTU_OP 4'b0011
`define AND_OP 4'b0100
`define NOR_OP 4'b0101
`define OR_OP 4'b0110
`define XOR_OP 4'b0111
`define SLL_OP 4'b1000
`define SRL_OP 4'b1001
`define SRA_OP 4'b1010
`define LUI_OP 4'b1011
module id(
input rst,
input [`FOURBYTE] inst_i,
input [`FOURBYTE] reg1_data_i,
input [`FOURBYTE] reg2_data_i,
output [`ONEBYTE] aluop_o,
output [`FOURBYTE] reg1_o,
output [`FOURBYTE] reg2_o,
output [4:0] wd_o, //inst[15:11]
output wreg_o,
output [4:0] reg1_addr_o, //inst[25:21]
output reg1_read_o,
output [4:0] reg2_addr_o, //inst[20:16]
output reg2_read_o
);
wire [5:0] op = inst_i[31:26];
wire [5:0] func = inst_i[5:0];
wire [4:0] sa = inst_i[10:6]; //shamt
wire [4:0] rt = inst_i[20:16];
wire instvalid = wreg_o;
wire op_tem = ~(|op);
wire inst_add = op_tem && (func == 6'b100000);
wire inst_sub = op_tem && (func == 6'b100010);
wire inst_or = op_tem && (func == 6'b100101);
wire inst_and = op_tem && (func == 6'b100100);
wire inst_xor = op_tem && (func == 6'b100110);
wire inst_nor = op_tem && (func == 6'b100111);
wire inst_slt = op_tem && (func == 6'b101010);
wire inst_sltu = op_tem && (func == 6'b101011);
wire inst_sll = op_tem && (func == 6'b000000);
wire inst_srl = op_tem && (func == 6'b000010);
wire inst_sra = op_tem && (func == 6'b000011);
wire inst_lui = (op == 6'b001111);
wire [`FOURBYTE] imm = (inst_lui)? {inst_i[15:0],16'b0}:(inst_sll|inst_sra|inst_srl)?{27'b0,sa}:32'b0;
assign wreg_o = inst_add | inst_sub | inst_or | inst_srl | inst_sra | inst_lui |
inst_and | inst_xor | inst_nor | inst_slt | inst_sltu| inst_sll ;
assign reg1_read_o = inst_add | inst_sub | inst_or | inst_lui |
inst_and | inst_xor | inst_nor | inst_slt | inst_sltu ;
assign reg2_read_o = inst_add | inst_sub | inst_or | inst_srl | inst_sra |
inst_and | inst_xor | inst_nor | inst_slt | inst_sltu| inst_sll ;
assign wd_o = (inst_lui) ? inst_i[20:16] : inst_i[15:11];
assign reg1_addr_o = inst_i[25:21];
assign reg2_addr_o = inst_i[20:16];
assign aluop_o[0] = inst_sub|inst_sltu|inst_nor|inst_xor|inst_srl|inst_lui;
assign aluop_o[1] = inst_slt|inst_sltu|inst_or |inst_xor|inst_sra|inst_lui;
assign aluop_o[2] = inst_and|inst_nor |inst_or |inst_xor;
assign aluop_o[3] = inst_sll|inst_srl |inst_sra|inst_lui;
assign reg1_o = (rst)?32'b0:(reg1_read_o)?reg1_data_i:imm;
assign reg2_o = (rst)?32'b0:(reg2_read_o)?reg2_data_i:imm;
endmodule
边栏推荐
猜你喜欢
随机推荐
【愚公系列】2022年08月 Go教学课程 033-结构体方法重写、方法值、方法表达式
100句话,是否会触动你?
Module模块化编程的优点有哪些
支付宝小程序禁止页面弹性下拉或上拉
【GNN终身学习】2022 CVPR 终身图学习
[漏洞复现]CVE-2018-12613(远程文件包含)
requests之防盗链学习
Dark Horse 2022 latest redis course notes and knowledge points (for interview)
PoPW token distribution mechanism may ignite the next bull market
微信小程序转支付宝小程序注意事项
[MySQL]mysql: Solve the problem of [Err] 1093 - You can't specify target table 'table name' for update in FROM clause
Object detection app based on appinventor and EasyDL object detection API
数制之间的转换
Shell programming loop statement and function
这下你知道为什么程序员要和产品干架了吧?
Arduino+2片74hc595 驱动8x8(共阳)点阵(1008BS)
BUUCTF MISC brush notes (2)
[V&N2020 公开赛]内存取证
Makefile中patsubst、wildcard、notdir的使用
leetcode 32. 最长有效括号 (困难)

![[V&N2020 Open] Memory Forensics](/img/b7/20f72a40d43a402009e9451903615b.png)







