收藏 分销(赏)

计算机组成原理实验报告-单周期CPU的设计与实现.doc

上传人:a199****6536 文档编号:1248792 上传时间:2024-04-19 格式:DOC 页数:37 大小:871.23KB
下载 相关 举报
计算机组成原理实验报告-单周期CPU的设计与实现.doc_第1页
第1页 / 共37页
计算机组成原理实验报告-单周期CPU的设计与实现.doc_第2页
第2页 / 共37页
计算机组成原理实验报告-单周期CPU的设计与实现.doc_第3页
第3页 / 共37页
计算机组成原理实验报告-单周期CPU的设计与实现.doc_第4页
第4页 / 共37页
计算机组成原理实验报告-单周期CPU的设计与实现.doc_第5页
第5页 / 共37页
点击查看更多>>
资源描述

1、电子科技大学计算机科学与工程学院标 准 实 验 报 告(实验)课程名称: 计算机组成原理实验 电子科技大学教务处制表电 子 科 技 大 学实 验 报 告学生姓名: 郫县尼克杨 学 号: 2014666666666 指导教师:陈虹实验地点: 主楼A2-411 实验时间:12周-15周一、 实验室名称:主楼A2-411二、 实验项目名称:单周期CPU的设计与实现。三、 实验学时:8学时四、 实验原理:(一) 概述指令0指令1指令5指令2指令41个时钟周期Clock单周期(Single Cycle)CPU是指CPU从取出1条指令到执行完该指令只需1个时钟周期。一条指令的执行过程包括:取指令分析指令取

2、操作数执行指令保存结果。对于单周期CPU来说,这些执行步骤均在一个时钟周期内完成。(二) 单周期cpu总体电路本实验所设计的单周期CPU的总体电路结构如下。(三) MIPS指令格式化MIPS指令系统结构有MIPS-32和MIPS-64两种。本实验的MIPS指令选用MIPS-32。以下所说的MIPS指令均指MIPS-32。MIPS的指令格式为32位。下图给出MIPS指令的3种格式。263125212016151110650oprsrtrdsafuncR型指令263125212016150oprsrtimmediateI型指令2631250opaddressJ型指令本实验只选取了9条典型的MIPS

3、指令来描述CPU逻辑电路的设计方法。下图列出了本实验的所涉及到的9条MIPS指令。五、 实验目的1、掌握单周期CPU的工作原理、实现方法及其组成部件的原理和设计方法,如控制器、运算器等。2、认识和掌握指令与CPU的关系、指令的执行过程。3、熟练使用硬件描述语言Verilog、EDA工具软件进行软件设计与仿真,以培养学生的分析和设计CPU的能力。六、 实验内容(一)拟定本实验的指令系统,指令应包含R型指令、I型指令和J型指令,指令数为9条。(二)CPU各功能模块的设计与实现。(三)对设计的各个模块的仿真测试。(四)整个CPU的封装与测试。七、 实验器材(设备、元器件):(一)安装了Xilinx

4、ISE Design Suite 13.4的PC机一台(二)FPGA开发板:Anvyl Spartan6/XC6SLX45(三)计算机与FPGA开发板通过JTAG(Joint Test Action Group)接口连接,其连接方式如图所示。八、 实验步骤一个CPU主要由ALU(运算器)、控制器、寄存器堆、取指部件及其它基本功能部件等构成。在本实验中基本功能部件主要有:32位2选1多路选择器、5位2选1多路选择器、32位寄存器堆、ALU等。(一)新建工程(New Project)启动ISE Design Suite 13.4软件,然后选择菜单FileNew Project,弹出New Proj

5、ect Wizard对话框,在对话框中输入工程名CPU,并指定工作路径D:Single_Cycle_CPU。(二)基本功能器件的设计与实现(1)多路选择器的设计与实现a.5位2选1多路选择器(MUX5_2_1)的设计与实现在ISE集成开发环境中,在工程管理区任意位置单击鼠标右键,在弹出的菜单中选择New Source命令,创建一个Verilog Module模块,名称为:MUX5_2_1,然后输入其实现代码:module MUX5_2_1(input 4:0 A,input 4:0 B,input Sel,output 4:0 O );assign O = Sel ? B : A;endmod

6、ule在ISE集成开发环境中,对模块MUX5_2_1进行综合(Synthesize),综合结果如图所示:在ISE集成开发环境中,对模块MUX5_2_1进行仿真(Simulation)。输入如下测式代码: module MUX5_2_1_T;/ Inputsreg 4:0 A;reg 4:0 B;reg sel;/ Outputswire 4:0 C;/ Instantiate the Unit Under Test (UUT)MUX5_2_1 uut (.A(A), .B(B), .sel(sel), .C(C);initial begin/ Initialize InputsA = 0;B

7、= 0;sel = 0;/ Wait 100 ns for global reset to finish#100; A = 5b10100;B = 0;sel = 1;/ Wait 100 ns for global reset to finish#100; A = 1;B = 5b10000;sel = 0;/ Wait 100 ns for global reset to finish#100; A = 5b00000;B = 5b11000;sel = 1;/ Add stimulus hereendendmodule然后进行仿真,仿真结果如图所示:b.32位2选1多路选择器的设计与实现

8、在ISE集成开发环境中,在工程管理区任意位置单击鼠标右键,在弹出的菜单中选择New Source命令,创建一个Verilog Module模块,名称为:MUX32_2_1,然后输入其实现代码:module MUX32_2_1(input 31:0A ,input 31:0B,input sel,output 31:0 O );assign O= sel?B:A;endmodule在ISE集成开发环境中,对模块MUX32_2_1进行综合(Synthesize),综合结果如图所示:在ISE集成开发环境中,对模块MUX32_2_1进行仿真(Simulation)。首先输入如下测式代码: module

9、 MUX32_2_1_T;/ Inputsreg 31:0 A;reg 31:0 B;reg sel;/ Outputswire 31:0 O;/ Instantiate the Unit Under Test (UUT)MUX32_2_1 uut (.A(A), .B(B), .sel(sel), .O(O);initial beginA=0;B=0;sel=0;/ Wait 100 ns for global reset to finish#100;A=32h00000001;B=32h00000000;sel=1;#100;A=32h00000101;B=32h00000010;sel

10、=0; / Add stimulus hereend endmodule然后进行仿真,仿真结果如图所示:(2)符号扩展(Sign_Extender)的设计与实现在ISE集成开发环境中,在工程管理区任意位置单击鼠标右键,在弹出的菜单中选择New Source命令,创建一个Verilog Module模块,名称为:Sign_Extender,然后输入其实现代码:module Sign_Extender(input 15:0 d,output 31:0 o ); assign o = (d15:15 = 1b0) ? 16b0, d15:0 : 16b1, d15:0;endmodule在ISE集成

11、开发环境中,对模块Sign_Extender进行综合(Synthesize),综合结果如图所示。在ISE集成开发环境中,对模块MUX32_2_1进行仿真(Simulation)。首先输入如下测式代码:module Sign_Extender_t;/ Inputsreg 15:0 d;/ Outputswire 31:0 o;/ Instantiate the Unit Under Test (UUT)Sign_Extender uut (.d(d), .o(o);initial begin/ Initialize Inputs d = 0;/ Wait 100 ns for global re

12、set to finish#100; / Add stimulus hered = 16h0011;#100;d = 16h1011;end endmodule然后进行仿真,仿真结果如图所示:(3)32位寄存器堆(RegFile)的设计与实现在ISE集成开发环境中,在工程管理区任意位置单击鼠标右键,在弹出的菜单中选择New Source命令,创建一个Verilog Module模块,名称为:RegFile,然后输入其实现代码:module RegFile(input 4:0 Rn1, Rn2, Wn,input Write,input 31:0 Wd,output 31:0 A, B,inpu

13、t Clock ); reg 31:0 Register1:31;assign A = (Rn1 = 0) ? 0 : RegisterRn1;assign B = (Rn2 = 0) ? 0 : RegisterRn2;always (posedge Clock) beginif (Write & Wn != 0)RegisterWn = Wd;endendmodule在ISE集成开发环境中,对模块RegFile进行综合(Synthesize),综合结果如图所示。在ISE集成开发环境中,对模块RegFile进行仿真(Simulation)。输入如下测式代码:module Regfile_t;

14、/ Inputsreg 4:0 Rn1;reg 4:0 Rn2;reg 4:0 Wn;reg Write;reg 31:0 Wd;reg Clock;/ Outputswire 31:0 A;wire 31:0 B;/ Instantiate the Unit Under Test (UUT)RegFile uut (.Rn1(Rn1), .Rn2(Rn2), .Wn(Wn), .Write(Write), .Wd(Wd), .A(A), .B(B), .Clock(Clock);initial begin/ Initialize InputsRn1 = 0;Rn2 = 0;Wn = 0;Wr

15、ite = 0;Wd = 0;Clock = 0;/ Wait 100 ns for global reset to finish#100; Rn1 = 5b00001;Rn2 = 5b00001;Wn = 5b00001;Write = 1;Wd = 0;Clock = 0;#100;Clock = 1;#50;Wd = 32hBBBBBBBB;#50;Clock = 0;#100;Clock = 1;#100Clock = 0;/ Add stimulus hereend endmodule然后进行仿真,仿真结果如图所示:(4)运算器(ALU)设计与实现在ISE集成开发环境中,在工程管理区

16、任意位置单击鼠标右键,在弹出的菜单中选择New Source命令,创建一个Verilog Module模块,名称为:ALU,然后输入其实现代码:module ALU(input 31:0 A, B,input 2:0 ALU_operation,output 31:0 Result,output Zero );assign Result = (ALU_operation = 3b000) ? A + B : (ALU_operation = 3b100) ? A - B : (ALU_operation = 3b001) ? A & B : (ALU_operation = 3b101) ?

17、A | B : (ALU_operation = 3b010) ? A B : (ALU_operation = 3b110) ? B15:0, 16h0 : 32hxxxxxxxx; assign Zero = |Result;endmodule在ISE集成开发环境中,对模块ALU进行综合(Synthesize),综合结果如图所示:在ISE集成开发环境中,对模块ALU进行仿真(Simulation)。输入如下测式代码: module ALU_tb;/ Inputsreg 31:0 A;reg 31:0 B;reg 2:0 ALU_operation;/ Outputswire 31:0 Re

18、sult;wire Zero;/ Instantiate the Unit Under Test (UUT)ALU uut (.A(A), .B(B), .ALU_operation(ALU_operation), .Result(Result), .Zero(Zero);initial begin/ Initialize InputsA = 0;B = 0;ALU_operation = 0;/ Wait 100 ns for global reset to finish#100; A = 1;B = 1;ALU_operation = 0;/ Add stimulus here#100A

19、= 2;B = 2;ALU_operation = 4;#100A = 1;B = 1;ALU_operation = 1;#100A = 1;B = 1;ALU_operation = 5;#100A = 1;B = 1;ALU_operation = 2;end endmodule然后进行仿真,仿真结果如图所示:(5)控制器(Controller)的设计与实现为了简化设计,控制器由控制单元Control和控制单元ALUop组成,控制器结构如下所示。a Control的设计与实现在ISE集成开发环境中,在工程管理区任意位置单击鼠标右键,在弹出的菜单中选择New Source命令,创建一个Ve

20、rilog Module模块,名称为:Control,然后输入其实现代码:module Control(input 5:0 op,output RegDst,output RegWrite,output ALUSrc,output MemWrite,output MemRead,output MemtoReg,output Branch,output 1:0 ALUctr ); wire i_Rt=|op;wire i_Lw=op5 & op3;wire i_Sw=op5 & op3;wire i_Beq =op2 & op1;wire i_Lui=op3 & op2;assign RegDs

21、t = i_Rt;assign RegWrite=i_Rt|i_Lw|i_Lui;assign ALUSrc =i_Lw|i_Sw |i_Lui;assign MemWrite =i_Sw;assign MemRead=i_Lw;assign MemtoReg= i_Lw;assign Branch=i_Beq;assign ALUctr1= i_Rt|i_Lui;assign ALUctr0=i_Beq|i_Lui;endmodule在ISE集成开发环境中,对模块Control进行综合(Synthesize),综合结果如图:在ISE集成开发环境中,对模块Control进行仿真(Simulat

22、ion)。首先输入如下测式代码:module Control_tb;/ Inputsreg 5:0 op;/ Outputswire RegDst;wire RegWrite;wire ALUSrc;wire MemWrite;wire MemRead;wire MemtoReg;wire Branch;wire 1:0 ALUctr;/ Instantiate the Unit Under Test (UUT)Control uut (.op(op), .RegDst(RegDst), .RegWrite(RegWrite), .ALUSrc(ALUSrc), .MemWrite(MemWr

23、ite), .MemRead(MemRead), .MemtoReg(MemtoReg), .Branch(Branch), .ALUctr(ALUctr);initial begin/ Initialize Inputsop = 0;/ Wait 100 ns for global reset to finish#100; op = 6b000000;#100; op = 6b100011;#100; op = 6b101011;#100; op = 6b000100;#100; op = 6b001111;end endmodule然后进行仿真,仿真结果如图所示:b ALUop的设计与实现

24、在ISE集成开发环境中,在工程管理区任意位置单击鼠标右键,在弹出的菜单中选择New Source命令,创建一个Verilog Module模块,名称为:ALUop,然后输入其实现代码:module ALUop(input 5:0 func,input 1:0 ALUctr,output 2:0 ALU_op );wire i_Rt = ALUctr1 & ALUctr0;assign ALU_op2=(i_Rt&(func2&func1)|(func2 &func0) | ALUctr0;assign ALU_op1=(i_Rt &func2 &func1)| (ALUctr1& ALUctr

25、0);assign ALU_op0=(i_Rt &func2 &func1);endmodule在ISE集成开发环境中,对模块ALUop进行综合(Synthesize),综合结果如图:在ISE集成开发环境中,对模块ALUop进行仿真(Simulation)。首先输入如下测式代码:module ALU_tb;/ Inputsreg 31:0 A;reg 31:0 B;reg 2:0 ALU_operation;/ Outputswire 31:0 Result;wire Zero;/ Instantiate the Unit Under Test (UUT)ALU uut (.A(A), .B(

26、B), .ALU_operation(ALU_operation), .Result(Result), .Zero(Zero);initial begin/ Initialize InputsA = 0;B = 0;ALU_operation = 0;/ Wait 100 ns for global reset to finish#100; A = 1;B = 1;ALU_operation = 0;/ Add stimulus here#100A = 2;B = 2;ALU_operation = 4;#100A = 1;B = 1;ALU_operation = 1;#100A = 1;B

27、 = 1;ALU_operation = 5;#100A = 1;B = 1;ALU_operation = 2;end endmodule然后进行仿真,仿真结果如图所:c 将Control与ALUop封装成Controller在ISE集成开发环境中,在工程管理区任意位置单击鼠标右键,在弹出的菜单中选择New Source命令,创建一个Verilog Module模块,名称为:Controller,然后输入其实现代码:module Controller(input 5:0 op,input 5:0 func,output RegDst,output RegWrite,output ALUSrc

28、,output MemWrite,output MemRead,output MemtoReg,output Branch,output 2:0 ALU_op );wire 1:0 ALUctr;Control U0 (op, RegDst, RegWrite, ALUSrc, MemWrite, MemRead, MemtoReg, Branch, ALUctr);ALUop U1 (func, ALUctr, ALU_op);endmodule在ISE集成开发环境中,对模块Controller进行综合(Synthesize),综合结果如图:在ISE集成开发环境中,对模块Controller

29、进行仿真(Simulation)。首先输入如下测式代码:module Controller_tb;/ Inputsreg 5:0 op;reg 5:0 func;/ Outputswire RegDst;wire RegWrite;wire ALUSrc;wire MemWrite;wire MemRead;wire MemtoReg;wire Branch;wire 2:0 ALU_op;/ Instantiate the Unit Under Test (UUT)Controller uut (.op(op), .func(func), .RegDst(RegDst), .RegWrite

30、(RegWrite), .ALUSrc(ALUSrc), .MemWrite(MemWrite), .MemRead(MemRead), .MemtoReg(MemtoReg), .Branch(Branch), .ALU_op(ALU_op);initial begin/ Initialize Inputsop = 0;func = 0;/ Wait 100 ns for global reset to finish#100;op =6b100011;#100op=6b101011;#100 op=6b000100;#100op=6b001111;endendmodule然后进行仿真,仿真结

31、果如图所示:(6)取指电路的设计与实现取指电路需完成ADD32、PC寄存器、多路选择器和左移两位模块,从而实现该取指电路。aADD32的设计与实现在ISE集成开发环境中,在工程管理区任意位置单击鼠标右键,在弹出的菜单中选择New Source命令,创建一个Verilog Module模块,名称为:ADD32,然后输入其实现代码:module ADD32(input 31:0 A, B,output 31:0 C );assign C = A + B;endmodule在ISE集成开发环境中,对模块Controller进行综合(Synthesize),综合结果如图:b左移两位模块(Left_2_

32、Shifter)的设计与实现在ISE集成开发环境中,在工程管理区任意位置单击鼠标右键,在弹出的菜单中选择New Source命令,创建一个Verilog Module模块,名称为:Left_2_Shifter,然后输入其实现代码:module Left_2_Shifter(input 31:0 d,output 31:0 o );assign o = d29:0, 2b00;endmodule在ISE集成开发环境中,对模块Controller进行综合(Synthesize),综合结果如图:c综合取指电路(Fetch)的设计与实现在ISE集成开发环境中,在工程管理区任意位置单击鼠标右键,在弹出的

33、菜单中选择New Source命令,创建一个Verilog Module模块,名称为:Fetch,然后输入其实现代码:module Fetch(input Reset,input Clock,input 31:0 B_addr,input Z, B,output 31:0 addr ); reg 31:0 PC;wire 31:0 U0_o;wire 31:0 U1_C;wire 31:0 U2_C;wire 31:0 Next_PC;wire sel = Z & B;Left_2_Shifter U0 (B_addr, U0_o);ADD32 U1 (PC, 4, U1_C);ADD32 U

34、2 (U1_C, U0_o, U2_C);MUX32_2_1 M1 (U1_C, U2_C, sel, Next_PC);assign addr = PC;always (posedge Clock or negedge Reset) beginif (Reset = 0)PC = 0;elsePC = Next_PC;endendmodule在ISE集成开发环境中,对模块Fetch进行综合(Synthesize),综合结果如图:在ISE集成开发环境中,对模块Fetch进行仿真(Simulation)。首先输入如下测式代码:module FETCH_T;/ Inputsreg clock;re

35、g reset;reg 31:0 b_addr;reg B;reg Z;/ Outputswire 31:0 inst;wire 31:0 o_addr;wire 31:0 o_sum;wire 31:0 o_sum1;/ Instantiate the Unit Under Test (UUT)FETCH uut (.clock(clock), .reset(reset), .b_addr(b_addr), .B(B), .Z(Z), .inst(inst), .o_addr(o_addr), .o_sum(o_sum), .o_sum1(o_sum1);initial begin/ Ini

36、tialize Inputsclock = 0;reset = 0;b_addr = 0;B = 0;Z = 0;/ Wait 100 ns for global reset to finish#100;clock=1;#100;clock=0;#100;clock=1;#100;clock=0;#100;clock=1;#100;clock=0;#100;clock=1;#100;Z=1;B=1;b_addr=32h4;clock=0;#100;clock=1;#100;clock=0;B=0;Z=0;#100;clock=1;#100;clock=0;#100;clock=1;b_addr

37、=32b0;#100;clock=0;#100;reset=1;clock=1;#100;clock=0;#100;clock=1;#100;clock=0; / Add stimulus here / Add stimulus hereendendmodule然后进行仿真,仿真结果如图所示:(7)数据通路Data_Flow的设计与实现除去指令存储器Instruction ROM、数据存储器DATA MEM,将剩余的电路封装成一个单周期的CPU数据通路(Data_Flow)模块。在ISE集成开发环境中,在工程管理区任意位置单击鼠标右键,在弹出的菜单中选择New Source命令,创建一个Ver

38、ilog Module模块,名称为:Data_Flow,然后输入其实现代码:module Data_Flow(input Reset,input Clock,input 31:0 Inst,input 31:0 Data,output MemWrite,output MemRead,output 31:0 Result,output 31:0 B_data,output 31:0 NextPC );wire 31:0 B_addr;wire Z, B;wire RegDst;wire RegWrite;wire ALUSrc;wire MemtoReg;wire 2:0 ALU_op;wire

39、 31:0 ALU_A, ALU_B;wire 4:0 Wn;wire 31:0 Wd;Fetch U0 (Reset, Clock, B_addr, Z, B, NextPC);Controller U1 (Inst31:26, Inst5:0, RegDst, RegWrite, ALUSrc, MemWrite, MemRead, MemtoReg, B, ALU_op);ALU U2 (ALU_A, ALU_B, ALU_op, Result, Z);RegFile U3 (Inst25:21, Inst20:16, Wn, RegWrite, Wd, ALU_A, B_data, Clock);MUX5_2_1 U4 (Inst20:16, Inst15:11, RegDst, Wn);MUX32_2_1 U5 (B_data, B_addr, ALUSrc, ALU_B);Sign_Extender U6 (Inst15:0, B_addr);MUX32_2_1 U7 (NextPC, Data, MemtoReg, Wd)

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 应用文书 > 报告/总结

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服