湘 潭 大 学 实 验 报 告课程名称 计算机原理与设计 实验名称 控制器实验 页数专业 班级 同组者姓名 无 组别 学号 姓名 实验日期一、实验目的1.了解多周期 MIPS CPU 的控制部件的总体结构。
2.掌握多周期 MIPS CPU 的控制部件的状态转移。
3.掌握用 Verilog HDL 实现有限状态机的常用方法。
4.验证实验台多周期 MIPS CPU 控制部件的控制信号产生功能。
二、实验要求1、做好实验预习:要求掌握周期 MIPS CPU 的控制部件的总体结构以及状态转移,并熟悉本实验中所用的控制台开关的作用和使用方法。
2、记录实验结果,包括以下内容:①根据操作结果填好控制信号的真值表;②按理论分析值给出对应的仿真波形。
3、写出实验报告,包括以下内容:①列表比较实验数据的理论分析值与实验结果值;并对结果进行分析。
实验结果与理论 分析值比较,有没有不同?为什么?②通过本实验,你对周期MIPS CPU的控制部件的总体结构有何认识,有什么心得体会?三、实验原理多周期 MIPS CPU 的控制部件的总体结构如图 3-2-1 所示。
多周期 MIPS CPU 的控制部件的状态转移如图 3-2-2 所示。
本实验根据状态及指令直接对控制信号赋值,使用中间变量 next_state,意为下一状态。
在当前状态中,根据指令对 next_state 赋值,并在每个时钟上升沿把 next_state 打入状态寄 存器,这是用 Verilog HDL 实现有限状态机时常用的方法。
模块设计如图 3-2-3 所示。
图 3-2-1 多周期 MIPS CPU 的控制部件的总体结构图图 3-2-2 多周期 MIPS CPU 的控制部件的状态状态转移图四、实验内容(1)设计元件 在 Quartus II 环境下,用文本输入编辑器 Text Editor 输入 mccu.v 单元文件,编译 VerilogHDL 文件,并将 mccu.v 单元文件制作成可调用的原理图元件。
(2)以原理图方式建立顶层文件工程 选择图形方式。
根据图 3-2-3 输入实验电路图,从 Quartus II 的基本元件库中将各元件调 入图形编辑窗口、连线,添加输入输出引脚。
将所设计的图形文件保存到原先建立的文件夹中,将当前文件设置成工程文件,以后的 操作就都是对当前工程文件进行的。
(3)器件选择 选择 Cyclone 系列,在 Devices 中选择器件 EP1C12QC240C8。
编译,引脚锁定,再编译。
引脚锁定后需要再次进行编译,才能将锁定信息确定下来,同时生成芯片编程/配置所需要 的各种文件。
(4)芯片编程 Programming(可以直接选择光盘中的示例已完成的设计进行验证实验)打开编程窗口。
将配置文件 mccu.sof 下载进 GW48 系列现代计算机组成原理系统中的 FPGA 中。
(5)选择实验系统的电路模式是 NO.0,验证控制部件的功能 设置 opfunc[5..0]、clk、op_func、z、clock、resetn 的值,验证控制部件的功能,记录实 验数据。
五、 实验环境与设备GW48CP+主系统、pc机六、实验代码设计(含符号说明)module mccu (op,func,z,clock,resetn,wpc,wir,wmem,wreg,iord,regrt,m2reg,aluc,shift ,alusrca,alusrcb,pcsource,jal,sext,state);input [5:0] op,func;input z,clock,resetn;output reg wpc,wir,wmem,wreg,iord,regrt,m2reg;output reg [3:0] aluc;output reg [1:0] alusrcb,pcsource;output reg shift,alusrca,jal,sext;output reg [2:0] state;reg [2:0] next_state;parameter [2:0] sif = 3'b000,sid = 3'b001,sexe = 3'b010,smem = 3'b011,swb = 3'b100;wire r_type,i_add,i_sub,i_and,i_or,i_xor,i_sll,i_srl,i_sra,i_jr;wirei_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[5],~op[4],~op[3],~op[2],~op)and(r_type,~op[5],~op[4],~op[3],~op[2],~op[1],~op[0]);and(i_add,r_type,func[5],~func[4],~func[3],~func[2],~func[1],~fun c[0]);and(i_sub,r_type,func[5],~func[4],~func[3],~func[2],func[1],~func [0]);and(i_and,r_type,func[5],~func[4],~func[3],func[2],~func[1],~func [0]);and(i_or,r_type,func[5],~func[4],~func[3],func[2],~func[1],func[0 ]);and(i_xor,r_type,func[5],~func[4],~func[3],func[2],func[1],~func[ 0]);and(i_sll,r_type,~func[5],~func[4],~func[3],~func[2],~func[1],~fu nc[0]);and(i_srl,r_type,~func[5],~func[4],~func[3],~func[2],func[1],~fun c[0]);and(i_sra,r_type,~func[5],~func[4],~func[3],~func[2],func[1],func [0]);and(i_jr,r_type,~func[5],~func[4],func[3],~func[2],~func[1],~func [0]);and(i_addi,~op[5],~op[4],op[3],~op[2],~op[1],~op[0]);and(i_andi,~op[5],~op[4],op[3],op[2],~op[1],~op[0]);and(i_ori,~op[5],~op[4],op[3],op[2],~op[1],op[0]);and(i_xori,~op[5],~op[4],op[3],op[2],op[1],~op[0]);and(i_lw,op[5],~op[4],~op[3],~op[2],op[1],op[0]);and(i_sw,op[5],~op[4],op[3],~op[2],op[1],op[0]);and(i_beq,~op[5],~op[4],~op[3],op[2],~op[1],~op[0]);and(i_bne,~op[5],~op[4],~op[3],op[2],~op[1],op[0]);and(i_lui,~op[5],~op[4],~op[3],op[2],op[1],op[0]);and(i_j,~op[5],~op[4],~op[3],~op[2],op[1],~op[0]);and(i_jal,~op[5],~op[4],~op[3],~op[2],op[1],op[0]);wire i_shift;or (i_shift,i_sll,i_srl,i_sra);always @ * beginwpc = 0;wir = 0;wmem = 0;wreg = 0;iord = 0;aluc = 4'bx000;alusrca = 0;alusrcb = 2'h0;regrt = 0;m2reg = 0;shift = 0;pcsource = 2'h0;jal = 0;sext = 1;case (state)sif:beginwpc = 1;wir = 1;alusrca = 1;alusrcb = 2'h1;next_state = sid;endsid:beginif(i_j)beginpcsource = 2'h3;wpc = 1;next_state = sif;endelse if(i_jal)beginpcsource = 2'h3;wpc = 1;jal = 1;wreg = 1;next_state = sif;endelse if(i_jr)beginpcsource = 2'h2;wpc = 1;next_state = sif;endelse beginaluc = 4'bx000;alusrca = 1;alusrcb = 2'h3;next_state = sexe;endendsexe:beginaluc[3] = i_sra;aluc[2] = i_sub | i_or | i_srl | i_sra | i_ori | i_lui;aluc[1] = i_xor | i_sll| i_srl | i_sra | i_xori| i_beq | i_bne | i_lui;aluc[0] = i_and | i_or | i_sll | i_srl | i_sra | i_andi| i_ori;if(i_beq || i_bne) beginpcsource = 2'h1;wpc = i_beq & z | i_bne & ~z;next_state = sif;endelse beginif(i_lw || i_sw) beginalusrcb = 2'h2;next_state = smem;endelse beginif(i_shift) shift = 1;if(i_addi || i_andi || i_ori || i_xori ||i_lui)alusrcb = 2'h2;if(i_andi || i_ori || i_xori)next_state = swb;endendendsmem:beginiord = 1;if(i_lw) beginnext_state = swb;end else beginwmem = 1;next_state = sif;endendswb:beginif(i_lw) m2reg = 1;if(i_lw || i_addi || i_andi || i_ori || i_xori ||i_lui) regrt = 1;wreg = 1;next_state = sif;enddefault:beginnext_state = sif;endendcaseendalways @ (posedge clock or negedge resetn)beginif(resetn == 0) beginstate <= sif;endelse beginstate <= next_state;endendendmodule七、实验检验与测试仿真结果波形图:引脚分配截图:八、 测试数据状态Q [2..0]i n s tz w p cP c s o u r c ew i ri o r dw m e ma l u c [3..0]s e l p cs h i f ta l u s r cb [1..0]s e x tw r e gm 2r e gr e g r t j a l IF 000 x x 1 00 1 0 0 x000 1 x 01 x 0 x x x ID 001j x 1 11 0 x 0 xxxx x x xx x 0 x x x jalx 1 11 0 x 0 xxxx x x xx x 1 x x 1 jr x 1 10 0 x 0 xxxx x x xx x 0 x x x JP x 0 xx 0 x 0 x000 1 x 11 1 0 x x x EXE 010 add x 0 xx 0 x 0 x000 0 0 00 x 0 x x x sub x 0 0 0 0 0 0100 0 0 00 1 0 x x x and x 0 0 0 0 0 0001 0 0 00 1 0 x x x or x 0 0 0 0 0 0101 0 0 00 1 0 x x x xorx 0 0 0 0 0 0010 0 0 00 1 0 x x x sll x 0 xx 0 x 0 0011 0 1 00 x 0 x x x srl x 0 0 0 0 0 0111 0 1 00 1 0 x x x sra x 0 0 0 0 0 1111 0 1 00 1 0 x x x addi x 0 0 0 0 0 0000 0 0 10 1 0 x x x andi x 0 0 0 0 0 0001 0 0 10 1 0 x x x orix0101101xxxxori x 0 0 0 0 0 0010 0 0 10 1 0 x x x lui x 0 xx 0 x 0 x110 x x 10 x 0 x x xEXE 010 beq0 001 0 x 0 x100 0 0 00 x 0 x x x1 1bne0 101 0 x 0 x100 0 0 00 x 0 x x x1 0EXE 010 m_typex x 0 xx 0 x 0 x000 0 0 10 1 0 x x x MEM 011 i_lw x 0 xx 0 1 0 xxxx x x xx x 0 x x x MEM 011 i_sw x 0 xx 0 1 1 xxxx x x xx x 0 x x x WB 100R_type x 0 xx 0 x 0 xxxx x x xx x 1 0 0 0I_type x 0 xx 0 x 0 xxxx x x xx x 1 0 1 0 WB 100 i_lw x 0 xx 0 x 0 xxxx x x xx x 1 1 1 0注:红色部分为实验记录的数据内容。