实验四多周期CPU与存储器实验.doc

上传人:小** 文档编号:3017203 上传时间:2020-06-22 格式:DOC 页数:15 大小:1.09MB
返回 下载 相关 举报
实验四多周期CPU与存储器实验.doc_第1页
第1页 / 共15页
实验四多周期CPU与存储器实验.doc_第2页
第2页 / 共15页
点击查看更多>>
资源描述

《实验四多周期CPU与存储器实验.doc》由会员分享,可在线阅读,更多相关《实验四多周期CPU与存储器实验.doc(15页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、.-湘潭大学实验报告 课程名称计算机原理与设计实验名称_多周期CPU与存储器实验 _ 页数 专业计算机科学与技术班级_2_同组者姓名 组别学号2015962138姓名庄振南实验日期_2016.11.02_ 一、实验目的 1、深入理解MIPSCPU指令系统的功能和工作原理;2、掌握多周期CPU的工作原理和逻辑功能实现;3、熟练掌握用Verilog HDL语言设计多周期存储器的方法;4、熟练掌握对多周期存储器的仿真实验验证和硬件测试两种调试方法;5、通过对多周期CPU的运行情况进行观察和分析,进一步加深理解。二、实验要求 1、深入理解MIPSCPU指令系统的功能和工作原理;2、掌握多周期CPU的工

2、作原理和逻辑功能实现;3、熟练掌握用Verilog HDL语言设计多周期存储器的方法;三、实验原理 实现上述原理框图根据功能将其分划分为控制单元(cunit)、执行单元(eunit)、指令单元(iunit)以及存储单元(munit)四大模块。 (1).控制单元(cunit)是多周期微处理器的核心控制微处理器取指令、指令译码和指令执行等工作。主要由指令译码器控制器(outputs control)、算术逻辑运算控制器(ALU control)两个子模块组成。 (2).执行单元(eunit)主要由寄存器堆(registers)和算术逻辑单元(ALU)两个子模块组成。其中寄存器是微处理器最基本的元素

3、MIPS系统的寄存器堆由32个32位寄存器组成而ALU则是微处理器的主要功能部件执行加、减、比较等算术运算和与、或、或非、异或等逻辑运算。指令单元(iunit)的作用是决定下一条指令的地址PC值。 (3).存储单元(munit)由存储器(memory)、指令寄存器(instruction register)和存储数据寄存器(memory data register)组成。四、实验内容 1、设计一个32位MIPS多周期CPU具体的要求如下: 至少运行下列的6类32条MIPS指令。 (1)算术逻辑指令and、sub、addi (2)逻辑运算指令and、0r、xor、 andi、 ori、xori(

4、3)位移指令sll、srl、sra(4)条件分支指令beq、bne、(5)无条件跳转指令j、jr (6)数据传送指令lw、sw2.设计一个存储器五、实验环境与设备 电脑,电箱。六、实验代码设计(含符号说明) 寄存器元件代码:module regfile (rna,rnb,d,wn,we,clk,clrn,qa,qb);input4:0rna,rnb,wn;input31:0d;inputwe,clk,clrn;output31:0qa,qb;reg31:0register1:31;/r1-r31assign qa = (rna = 0) ? 0 : registerrna;/readassig

5、n qb = (rnb = 0) ? 0 : registerrnb;/readalways (posedge clk or negedge clrn) beginif (clrn = 0) begin/resetinteger i;for (i=1; i32; i=i+1)registeri = 0;endelse beginif (wn != 0) & (we = 1)/writeregisterwn = d;endendendmodule32位四选一选择器:module mux4x32 (a0,a1,a2,a3,s,y);input 31:0a0,a1,a2,a3;input1:0s;o

6、utput31:0y;function31:0select;input 31:0a0,a1,a2,a3;input 1:0s;case (s)2b00:select=a0;2b01:select=a1;2b10:select=a2;2b11:select=a3;endcaseendfunctionassigny=select (a0,a1,a2,a3,s);endmodule5位二选一选择器:module mux2x5 (a0,a1,s,y);input 4:0a0,a1;inputs;output4:0y;assigny = s ? a1 : a0;endmodule32位二选一选择器:mo

7、dule mux2x32 (a0,a1,s,y);input 31:0a0,a1;inputs;output31:0y;assigny = s ? a1 : a0;endmodule存储器元件:module mcmem (clk, dataout, datain, addr, we, inclk, outclk);input31:0 datain;input31:0 addr;inputclk, we, inclk, outclk;output31:0dataout;wirewrite_enable = we & clk;lpm_ram_dqram (.data(datain),.addres

8、s(addr7:2),.we(write_enable),.inclock(inclk),.outclock(outclk),.q(dataout);defparamram.lpm_width=32;defparam ram.lpm_widthad=6;defparamram.lpm_indata=registered;defparamram.lpm_outdata=registered;defparamram.lpm_file=mcmem.mif;defparamram.lpm_address_control=registered;endmodule控制部件:module mccu (op,

9、 func, z, clock, resetn, wpc, wir, wmem, wreg, iord, regrt, m2reg, aluc, shift, alusrca, alusrcb, pcsource, jal, sext, state);input5:0op, func;inputz, clock, resetn;output regwpc, wir, wmem, wreg, iord, regrt, m2reg;output reg3:0aluc;output reg1:0alusrcb, pcsource;output regshift, alusrca, jal, sext

10、;output reg2:0state;reg2:0next_state;parameter2:0sif=3b000,/ IF statesid=3b001,/ ID statesexe=3b010,/ EXE statesmem=3b011,/ MEM stateswb=3b100;/ WB statewire r_type,i_add,i_sub,i_and,i_or,i_xor,i_sll,i_srl,i_sra,i_jr;wire i_addi,i_andi,i_ori,i_xori,i_lw,i_sw,i_beq,i_bne,i_lui,i_j,i_jal;and(r_type,op

11、5,op4,op3,op2,op1,op0);and(i_add,r_type, func5,func4,func3,func2,func1,func0);and(i_sub,r_type, func5,func4,func3,func2, func1,func0);and(i_and,r_type, func5,func4,func3, func2,func1,func0);and(i_or, r_type, func5,func4,func3, func2,func1, func0);and(i_xor,r_type, func5,func4,func3, func2, func1,fun

12、c0);and(i_sll,r_type,func5,func4,func3,func2,func1,func0);and(i_srl,r_type,func5,func4,func3,func2, func1,func0);and(i_sra,r_type,func5,func4,func3,func2, func1, func0);and(i_jr, r_type,func5,func4, func3,func2,func1,func0);and(i_addi,op5,op4, op3,op2,op1,op0);and(i_andi,op5,op4, op3, op2,op1,op0);a

13、nd(i_ori, op5,op4, op3, op2,op1, op0);and(i_xori,op5,op4, op3, op2, op1,op0);and(i_lw, op5,op4,op3,op2, op1, op0);and(i_sw, op5,op4, op3,op2, op1, op0);and(i_beq, op5,op4,op3, op2,op1, op0);and(i_bne, op5,op4,op3, op2,op1, op0);and(i_lui, op5,op4, op3, op2, op1, op0);and(i_j, op5,op4,op3,op2, op1,op

14、0);and(i_jal, op5,op4,op3,op2, op1, op0);wire i_shift;or (i_shift,i_sll,i_srl,i_sra);always * begin/ control signals dfault outputs:wpc=0;/do not write pcwir=0;/do not write irwmem=0;/ do not write memorywreg=0;/ do not write register fileiord=0;/ select pc as memory addressaluc=4bx000;/ ALU operati

15、on: addalusrca=0;/ ALU input a: reg a or saalusrcb=2h0;/ ALU input b: reg bregrt=0;/ reg dest no: rdm2reg=0;/ select reg cshift=0;/ select reg apcsource=2h0;/ select alu outputjal=0;/ not a jalsext=1;/ sign extendcase (state)/- IF:sif: begin/ IF statewpc=1;/ write pcwir=1;/ write IRalusrca=1;/ PCalu

16、srcb=2h1;/ 4next_state=sid;/ next state: IDend/- ID:sid: begin/ ID stateif (i_j) begin/ j instructionpcsource=2h3;/ jump addresswpc=1;/ write PCnext_state=sif;/ next state: IFendelse if (i_jal) begin/ jal instructionpcsource=2h3;/ jump addresswpc=1;/ write PCjal=1;/ reg no = 31wreg=1;/ save PC+4next

17、_state=sif;/ next state: IFendelse if (i_jr) begin/ jr instructionpcsource=2h2;/ jump registerwpc=1;/ write PCnext_state=sif;/ next state: IFendelse begin/ other instructionaluc=4bx000;/ addalusrca=1;/ PCalusrcb=2h3;/ branch offsetnext_state=sexe;/ next state: EXEendend/- EXE:sexe: begin/ EXE statea

18、luc3=i_sra;aluc2=i_sub | i_or | i_srl | i_sra | i_ori | i_lui ;aluc1=i_xor | i_sll | i_srl | i_sra | i_xori | i_beq | i_bne | i_lui ;aluc0=i_and | i_or | i_sll | i_srl | i_sra | i_andi | i_ori ;if (i_beq | i_bne) begin/ beq or bne instructionpcsource=2h1;/ branch addresswpc=i_beq & z | i_bne & z;/ w

19、rite PCnext_state=sif;/ next state: IFendelse begin/ other instructionif(i_lw | i_sw) begin/ lw or sw instructionalusrcb=2h2;/ select offsetnext_state=smem;/ next state: MEMendelse begin/ other instructionif (i_shift)shift=1;/ shift instructionif (i_addi | i_andi | i_ori | i_xori | i_lui)alusrcb=2h2

20、;/ select immediateif (i_andi | i_ori | i_xori)sext=0;/ 0-extendnext_state=swb;/ next state: WBendendend/- MEM:smem: begin/ MEM stateiord=1;/ memory address = Cif (i_lw) beginnext_state=swb;/ next state: WBendelse begin/ storewmem=1;/ write memorynext_state=sif;/ next state: IFendend/- WB:swb: begin

21、/ WB stateif (i_lw)m2reg=1;/ select memory dataif (i_lw | i_addi | i_andi | i_ori | i_xori | i_lui)regrt=1;/ reg dest no: rtwreg=1;/ write register filenext_state=sif;/ next state: IFend/- ENDdefault: beginnext_state=sif;/default stateendendcaseendalways (posedge clock or negedge resetn) begin/ stat

22、e registersif (resetn = 0) beginstate=sif;endelse beginstate=next_state;endendendmodule32位带使能端触发器:module dffe32 (d,clk,clrn,e,q);input31:0d;inputclk,clrn,e;output31:0q;reg31:0q;always (negedge clrn or posedge clk)if (clrn = 0) beginq = 0;endelse beginif(e = 1)q = d;endendmodule32位触发器:module dff32 (d

23、,clk,clrn,q);input31:0d;inputclk,clrn;output31:0q;reg31:0q;always (negedge clrn or posedge clk)if (clrn = 0) beginq = 0;endelse beginq = d;endendmoduleALU计算部件:module alu (a,b,aluc,r,z);input 31:0 a,b;input 3:0 aluc;output 31:0 r;output z;assign r = cal(a,b,aluc);assign z = |r;function 31:0 cal;input

24、 31:0 a,b;input 3:0 aluc;casex (aluc)4bx000: cal=a+b;4bx100: cal=a-b;4bx001: cal=a&b;4bx101: cal=a|b;4bx010: cal=ab;4bx110: cal=b15:0,16h0;4bx011: cal=ba4:0;4b1111: cal=$signed(b)a4:0;endcaseendfunctionendmodule其他部件:module f (reg_dest,jal,wn);input4:0reg_dest;input jal;output4:0wn;assignwn=reg_dest

25、| 5jal;endmodulemodule sa (di,dot);input 4:0 di;output 31:0 dot;assign dot = 27b0,di;endmodulemodule out4 (out);output 31:0 out;assign out = 32h4;endmodulemodule e (immin,sext,immediate,offset);input15:0immin;inputsext;output31:0 immediate,offset;wire e=sext & immin15;wire15:0imm=16e;assignoffset =i

26、mm13:0,immin15:0,1b0,1b0;assignimmediate= imm,immin15:0;endmodulemodule combine (address,pc,add);input25:0address;input3:0pc;output31:0add;assignadd=pc3:0,address25:0,1b0,1b0;endmodulemodule convert1 (dain,sain,op,func,rs,rt,rd,imm,addr);input31:0dain;output4:0sain,rs,rt,rd;output5:0op,func;output15

27、:0imm;output25:0addr;assignsain=dain10:6;assignop=dain31:26;assignfunc=dain5:0;assignrs=dain25:21;assignrt=dain20:16;assignrd=dain15:11;assignimm=dain15:0;assignaddr=dain25:0;endmodulemodule convert2 (pc,pcout);input31:0pc;output3:0pcout;assignpcout=pc31:28;endmodule七、实验检验与测试 存储器内的测试数据:- Copyright (

28、C) 1991-2013 Altera Corporation- Your use of Altera Corporations design tools, logic functions - and other software and tools, and its AMPP partner logic - functions, and any output files from any of the foregoing - (including device programming or simulation files), and any - associated documentati

29、on or information are expressly subject - to the terms and conditions of the Altera Program License - Subscription Agreement, Altera MegaCore Function License - Agreement, or other applicable license agreement, including, - without limitation, that your use is for the sole purpose of - programming l

30、ogic devices manufactured by Altera and sold by - Altera or its authorized distributors. Please refer to the - applicable agreement for further details.- Quartus II generated Memory Initialization File (.mif)DEPTH = 64;%Memory depth and width are required%WIDTH = 32;%Enter a decimal number%ADDRESS_R

31、ADIX = HEX;%Address and value radixes are optional%DATA_RADIX = HEX;%Enter BIN, DEC, HEX, or OCT; unless%otherwise specified, radixes = HEX%CONTENT BEGIN0.3F : 00000000;% Range-Every address from 0 to 3F = 00000000% 0 : 3c010000;% (00)main:luir1,0# address of data0% 1 : 34240080;% (04)orir4,r1,0x80#

32、 address of data0% 2 : 20050004;% (08)addir5,r0,4# counter% 3 : 0c000018;% (0c)call:jalsum# call function% 4 : ac820000;% (10)swr2,0(r4)# store result% 5 : 8c890000;% (14)lwr9,0(r4)# check sw% 6 : 01244022;% (18)subr8,r9,r4# sub: r8 - r9 - r4% 7 : 20050003;% (1c)addir5,r0,3# counter% 8 : 20a5ffff;%

33、(20)loop2:addir5,r5,-1# counter - 1% 9 : 34a8ffff;% (24)orir8,r5,0xffff# zero-extend: 0000ffff% A : 39085555;% (28)xorir8,r8,0x5555# zero-extend: 0000aaaa% B : 2009ffff;% (2c)addir9,r0,-1# sign-extend: ffffffff% C : 312affff;% (30)andir10,r9,0xffff# zero-extend: 0000ffff% D : 01493025;% (34)orr6,r10

34、,r9# or: ffffffff% E : 01494026;% (38)xorr8,r10,r9# xor: ffff0000% F : 01463824;% (3c)andr7,r10,r6# and: 0000ffff% 10 : 10a00001;% (40)beqr5,r0,shift# if r5 = 0, goto shift% 11 : 08000008;% (44)jloop2# jumploop2% 12 : 2005ffff;% (48)shift:addir5,r0,-1# r5 = ffffffff% 13 : 000543c0;% (4c)sllr8,r5,15#

35、 15 = ffff8000% 14 : 00084400;% (50)sllr8,r8,16# 16 = ffff8000(arith)% 16 : 000843c2;% (58)srlr8,r8,15# 15 = 0001ffff(logic)% 17 : 08000017;% (5c)finish: jfinish# dead loop% 18 : 00004020;% (60)sum:addr8,r0,r0# sum% 19 : 8c890000;% (64)loop:lwr9,0(r4)# load data% 1A : 20840004;% (68)addir4,r4,4# address + 4% 1B : 01094020;% (6c)addr8,r8,r9# sum% 1C : 20a5ffff;% (70)addir5,r5,-1# counter - 1% 1D : 14a0fffb;% (74)bner5,r0,loop# finish?% 1E : 00081000;% (78)sllr2,r8,0# move result to v0% 1F : 03e00008;% (7c)jrr31# return% 20 : 000000A3;% (80)da

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 其他杂项

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁