西安交通大学组成专题实验报告_第1页
西安交通大学组成专题实验报告_第2页
西安交通大学组成专题实验报告_第3页
西安交通大学组成专题实验报告_第4页
西安交通大学组成专题实验报告_第5页
已阅读5页,还剩36页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

计算机组织与结构专题实验报告MIPS单周期处理器的设计学生姓名 赵荣建 专业班级 计算机45班 学 号 指导教师 姜欣宁 完成日期 2017-05-09 一.实验目的根据所学的CPU组成原理,自主设计一个MIPS32位的单周期处理器。二.设计方案参照计算机组成原理教材上的MIPS32位处理器的工作原理。1.构建数据通路取指令IF指令译码ID指令执行EXE存储器访问MEM结果写回WB取指周期:a.从指令寄存器PC输出端得到地址b.送地址到指令存储器IM地址端Ac.从指令存储器IM的数据端RD得到指令d.计算下地址:通过运算器,PC+4形成下地址,送回到PC。2. .MIPS 寄存器集:定义了32个32位的寄存器3.MIPS三种指令格式:R-类型、I-类型和J-类型R-类型格式:* 所有指令操作吗OP都是0;特定操作由funct决定。* 机器语言指令中,字段分配格式如上图;前两个寄存器rs、 rt 是源寄存器,rd是目的寄存器。而在汇编语言格式中,第一个 寄存器是目的寄存器。 如:add $t0,$s4,$s5 #rd=rs+rt,t0=s4+s5; I-类型格式:* 指令含4个字段;op, rs, rt 和 imm* 有两个寄存器操作数和一个16位立即数操作数,一些指令中,rt也可作为源寄存器。J-类型格式:* 有一个26位立即数操作数,扩展后形成目的地址。 4.算逻单元ALU的设计ALU工作原理图* 两级控制:通过系统控制器(Control) 和运算器控制器(ALU Control)产生 ALU的控制信号:ALUoper* ALU控制信号对照表:ALUopFunc(来自R型指令的func字段)操作ALUop1ALUop2F5F4F3F2F1F000010:ADD01110:SUB10000010:ADD10010110:SUB10100000:AND10101001: OR11010111:SLT5.单周期数据通路的构建 1)构件:PC、指令存储器、寄存器文件RF和数据存储器; 2)取指令的过程:PCIM: A/RD 3)取源操作数的过程: IM:RDRF:A1/RD1。 4)立即数的符号扩展的过程: IM:RD(Instr:15:0)Sign Extend(15:0Signimm31:0); 其中Signimm15:0=Instr15:0, Signimm31:16=Instr155)存储器地址计算: 6)向寄存器文件写入数据 RegWrite信号被置成1,写入过程在时钟周期最后的时钟上升沿完成。 7)形成PC的下地址 指令占4个字节,字编址。6.单周期控制器的构建 控制单元基于指令中的opcode字段(31:26)、funct字段(5:0)产生控制信号;主译码的真值表。见下图: 7.完整的单周期MIPS处理器三.设计过程1.指令集设计R型指令指令序号指令译码结果(B)存储指令(H)add $s0,$s1,$s2 10001 10010 10000 00000 sub $t0,$t1,$t2 01001 01010 01000 00000 012a4022and $s3,$s4,$s5 10100 10101 10011 00000 or $s0,$s6,$s7 10110 10111 10000 00000 02d78025xor $t3,$t4,$t5 01100 01101 01011 00000 018d5826slt $t7,$t5,$t6 01101 01110 01111 00000 01ae782anor $t7,$t5,$t6 01101 01110 01111 00000 01ae7827srl $t0,$s1,$t5 10001 01101 01000 00000 022d4002sll $t0,$s1,$t2 10001 01010 01000 00000 022a4000inc $t0,$t6 01110 00000 01000 00000 01c04003dec $t0,$t5 01101 00000 01000 00000 01a04004I型指令指令序号指令译码结果(B)存储指令(H)lw $s0,1($t1) 01001 10000 8dsw $t1,1($t1) 01001 01001 adaddi $t0,$t1,1 01001 01000 beq $t1,$t1,1 01001 01001 J型指令指令序号指令译码结果(B)存储指令(H)J 17 2.MIPS 32位单周期处理器结构设计CPU设计结构图如下:信号说明:a1:pc中的指令的地址送往IM去寻找指令a2:pc产生的下一条指令的地址a3:pc中指令的地址加4a4:取pc中指令的地址加4后的高六位b1:取J型指令的低26位b2:操作码字段高六位b3:第一个源操作数的寄存器地址,R型的21-25位,I型的21-25位b4:第二个源操作数的寄存器地址,R型的16-20位,I型指令的目的寄存器地址,16-20位b5:R型指令的目的寄存器地址,11-15位b6:I型指令的立即数,0-15位b7:R型指令的低六位,0-5位b8:b4和b5经二路选择器二选一b20:从IM中取出来的指令内容c1:I型指令将16位立即数扩展成32位c2:存入目的寄存器的内容c3:从源寄存器1中取出的内容c4:从源寄存器2中取出的内容c5:c1和c4二选一c6:ALU计算出的结果,也是读DM的地址c7:从DM中取出的内容c8、c9:针对不同类型的指令对进行pc值的修正的选择d1:功能选择信号e类信号:主操作控制信号,主要是各部件的读写控制信号核心模块说明:IM:按序号存放指令(共17条,其中lw指令执行了两次),在CPU启动时从开始执行。Rf:主寄存器,存放32个32位字,存储情况见下表(十进制表示,单数行是地址序号,双数行是对应的存储值):0141312111098765432101514131211109876543210DM:数据存储器,存储情况见下表(十进制表示,单数行是地址序号,双数行是对应的存储值):87654321876543218765432187654321tRf:测试模块,用于输出指令执行结果以检验是否正确;IRf:测试模块,用于输出当前执行的指令,与tRf搭配使用。四.代码分析1. Add /完成分支指令的目标地址计算/library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity add is Port ( a: in STD_LOGIC_VECTOR (31 downto 0); b : in STD_LOGIC_VECTOR (31 downto 0); y : out STD_LOGIC_VECTOR (31 downto 0);end add;architecture Behavioral of add isbeginy=a + b;-将a和b相加赋给yend Behavioral;2. Add4 /完成PC+1(采用字寻址)的计算/library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity Add4 isport(pcin:in std_logic_vector(31 downto 0); pcout:out std_logic_vector(31 downto 0);end Add4;architecture behave of Add4 isbeginprocess(pcin)beginpcout result result result result result result result result result -slt比较大小 if(a1b1)then result=x; else result result result=x;end case; if(a1=b1)then -beq 判断分支指令是否转移当a1=b1时进行转移 zero=1; else zero=0; end if; end process;end behave;4. and_gate /与门,完成分支指令的判定/library ieee;use ieee.std_logic_1164.all;entity and_gate isport(a,b:in std_logic;c:out std_logic);end and_gate;architecture dataflow of and_gate isbegin c = a and b;end dataflow;5. mux2_1 /5位二路选择器,由控制信号选择目的寄存器/library ieee;use ieee.std_logic_1164.all;entity mux2_1 is generic (width:integer:=5); Port ( d0,d1 : in STD_LOGIC_VECTOR (width-1 downto 0); s : in STD_LOGIC; y : out STD_LOGIC_VECTOR (width-1 downto 0);end mux2_1;architecture Behavioral of mux2_1 isbeginy=d0 when s=0 else d1;-s位0选择d0,若s为1选择d1end Behavioral;6. Rf /32个32位寄存器组成的主寄存器,有预存/library ieee;use ieee.std_logic_1164.all;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity regfile is Port ( clk : in STD_LOGIC; we3 : in STD_LOGIC;-写使能信号 ra1 : in STD_LOGIC_VECTOR (4 downto 0);-源寄存器1的地址 ra2 : in STD_LOGIC_VECTOR (4 downto 0);- 源寄存器2的地址 wa3 : in STD_LOGIC_VECTOR (4 downto 0);-目的寄存器地址 wd3 : in STD_LOGIC_VECTOR (31 downto 0);-写入目的寄存器的内容 rd1 : out STD_LOGIC_VECTOR (31 downto 0);-从源寄存器1中读出的内容 rd2 : out STD_LOGIC_VECTOR (31 downto 0);-从源寄存器2中读出的内容end regfile;architecture Behavioral of regfile is-subtype ramtype is std_logic_vector(31 downto 0);-type memory is array(0 to 31) of ramtype;type ramtype is array(31 downto 0) of STD_LOGIC_VECTOR(31 DOWNTO 0);SIGNAL mem:ramtype:=-signal mem_initial:memory:=(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(xa),(xb),(xc),(xd),(xe),(xf),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(xa),(xb),(xc),(xd),(xe),(x);-预先存入32个寄存器的32位数beginprocess(clk) begin if (clkevent and clk=1) then if (we3=1) then mem(CONV_INTEGER(wa3)=wd3;-写使能信号为一,将目的寄存器的内容写入目的寄存器地址所对的单元内 end if; end if;end process;process(ra1,ra2) begin if(conv_integer(ra1)=0)then rd1=x; else rd1=mem(conv_integer(ra1);-读出源寄存器1中的内容 end if; if(conv_integer(ra2)=0) then rd2=x; else rd2=mem(conv_integer(ra2);- -读出源寄存器2中的内容 end if; end process;end Behavioral;7. signext /符号拓展模块,将16位立即数拓展为32位,用于分支指令/library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity signext is Port ( a : in STD_LOGIC_VECTOR (15 downto 0); y : out STD_LOGIC_VECTOR (31 downto 0);end signext;architecture Behavioral of signext isbeginY=X0000& a when a(15)=0 else xffff &a;-16位数扩展为32位,若是正数,前面扩展0,负数则扩展1end Behavioral;8. PC /程序计数器,提供取指令地址/library ieee;use ieee.std_logic_1164.all;entity pc is -实体描述port(pc_in: in std_logic_vector(31 downto 0); clk,reset: in std_logic; pc_out: out std_logic_vector(31 downto 0);end pc;architecture behave of pc is -实体的行为描述-signal pc_temp: std_logic_vector(31 downto 0);beginF:process(clk)beginif (clkevent and clk = 1) then if(reset=0)thenpc_out = pc_in;end if;end if;end process;end behave;9. IM /指令存储器,已预存17条指令,由PC指出地址/library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use IEEE.STD_LOGIC_ARITH.ALL;entity IM isport(-clk,read,write:in std_logic;address:in std_logic_vector(31 downto 0);-im_in:in std_logic_vector(31 downto 0);im_out:out std_logic_vector(31 downto 0);end IM;architecture behave of IM issubtype dword is std_logic_vector(31 downto 0);type memory is array(0 to 18) of dword;signal mem_initial:memory:=(x),(x012a4022),(x),(x02d78025),(x018d5826),(x01ae782a),(x01ae7827),(x8d),(xad),(x8d),(x),(x)-beq,(x),(x022d4002),(x022a4000),(x)-J,(x),(x01c04003),(x01a04004);-指令寄存器中预先存储了17条指令beginprocess(address)beginim_outcontrolscontrolscontrolscontrolscontrolscontrolscontrolscontrols=-;end case;end process;memread =controls(9);regwrite=controls(8);regdst =controls(7);alusrc =controls(6);branch =controls(5);memwrite=controls(4);memtoreg=controls(3);jump =controls(2);aluop aluoperaluopercase funct is when =aluoperaluoperaluoperaluoperaluoperaluoperaluoperaluoperaluoperaluoperaluoperaluoper=-; end case;end case;end process;end Behave;12. DM /数据存储器,有预存/library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity dm isport( address: in std_logic_vector(31 downto 0); data_in: in std_logic_vector(31 downto 0); write,read: in std_logic; data_out: out std_logic_vector(31 downto 0); clock: in std_logic );end dm;architecture behave of dm istype ramtype is array(31 downto 0) of STD_LOGIC_VECTOR(31 DOWNTO 0);SIGNAL sram:ramtype:=(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x),(x);-预先存储在DM中的数据,用于对实验的进行验证使用begin write_op:process(write,clock) begin if(clockevent and clock=1) then if(read=0 and write=1) then sram(conv_integer(address)=data_in;-数据读入DM end if; end if;end process;read_op:process(read,write,sram,address) begin if (read=1 and write=0) then data_out=sram(conv_integer(address);-数据从DM中读出 else data_outZ); end if;end process;end behave;13. mux2_11 /32位二路选择器,实例化4次完成不同的功能/library ieee;use ieee.std_logic_1164.all;entity mux2_11 is generic (width:integer:=32); Port ( d01,d11 : in STD_LOGIC_VECTOR (width-1 downto 0); s1 : in STD_LOGIC; y1 : out STD_LOGIC_VECTOR (width-1 downto 0);end mux2_11;architecture Behavioral of mux2_11 isbeginy1=d01 when s1=0 else d11;end Behavioral;14. tRf /测试模块,用于输出指令执行结果以检验是否正确/library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity tregfile is Port ( tclk : in STD_LOGIC; twe3 : in STD_LOGIC; tra1 : in STD_LOGIC_VECTOR (4 downto 0); tra2 : in STD_LOGIC_VECTOR (4 downto 0); twa3 : in STD_LOGIC_VECTOR (4 downto 0); twd3 : in STD_LOGIC_VECTOR (31 downto 0); trd1 : out STD_LOGIC_VECTOR (31 downto 0); trd2 : out STD_LOGIC_VECTOR (31 downto 0);end tregfile;architecture Behavioral of tregfile istype ramtype is array(31 downto 0) of STD_LOGIC_VECTOR(31 DOWNTO 0);SIGNAL mem:ramtype;beginprocess(tclk) begin if (tclkevent and tclk=1) then if (twe3=1) then mem(CONV_INTEGER(twa3)=twd3;-向目的寄存器中写数据 end if; end if;end process;process(tra1,tra2) begin if(conv_integer(tra1)=0)then trd1=x; else trd1=mem(conv_integer(tra1);-读源寄存器1中的数据 end if; if(conv_integer(tra2)=0) then trd2=x; else trd2=mem(conv_integer(tra2);- 读源寄存器1中的数据 end if; end process;end Behavioral;15. IRf /测试模块,用于输出当前执行的指令,与tRf搭配使用/library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity Iregfile is Port ( iclk : in STD_LOGIC; iwe3 : in STD_LOGIC; ira1 : in STD_LOGIC_VECTOR (4 downto 0); ira2 : in STD_LOGIC_VECTOR (4 downto 0); iwa3 : in STD_LOGIC_VECTOR (4 downto 0); iwd3 : in STD_LOGIC_VECTOR (31 downto 0); ird1 : out STD_LOGIC_VECTOR (31 downto 0); ird2 : out STD_LOGIC_VECTOR (31 downto 0);end Iregfile;architecture Behavioral of Iregfile istype ramtype is array(31 downto 0) of STD_LOGIC_VECTOR(31 DOWNTO 0);SIGNAL mem:ramtype;beginprocess(iclk) begin if (iclkevent and iclk=1) then if (iwe3=1) then mem(CONV_INTEGER(iwa3)=iwd3; end if; end if;end process;process(ira1,ira2) begin if(conv_integer(ira1)=0)then ird1=x; else ird1=mem(conv_integer(ira1); end if; if(conv_integer(ira2)=0) then ird2=x; else ird2=mem(conv_integer(ira2); end if; end process;end Behavioral;16. CPU /顶层模块/library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity CPU isport(rout1,rout2: out std_logic_vector(31 downto 0);-测试 clk1,ret: in std_logic);end CPU;architecture behave of CPU issignal a1,a2,a3,a4:std_logic_vector(31 downto 0);signal b1:std_logic_vector(25 downto 0);signal b2,b7:std_logic_vector(5 downto 0);signal b3,b4,b5,b8:std_logic_vector(4 downto 0);signal b6:std_logic_vector(15 downto 0);signal c1,c2,c3,c4,c5,c6,c7,c8,c9,b20:std_logic_vector(31 downto 0);signal d1:std_logic_vector(1 downto 0);signal e1,e2,e3,e4,e5,e6,e7,e8,e9,e10 :std_logic;signal f1:std_logic_vector(3 downto 0);-signal g1:std_logic_vector(27 downto 0);-具体信号见前面,都具体解释了component Add4port(pcin:in std_logic_vector(31 downto 0);pcout:out std_logic_vector(31 downto 0); end component;component pcport(pc_in: in std_logic_vector(31 downto 0); clk,reset: in std_logic; pc_out: out std_logic_vector(31 downto 0);end component;-pc模块component IMport(-clk,read,write:in std_logic;address:in std_logic_vector(31 downto 0);-im_in:in std_logic_vector(31 downto 0);im_out:out std_logic_vector(31 downto 0); end component;-IM模块component add Port ( a: in STD_LOGIC_VECTOR (31 downto 0); b : in STD_LOGIC_VECTOR (31 downto 0); y : out STD_LOGIC_VECTOR (31 downto 0);end component;-add模块component mux2_1 generic (width:integer:=5); Port ( d0,d1 : in STD_LOGIC_VECTOR (width-1 downto 0); s : in STD_LOGIC; y : out STD_LOGIC_VECTOR (width-1 downto 0); end component;-mux2_1模块component mux2_11 generic (width:integer:=32); Port ( d01,d11 : in STD_LOGIC_VECTOR (width-1 downto 0); s1 : in STD_LOGIC; y1 : out STD_LOGIC_VECTOR (width-1 downto 0);end component;component and_gateport(a,b:in std_logic;c:out std_logic);end com

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论