没有合适的资源?快使用搜索试试~ 我知道了~
首页基于VHDL语言的单周期MIPS微处理器设计
基于VHDL语言的单周期MIPS微处理器设计 MIPS单周期方案是MIPS子集最简单的实现方案,主要设计了12个模块和一个顶层文件,实现的指令包括取字(lw),存字(sw),等值分支(beq),不等值则分支(bne),和算术逻辑指令 add、sub、and、or、nor、逻辑左移(sll)、逻辑右移(srl)和小于则置位(slt),立即数指令ori、andi、addi, 跳转指令(J)共16条指令
资源详情
资源评论
资源推荐
深圳大学研究生课程论文
基于 VHDL 语言的单周期 MIPS 微处理器设计
MIPS 单周期方案是 MIPS 子集最简单的实现方案,主要设计了 12 个模块和一个顶
层文件,实现的指令包括取字(lw),存字(sw),等值分支(beq),不等值则分支(bne),和
算术逻辑指令 add、sub、and、or、nor、逻辑左移(sll)、逻辑右移(srl)和小于则置位
(slt),立即数指令 ori、andi、addi, 跳转指令(J)共 16 条指令。以下是实现方案的各个模
块。
一、 程序计数器(PC)
PC 其实就是一个 D 触发器,当复位信号(reset)来的时候,同时时钟也到了的时候,
把输入(pc_in)给输出(pc_out),复位的第一个输出是从 x’0000’开始,下面是这个模块的
实现代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity PC is
port( pc_in : in std_logic_vector(31 downto 0);
pc_out : out std_logic_vector(31 downto 0);
clk : in std_logic;
reset : in std_logic);
end PC;
architecture Behavioral of PC is
begin
process(clk,reset,pc_in)
begin
if reset='1' then pc_out<="00000000000000000000000000000000";
elsif clk='1' and clk'event
then pc_out <= pc_in;
end if;
end process;
end Behavioral;
二、 指令地址的计算模块
这个模块的功能是计算指令的地址,由于所选的指令原因,所以有三种指令地址
来源,首先是普通指令的递增,即 PC+4,执行完一条指令后跳转到下一条继续执行;
第二种是相等则分支和不等则分支指令,通过 ALU 的输出 Zero 和控制单元的控制信号
(Branch)相与判断是否选择分支目标地址,分支目标地址的计算方式是: PC+4 的值与
符号扩展并左移 2 位后的指令低 16 位的值相加;第三种是跳转指令 J,跳转指令是无
条件的不同于分支指令,32 位的地址的低 28 位来自 26 位立即数字段左移两位所得,
第 1 页 共 19 页
高四位为当前 PC+4 的最高四位(即顺序下条指令地址的 31:28 位)。下面是代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity PC_ADDR is
port( pc_out : in std_logic_vector(31 downto 0);
Jump_addr : in std_logic_vector(25 downto 0);
Jump,Branch,Zero : in std_logic;
sh_l2 : in std_logic_vector(31 downto 0); --Imm_ext shift left 2
pc_in : out std_logic_vector(31 downto 0));
end PC_ADDR;
architecture Behavioral of PC_ADDR is
constant N:integer:=1;
begin
process(pc_out,Jump_addr,sh_l2,Jump,Branch,Zero)
variable pcadd_out : std_logic_vector(31 downto 0); --pc+4 out
variable Jump_addrout : std_logic_vector(31 downto 0); --pc+4[31-28] & [28-0]
variable and_out : std_logic; --branch and zero
variable add_out : std_logic_vector(31 downto 0); --pc+4+sh_l2
begin
pcadd_out := pc_out + N;
and_out := Branch and Zero;
--add_out :=pc_out + N + sh_l2;
if Jump = '1' then
Jump_addrout := pcadd_out(31 downto 28) & Jump_addr(25 downto 0) & "00";
pc_in <= Jump_addrout;
elsif and_out = '1' then
add_out := pcadd_out + sh_l2;
pc_in <= add_out;
else
pc_in <= pcadd_out;
end if;
end process;
end Behavioral;
三、 指令存储器(Instr_Mem)模块
这个模块是一个指令存储器,在这里面共写了 16 条指令,通过 reset 初始化在指令
存 储 器 里 面 , 输 出 为 指 令 的 各 个 部 分 分 别 输 出 , 即 跳 转 立 即 数 ,
opcode,funct,rs,rt,rd,Imm,共有 7 个输出端口。下面是代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
第 2 页 共 19 页
entity InstrMem is
port( Readaddr : in std_logic_vector(31 downto 0);
Reset : in std_logic;
Instr_j : out std_logic_vector(25 downto 0);
Instr_opcode : out std_logic_vector(5 downto 0);
Instr_rs : out std_logic_vector(4 downto 0);
Instr_rt : out std_logic_vector(4 downto 0);
Instr_rd : out std_logic_vector(4 downto 0);
Instr_funct : out std_logic_vector(5 downto 0);
Instr_imm : out std_logic_vector(15 downto 0));
end InstrMem;
architecture Behavioral of InstrMem is
type RAM is array(0 to 31) of std_logic_vector(31 downto 0);
signal RAMS:RAM:=(others=>(others=>'0'));
signal Instr:std_logic_vector(31 downto 0);
begin
process(Reset,Readaddr,RAMS)
begin
if Reset = '1' then
RAMS(0)<=conv_std_logic_vector(0,6)&conv_std_logic_vector(18,5)&conv_std_logic
_vector(19,5)&conv_std_logic_vector(17,5)&conv_std_logic_vector(0,5)&conv_std_lo
gic_vector(32,6);
--add $s1,$s2,$s3 加指令
RAMS(1)<=conv_std_logic_vector(0,6)&conv_std_logic_vector(18,5)&conv_std_logi
c_vector(19,5)&conv_std_logic_vector(17,5)&conv_std_logic_vector(0,5)&conv_std_l
ogic_vector(34,6);
--sub $s1,$s2,$s3 减指令
RAMS(2)<=conv_std_logic_vector(12,6)&conv_std_logic_vector(18,5)&conv_std_log
ic_vector(17,5)&conv_std_logic_vector(100,16);
--andi $s1,$s2,100 与立即数指令
RAMS(3)<=conv_std_logic_vector(35,6)&conv_std_logic_vector(18,5)&conv_std_log
ic_vector(17,5)&conv_std_logic_vector(100,16);
--lw $s1,100($s2) 取字指令
RAMS(4)<=conv_std_logic_vector(43,6)&conv_std_logic_vector(18,5)&conv_std_log
ic_vector(17,5)&conv_std_logic_vector(100,16);
--sw $s1,100($s2) 存字指令
RAMS(5)<=conv_std_logic_vector(0,6)&conv_std_logic_vector(18,5)&conv_std_logi
c_vector(19,5)&conv_std_logic_vector(17,5)&conv_std_logic_vector(0,5)&conv_std_l
ogic_vector(36,6);
--and $s1,$s2,$s3 与指令
RAMS(6)<=conv_std_logic_vector(0,6)&conv_std_logic_vector(18,5)&conv_std_logi
c_vector(19,5)&conv_std_logic_vector(17,5)&conv_std_logic_vector(0,5)&conv_std_l
ogic_vector(37,6);
--or $s1,$s2,$s3 或指令
RAMS(7)<=conv_std_logic_vector(0,6)&conv_std_logic_vector(18,5)&conv_std_logi
c_vector(19,5)&conv_std_logic_vector(17,5)&conv_std_logic_vector(0,5)&conv_std_l
第 3 页 共 19 页
ogic_vector(39,6);
--nor $s1,$s2,$s3 或非指令
RAMS(8)<=conv_std_logic_vector(13,6)&conv_std_logic_vector(18,5)&conv_std_log
ic_vector(17,5)&conv_std_logic_vector(100,16);
--ori $s1,$s2,100 或立即数指令
RAMS(9)<=conv_std_logic_vector(0,6)&conv_std_logic_vector(0,5)&conv_std_logic
_vector(18,5)&conv_std_logic_vector(17,5)&conv_std_logic_vector(10,5)&conv_std_l
ogic_vector(0,6);
--sll $s1,$s2,10 逻辑左移指令
RAMS(10)<=conv_std_logic_vector(0,6)&conv_std_logic_vector(0,5)&conv_std_logi
c_vector(18,5)&conv_std_logic_vector(17,5)&conv_std_logic_vector(10,5)&conv_std
_logic_vector(2,6);
--srl $s1,$s2,10 逻辑右移指令
RAMS(11)<=conv_std_logic_vector(4,6)&conv_std_logic_vector(17,5)&conv_std_log
ic_vector(18,5)&conv_std_logic_vector(0,16);
--beq $s1,$s2,0 相等则分支指令
RAMS(12)<=conv_std_logic_vector(5,6)&conv_std_logic_vector(17,5)&conv_std_log
ic_vector(18,5)&conv_std_logic_vector(0,16);
--bne $s1,$s2,0 不等则分支指令
RAMS(13)<=conv_std_logic_vector(0,6)&conv_std_logic_vector(18,5)&conv_std_log
ic_vector(19,5)&conv_std_logic_vector(17,5)&conv_std_logic_vector(0,5)&conv_std_
logic_vector(42,6);
--slt $s1,$s2,$s3 小于则置 1 指令
RAMS(14)<=conv_std_logic_vector(8,6)&conv_std_logic_vector(18,5)&conv_std_log
ic_vector(17,5)&conv_std_logic_vector(100,16);
--addi $s1,$s2,100 加立即数指令
RAMS(15)<=conv_std_logic_vector(2,6)&conv_std_logic_vector(2500,26);
--j 10000 跳转指令
end if;
Instr <= RAMS(conv_integer(Readaddr(4 downto 0)));
end process;
Instr_j <= Instr(25 downto 0);
Instr_opcode <= Instr(31 downto 26);
Instr_rs <= Instr(25 downto 21);
Instr_rt <= Instr(20 downto 16);
Instr_rd <= Instr(15 downto 11);
Instr_imm <= Instr(15 downto 0);
Instr_funct <= Instr(5 downto 0);
end Behavioral;
四、 控制单元模块(Opcode_Ctrl)
第 4 页 共 19 页
剩余18页未读,继续阅读
a6930559
- 粉丝: 3
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- ExcelVBA中的Range和Cells用法说明.pdf
- 基于单片机的电梯控制模型设计.doc
- 主成分分析和因子分析.pptx
- 共享笔记服务系统论文.doc
- 基于数据治理体系的数据中台实践分享.pptx
- 变压器的铭牌和额定值.pptx
- 计算机网络课程设计报告--用winsock设计Ping应用程序.doc
- 高电压技术课件:第03章 液体和固体介质的电气特性.pdf
- Oracle商务智能精华介绍.pptx
- 基于单片机的输液滴速控制系统设计文档.doc
- dw考试题 5套.pdf
- 学生档案管理系统详细设计说明书.doc
- 操作系统PPT课件.pptx
- 智慧路边停车管理系统方案.pptx
- 【企业内控系列】企业内部控制之人力资源管理控制(17页).doc
- 温度传感器分类与特点.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论11