CPU模型機設計課程設計報告_第1頁
CPU模型機設計課程設計報告_第2頁
CPU模型機設計課程設計報告_第3頁
CPU模型機設計課程設計報告_第4頁
CPU模型機設計課程設計報告_第5頁
已閱讀5頁,還剩14頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、精選優(yōu)質文檔-傾情為你奉上CPU模型機設計CPU與存儲器連接課程設計報告 索 引:1課程設計的目的及要求32處理器的設計思想和設計內容33設計處理器的結構和實現(xiàn)方法34模型機的指令系統(tǒng)45處理器的狀態(tài)跳轉操作過程46. CPU的VHDL代碼77. 模型機在Quartus II環(huán)境下的應用148. 仿真波形159. 課程設計的總結17一 課程設計的目的及要求:1. 目的:了解Quartus II軟件的應用,學習Quartus II環(huán)境下設計CPU的基本過程;掌握CPU設計代碼的含義以及CPU的工作原理;了解CPU與內存RAM間的連接數據的傳輸過程;學習在Quartus II環(huán)境下建立模型機的具體

2、過程。融會貫通本課程各章節(jié)的內容,通過知識的綜合運用,加深對計算機系統(tǒng)各模塊的工作原理及相互聯(lián)系的認識。學習設計和調試計算機的基本步驟和方法,提高使用軟件仿真工具和集成電路的基本技能。培養(yǎng)科學研究的獨立工作能力,取得工程設計與組裝調試的實踐和經驗。 2.要求:以計算機組成與設計書中123頁的簡化模型為基礎,更改其指令系統(tǒng),形成設計者的CPU,在Quartus II環(huán)境下與主存連接,調試程序,觀察指令的執(zhí)行是否達到設計構想。二 處理器的設計思想和設計內容:處理器的字長為16b;包括四種指令格式,格式1、格式2、格式3的指令字長度為8b,格式4的指令字長度為16b;處理器內部的狀態(tài)機包括6個五個狀

3、態(tài)。關于CPU:操作碼4位,一共設計16條指令,主要包括空操作指令、中斷指令、加法指令、減法指令、三種邏輯運算指令、循環(huán)移位操作指令,數據傳輸指令,轉移類指令,特權指令等等。關于RAM:地址線設置成16bits,主存空間為64words。書中原CPU的主要修改:(1) 模型機CPU指令集中的邏輯左移與邏輯右移改成邏輯循環(huán)右移與邏輯循環(huán)左移。(2) 模型機CPU指令集中的or改成not。(3) 模型機CPU指令的執(zhí)行流程及狀態(tài)跳轉。三 設計處理器的結構和實現(xiàn)方法:(指令格式)格式1:寄存器尋址方式15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 OP Rx Ry 空白格

4、式2:立即數尋址方式15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 OP I 空白格式3:無操作數尋址方式15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 OP 空白 空白格式4:直接尋址方式15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 OP Addr四 模型機的指令系統(tǒng)CPU的指令集:操作碼OPIR(15.12)指令格式指 令 的 助 記 符指 令 的 內 容000003Idle無操作 PC=PC+1000012Load DataR0ßI 立即數操作000101Move Rx RyRx ß

5、(Ry) PC=PC+1000111Add Rx RyRx ß(Rx)+(Ry) PC=PC+1001001Sub Rx RyRx ß(Rx)-(Ry) PC=PC+1001011AND Rx RyRx ß(Rx) AND(Ry) PC=PC+1001101SHRLRx 邏輯右移PC=PC+1001111SHLL Rx邏輯左移PC=PC+1010001SHRC Rx循環(huán)右移PC=PC+1010011SHLC Rx循環(huán)左移PC=PC+1010101Swap Rx Ry Aß(Ry) Ryß(Rx) Rxß(A) PC=PC+101011

6、4Jmp AddrPCßAddr PC=PC+1011004Jz AddrIf (R0)=0 then PCßAddr else PC=PC+1011014Read AddrR0ß(Addr) PC=PC+1011104Write Addr Addrß(R0) PC=PC+1 011113Stop無操作 PC保持不變100001XNOR Rx RyRx ßnot(Rx) OR (Ry) )PC=PC+1100011OR Rx Ry Rx ß(Rx) OR (Ry) PC=PC+1100101XOR Rx RyRx ß(Rx)

7、 XOR (Ry) PC=PC+1100111NOT Rx RyRx ß(Rx) PC=PC+1101001NANDRx RyRx ßnot( (Rx) AND(Ry) PC=PC+1五 處理器的狀態(tài)跳轉操作過程:(1) 、模型機每一狀態(tài)下的操作及狀態(tài)跳轉當前狀態(tài)執(zhí)行操作次態(tài)與讀下一條指令的有關的操作St_0取指令IR(15.0)ßM_data_in(15.0)St_1Write-Readß0 PC=PC+1St_1IF OP=Load THENR0ßIR(11.8)|”0”MARßPCIF(OP=Stop)THENSt_1ELSE

8、St_2END IFIF OP=Move THEN Rx ß(Ry)IF OP= shrc THENRx ß(Rx)循環(huán)右移IF OP= shrl THEN Rx ß(Rx)循環(huán)左移IF OP= shrc THEN Rx ß(Rx)邏輯右移IF OP= shlc THEN Rx ß(Rx)邏輯左移IF OP= Add THEN Aß(Ry)IF OP= SUB THEN Aß(Ry)IF OP=NOT THEN Aß(Rx)IF OP= AND THEN Aß(Ry)IF OP= NAND THEN A&

9、#223;(Ry)IF OP= OR THEN Aß(Ry)IF OP= XOR THEN Aß(Ry)IF OP= NXOR THEN Aß(Ry)IF OP= Swap THEN Aß(Ry)IF OP=Stop THEN NULLIF OP=Idle THEN NULLIF OP=Jmp THEN NULLIF OP=Jz THEN NULLIF OP=Read THEN NULLIF OP=Write THEN NULLSt_2IF OP= Load OR OP=Move OR OP= SHRL OR OP=SHLL OR OP=Idle OR

10、OP= SHRC OR OP= SHLCTHEN NULLSt_0Write-Readß0IF OP= Add THEN Rx ß(Rx)+AIF OP= Sub THEN Rx ß(Rx)-AIF OP= AND THEN Rx ß(Rx)ANDAIF OP= NAND THEN Rx ß(Rx)NANDAIF OP= ORTHEN Rx ß(Rx)ORAIF OP= NOT THEN Rx ß NOT AIF OP= XOR THEN Rx ß(Rx) XORAIFOP=NXORTHENRxß(Rx)

11、 NXORAIF OP= Swap THEN Ryß(Rx)St_3Write-Readß0IF OP= Jmp THEN(PCßIR(1.0) MARßIR(10.0)IF OP= Jz THENIF (R0)=0 THEN(PCßIR(1.0) MARßIR(10.0)ELSE MARßPCIF OP= Read THEN MARßIR(10.0)IF OP= Write THEN MARßIR(11.0) MDAßR0St_3IF OP= Swap THEN Rxß(A)St_0

12、Write-Readß0IF OP= Jmp NOT OP= Jz St_0MARßPCWrite-Readß0IF OP= Write St_4MARßPCWrite-Readß0IF OP= Read St_4MARßPCWrite-Readß0St_4IF OP= Read THENR0ßM_data_inSt_0Write-Readß0(2) 、簡單指令執(zhí)行狀態(tài)描述讀內存指令:(1) St_0:取指令執(zhí)行以下操作;1)M_addressß(MAR) 把指令地址送到地址總線2)令Write

13、-Readß0 向內存發(fā)出讀命令(取指令)3)IR(15.0)ßM_data_in(15.0) 將讀出的指令加載于IR(15.0)4)PC=PC+1 至此指令已經全部取出,存在于IR(15.0),為取下一條指令準備地址(2) St_1:NULL 直接跳轉到下一狀態(tài)(3) St_2:MARßIR(10.0)將數據地址加載于MAR(4) St_3:1)M_addressß(MAR)把數據地址送到地址總線2)令Write-Readß0 向內存發(fā)出讀命令(取數據)3)MARßPC 把下一條指令地址加載于MAR(5) St_4:1)R0

14、3;M_data_in 將來自內存的數據加載于R0,本指令執(zhí)行完畢2)M_addressß(MAR) 把下一條指令地址送到地址總線3)令Write-Readß0 向內存發(fā)出讀命令(取下一條指令)4)下一狀態(tài)跳轉到St_0無條件轉移指令(1) St_0:取指令執(zhí)行以下操作;1)M_addressß(MAR) 把指令地址送到地址總線2)令Write-Readß0 向內存發(fā)出讀命令(取指令)3)IR(15.0)ßM_data_in(15.0) 將讀出的指令加載于IR(15.0)4)PC=PC+1 (此語句無用,因為程序計數器后續(xù)重新復制達到無條件轉移

15、目的)(2) St_1:NULL 直接跳轉到下一狀態(tài)(3) St_2:1)MARßIR(10.0) 將轉移目標地址加載于MAR2)PCßIR(10.0) 將轉移目標地址加載于PC(4) St_3:1) M_addressß(MAR) 把下一條指令地址送到地址總線2)令Write-Readß0 向內存發(fā)出讀命令(取下一條指令)3)下一狀態(tài)跳轉到St_0六.CPU的VHDL代碼:library ieee;use IEEE.std_logic_arith.all;use ieee.std_logic_1164.all;use ieee.std_logic_un

16、signed.all;package namespack isconstant idle : std_logic_vector(4 downto 0) :="00000"constant load : std_logic_vector(4 downto 0) :="00001"constant move : std_logic_vector(4 downto 0) :="00010"constant addp : std_logic_vector(4 downto 0) :="00011"constant subp

17、 : std_logic_vector(4 downto 0) :="00100"constant andp : std_logic_vector(4 downto 0) :="00101"constant shrl : std_logic_vector(4 downto 0) :="00110"constant shll : std_logic_vector(4 downto 0) :="00111"constant shrc : std_logic_vector(4 downto 0) :="0100

18、0"constant shlc : std_logic_vector(4 downto 0) :="01001"constant swap : std_logic_vector(4 downto 0) :="01010"constant jmp : std_logic_vector(4 downto 0) :="01011"constant jz : std_logic_vector(4 downto 0) :="01100"constant read : std_logic_vector(4 downt

19、o 0) :="01101"constant write : std_logic_vector(4 downto 0) :="01110"constant stop : std_logic_vector(4 downto 0) :="01111"constant xnorp : std_logic_vector(4 downto 0) :="10000"constant orp : std_logic_vector(4 downto 0) :="10001"constant xorp : std

20、_logic_vector(4 downto 0) :="10010"constant notp : std_logic_vector(4 downto 0) :="10011"constant nandp : std_logic_vector(4 downto 0) :="10100"end namespack;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use spack.all;entity cpu ispor

21、t( reset : in std_logic; clock : in std_logic; Write_Read: out std_logic; M_address: out std_logic_vector(10 downto 0); M_data_in: in std_logic_vector(15 downto 0); M_data_out: out std_logic_vector(15 downto 0); overflow: out std_logic);end cpu;architecture RTL of cpu is signal IR: std_logic_vector(

22、15 downto 0); signal MDR: std_logic_vector(15 downto 0); signal MAR: std_logic_vector(10 downto 0); signal state: integer range 0 to 4; beginstate_change: process(reset, clock, state ) beginif reset = '0' then state <= 0 ; elsif clock'event and clock = '0' then case state is w

23、hen 0 => state <= 1; when 1 => if IR(15 downto 11)= Stop then state <= 1; else state <= 2; end if; when 2 => case IR(15 downto 11) iswhen Swap|Jmp|Jz|Read|Write => state <= 3;when others => state <= 0;end case; when 3 => case IR(15 downto 11) is when Swap|Jmp|Jz=>

24、 state<=0; when others=> state<=4; end case; when others => state<=0; end case; elseNULL;end if;end process state_change; seq: process(reset,clock) variable PC:std_logic_vector(10 downto 0); variable R0,R1,R2,R3: std_logic_vector(15 downto 0); variable A: std_logic_vector(15 downto 0)

25、; variable temp: std_logic_vector(16 downto 0); begin if(reset='0') then IR <= (others=>'0'); PC := (others=>'0'); R0 := (others=>'0'); R1 := (others=>'0'); R2 := (others=>'0'); R3 := (others=>'0'); A := (others=>'0&

26、#39;); MAR <= (others=>'0'); MDR <= (others=>'0'); elsif(clock'event and clock='1') then overflow <= '0' case state is when 0=> IR <= M_data_in ; PC := PC+1; when 1=> if (IR(15 downto 11) /= Stop) then MAR <= PC; end if; case IR(15 downt

27、o 11) is when Load => R0:="0" & IR(10 downto 7); when Move => -Move Rx,Ry; case IR(10 downto 7) is when "0001"=> R0:=R1; when "0010"=> R0:=R2; when "0011"=> R0:=R3; when "0100"=> R1:=R0; when "0110"=> R1:=R2; when &

28、quot;0111"=> R1:=R3; when "1000"=> R2:=R0; when "1001"=> R2:=R1; when "1011"=> R2:=R3; when "1100"=> R3:=R0; when "1101"=> R3:=R1; when "1110"=> R3:=R2; when others=> NULL; end case; when Shrc => -cycle right

29、 shift case IR(10 downto 9) is when "00"=> R0:=R0(0)&R0(15 downto 1); when "01"=> R1:=R1(0)&R1(15 downto 1); when "10"=> R2:=R2(0)&R2(15 downto 1); when others=> R3:=R3(0)&R3(15 downto 1); end case; when Shlc => -cycle left shift case IR(1

30、0 downto 9) is when "00"=> R0:=R0(14 downto 0)&R0(15); when "01"=> R1:=R1(14 downto 0)&R1(15); when "10"=> R2:=R2(14 downto 0)&R2(15); when others=> R3:=R3(14 downto 0)&R3(15); end case; when Shrl => -logic right shift case IR(10 downto 9)

31、 is when "00"=> R0:='0'&R0(15 downto 1); when "01"=> R1:='0'&R1(15 downto 1); when "10"=> R2:='0'&R2(15 downto 1); when others=> R3:='0'&R3(15 downto 1); end case; when Shll => -logic left shift case IR(11 d

32、ownto 10) is when "00"=> R0:=R0(14 downto 0)&'0' when "01"=> R1:=R1(14 downto 0)&'0' when "10"=> R2:=R2(14 downto 0)&'0' when others=> R3:=R3(14 downto 0)&'0' end case; when Addp|Subp|Andp|Swap|orp|xorp|xnorp|n

33、andp|notp => case IR(8 downto 7) is when "00"=> A:=R0; when "01"=> A:=R1; when "10"=> A:=R2; when others=> A:=R3; end case; when others => NULL; end case; when 2=> -state 2 case IR(15 downto 11) is when Addp => -Rx:= Rx+A; case IR(10 downto 9) is

34、 when "00"=> temp := (R0(15) & R0(15 downto 0) + (A(15) & A(15 downto 0); R0:=temp(15 downto 0); overflow <= temp(16) XOR temp(15); when "01"=> temp :=(R1(15) & R1(15 downto 0) + (A(15) & A(15 downto 0); R1:=temp(15 downto 0); overflow <= temp(16) XOR

35、temp(15); when "10"=> temp :=(R2(15) & R2(15 downto 0) + (A(15) & A(15 downto 0); R2:=temp(15 downto 0); overflow <= temp(16) XOR temp(15); when others=> temp :=(R3(15) & R3(15 downto 0) + (A(15) & A(15 downto 0); R3:=temp(15 downto 0); overflow <= temp(16) XOR

36、temp(15); end case; when Subp => -Rx:= Rx-A; case IR(10 downto 9) is when "00"=> temp :=(R0(15) & R0(15 downto 0) + NOT(A(15) & A(15 downto 0) + 1; R0:=temp(15 downto 0); overflow <= temp(16) XOR temp(15); when "01"=> temp :=(R1(15) & R1(15 downto 0) + NOT

37、(A(15) & A(15 downto 0) + 1; R1:=temp(15 downto 0); overflow <= temp(16) XOR temp(15); when "10"=> temp :=(R2(15) & R2(15 downto 0) + NOT(A(15) & A(15 downto 0) + 1; R2:=temp(15 downto 0); overflow <= temp(16) XOR temp(15); when others=> temp :=(R3(15) & R3(15 d

38、ownto 0) + NOT(A(15) & A(15 downto 0) + 1; R3:=temp(15 downto 0); overflow <= temp(16) XOR temp(15); end case; when Swap => case IR(10 downto 7) is when "0100"=>R0:=R1; when "1000"=>R0:=R2; when "1100"=>R0:=R3; when "0001"=>R1:=R0; when &

39、quot;1001"=> R1:=R2; when "1101"=> R1:=R3; when "0010"=>R2:=R0; when "0110"=>R2:=R1; when "1110"=>R2:=R3; when "0111"=>R3:=R1; when "1011"=>R3:=R2; when "0011"=>R3:=R0; when others=> NULL; end case;

40、 when andp => case IR(10 downto 9) is when "00"=> R0:=R0 and A; when "01"=> R1:=R1 and A; when "10"=> R2:=R2 and A; when others=> R3:=R3 and A; end case; when nandp => case IR(10 downto 9) is when "00"=> R0:=not(R0 and A); when "01&qu

41、ot;=> R1:=not(R1 and A); when "10"=> R2:=not(R2 and A); when others=> R3:=not(R3 and A); end case; when orp => case IR(10 downto 9) is when "00"=> R0:=R0 or A; when "01"=> R1:=R1 or A; when "10"=> R2:=R2 or A; when others=> R3:=R3 or A;

42、 end case; when xorp => case IR(10 downto 9) is when "00"=> R0:=R0 XOR A; when "01"=> R1:=R1 XOR A; when "10"=> R2:=R2 XOR A; when others=> R3:=R3 XOR A; end case; when xnorp => case IR(10 downto 9) is when "00"=> R0:=not(R0 XOR A); when "01"=> R1:=not(R1 XOR A); when "10"=> R2:=not(R2 XOR A); when others=> R3:=not(R3 XOR A); end case; when notp=> case IR(10 downto 9) is when "00"=> R0:=not A; when "01"=> R1:=not A; when "10"=> R2:=not A; when others=> R3:=no

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論