版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、實(shí)驗(yàn)四 多周期MIPS CPU +存儲(chǔ)器實(shí)驗(yàn)一實(shí)驗(yàn)?zāi)康?、深入理解MIPSCPU指令系統(tǒng)的功能和工作原理;2、掌握多周期CPU的工作原理和邏輯功能實(shí)現(xiàn);3、熟練掌握用Verilog HDL語言設(shè)計(jì)多周期存儲(chǔ)器的方法;4、熟練掌握對(duì)多周期存儲(chǔ)器的仿真實(shí)驗(yàn)驗(yàn)證和硬件測(cè)試兩種調(diào)試方法;5、通過對(duì)多周期CPU的運(yùn)行情況進(jìn)行觀察和分析,進(jìn)一步加深理解。二實(shí)驗(yàn)設(shè)備硬件:現(xiàn)代計(jì)算機(jī)組成原理實(shí)驗(yàn)系統(tǒng)(兼)Nios 32位嵌入式系統(tǒng)實(shí)驗(yàn)開發(fā)平臺(tái) EP1C12Q240Core(TM)i3-3240 CPU3.40GHz 3.39GHz 1.91GB的內(nèi)存軟件:QuartusII 13.0sp1 Microsoft
2、 Windows xp三實(shí)驗(yàn)內(nèi)容1、設(shè)計(jì)一個(gè)32位MIPS多周期CPU具體的要求如下: 至少運(yùn)行下列的6類32條MIPS指令。 (1)算術(shù)邏輯指令and、sub、addi (2)邏輯運(yùn)算指令and、0r、xor、 andi、 ori、xori(3)位移指令sll、srl、sra(4)條件分支指令beq、bne、(5)無條件跳轉(zhuǎn)指令j、jr (6)數(shù)據(jù)傳送指令lw、sw2.設(shè)計(jì)一個(gè)存儲(chǔ)器四實(shí)驗(yàn)原理與步驟實(shí)現(xiàn)上述原理框圖根據(jù)功能將其分劃分為控制單元(cunit)、執(zhí)行單元(eunit)、指令單元(iunit)以及存儲(chǔ)單元(munit)四大模塊。 (1).控制單元(cunit)是多周期微處理器的核心
3、控制微處理器取指令、指令譯碼和指令執(zhí)行等工作。主要由指令譯碼器控制器(outputs control)、算術(shù)邏輯運(yùn)算控制器(ALU control)兩個(gè)子模塊組成。 (2).執(zhí)行單元(eunit)主要由寄存器堆(registers)和算術(shù)邏輯單元(ALU)兩個(gè)子模塊組成。其中寄存器是微處理器最基本的元素MIPS系統(tǒng)的寄存器堆由32個(gè)32位寄存器組成而ALU則是微處理器的主要功能部件執(zhí)行加、減、比較等算術(shù)運(yùn)算和與、或、或非、異或等邏輯運(yùn)算。指令單元(iunit)的作用是決定下一條指令的地址PC值。 (3).存儲(chǔ)單元(munit)由存儲(chǔ)器(memory)、指令寄存器(instruction reg
4、ister)和存儲(chǔ)數(shù)據(jù)寄存器(memory data register)組成。五實(shí)驗(yàn)源代碼寄存器元件代碼: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;/readassign qb = (rnb = 0) ? 0 : registerrnb;/readalways (posedge clk
5、 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;output31:0y;function31:0select;input 31:0a0,a1,a2,a3;input 1
6、: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位二選一選擇器:module mux2x32 (a0,a1,s,y);input 31:0a0,a1;inputs;output31:0y
7、;assigny = s ? a1 : a0;endmodule存儲(chǔ)器元件: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),.address(addr7:2),.we(write_enable),.inclock(inclk),.outclock(outc
8、lk),.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, func, z, clock, resetn, wpc, wir, wmem, wreg, iord, regrt,
9、 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;output reg2:0state;reg2:0next_state;parameter2:0sif=3b000,
10、/ 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,op5,op4,op3,op2,op1,op0);and(i_add,r_type, func5,func4,func3,
11、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,func0);and(i_sll,r_type,func5,func4,func3,func2,func1,func0);a
12、nd(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);and(i_ori, op5,op4, op3, op2,op1, op0);and(i_xori,op5,op4, o
13、p3, 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,op0);and(i_jal, op5,op4,op3,op2, op1, op0);wire i_shift;or (i
14、_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 operation: addalusrca=0;/ ALU input a: reg a or saalusrcb=2h0;/ AL
15、U 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;/ PCalusrcb=2h1;/ 4next_state=sid;/ next state: IDend/- ID:sid: be
16、gin/ 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_state=sif;/ next state: IFendelse if (i_jr) begin/ jr inst
17、ructionpcsource=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 statealuc3=i_sra;aluc2=i_sub | i_or | i_srl | i_sra | i_ori | i_l
18、ui ;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;/ write PCnext_state=sif;/ next state: IFendelse begin/ other
19、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;/ select immediateif (i_andi | i_ori | i_xori)sext=0;/ 0-e
20、xtendnext_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/ WB stateif (i_lw)m2reg=1;/ select memory dataif (i_lw | i
21、_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/ state registersif (resetn = 0) beginstate=sif;endelse beginstat
22、e=next_state;endendendmodule32位帶使能端觸發(fā)器: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位觸發(fā)器:module dff32 (d,clk,clrn,q);input31:0d;inputclk,clrn;output31:0q;reg31:0q;
23、always (negedge clrn or posedge clk)if (clrn = 0) beginq = 0;endelse beginq = d;endendmoduleALU計(jì)算部件: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 31:0 a,b;input 3:0 aluc;casex (aluc)4bx000: cal=a+b;4bx100
24、: 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 | 5jal;endmodulemodule sa (di,dot);input 4:0 di;output 31:0
25、 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 =imm13:0,immin15:0,1b0,1b0;assignimmediate= imm,immin15:0;end
26、modulemodule 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:0imm;output25:0addr;assignsain=dain10:6;assignop=dain31:26
27、;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存儲(chǔ)器內(nèi)的測(cè)試數(shù)據(jù):- Copyright (C) 1991-2013 Altera Corporation- Your use of Altera Corporations desi
28、gn 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 documentation or information are expressly subject - to the terms and conditions
29、 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 logic devices manufactured by Altera and sold by - Altera or its autho
30、rized 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_RADIX = HEX;%Address and value radixes are optional%DATA_RADIX = HEX;%
31、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# address of data0% 2 : 20050004;% (08)addir5,r0,4# counter% 3 : 0c000
32、018;% (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;% (20)loop2:addir5,r5,-1# counter - 1% 9 : 34a8ffff;% (24)orir8,r5,0xff
33、ff# 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,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
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026年人力資源管理師人力資源規(guī)劃基礎(chǔ)練習(xí)(含解析)
- 2026山東聊城市城發(fā)建設(shè)集團(tuán)有限公司、聊城市城發(fā)資產(chǎn)運(yùn)營(yíng)有限公司、聊城旭坤數(shù)字技術(shù)有限公司招聘5人備考考試試題及答案解析
- 2026廣東江門市廣悅化工股份有限公司招聘80人備考考試題庫(kù)及答案解析
- 2026年度淄博沂源縣事業(yè)單位公開招聘綜合類崗位工作人員(13人)考試備考試題及答案解析
- 2026廣東廣州銀行選聘參考考試題庫(kù)及答案解析
- 建業(yè)車庫(kù)施工方案(3篇)
- 新店酒館活動(dòng)策劃方案(3篇)
- 車庫(kù)轉(zhuǎn)盤施工方案(3篇)
- 物流機(jī)械維護(hù)室管理制度(3篇)
- 飛機(jī)培訓(xùn)課件
- (2025年)廣東省事業(yè)單位集中招聘筆試試題及答案解析
- 關(guān)于行政管理畢業(yè)論文
- 《刑法修正案安全生產(chǎn)相關(guān)內(nèi)容》知識(shí)培訓(xùn)
- 2024年南充市高坪區(qū)醫(yī)療衛(wèi)生輔助崗招募筆試真題
- 農(nóng)業(yè)消防知識(shí)培訓(xùn)課件
- 船舶危險(xiǎn)源 機(jī)艙風(fēng)險(xiǎn)源清單
- 物業(yè)催費(fèi)技巧培訓(xùn)
- 辦公樓物業(yè)服務(wù)投標(biāo)方案(技術(shù)方案)
- 品質(zhì)例會(huì)管理制度
- DG-TJ08-2235-2024 地下建筑增擴(kuò)與改建技術(shù)標(biāo)準(zhǔn)
- 山東省菏澤市牡丹區(qū)2024-2025學(xué)年八年級(jí)上學(xué)期期末語文試題(含答案)
評(píng)論
0/150
提交評(píng)論