当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
小程序调用百度api实现图像识别
leetcode 34. 在排序数组中查找元素的第一个和最后一个位置(二分经典题)
Shell编程之循环语句与函数
Calendar类和Date类转换时区 && 部分时区城市列表
RESTful
BUUCTF MISC刷题笔记(二)
vim 按了Ctrl+S后 卡死
uva11624 Fire! (双bfs)
OpenHarmony Light Smart Product Development Live Notes
【场景化解决方案】OA审批与用友U9数据集成
嵌入式之串口中断只能收到一个字节
Operator Overloading in Inheritance: A Legend of Input and Output
QT设置exe可执行文件的图标
Regular Expressions for Shell Programming
jdbctemplate connects to sql server, the data found in the code is inconsistent with the database, how to solve it?
VNCTF2021 部分题目复现
【场景化解决方案】OA审批与金智CRM数据同步
BUUCTF MISC刷题笔记(一)
QT program generates independent exe program (pit-avoiding version)
【场景化解决方案】构建医疗通讯录,“慧医钉”助力医院实现数字化管理


![[Vulnerability reproduction] CVE-2018-7490 (path traversal)](/img/0f/652869001b3e3b683192e6558d81fb.png)






