




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上CPU模型机设计CPU与存储器连接课程设计报告 索 引:1课程设计的目的及要求32处理器的设计思想和设计内容33设计处理器的结构和实现方法34模型机的指令系统45处理器的状态跳转操作过程46. CPU的VHDL代码77. 模型机在Quartus II环境下的应用148. 仿真波形159. 课程设计的总结17一 课程设计的目的及要求:1. 目的:了解Quartus II软件的应用,学习Quartus II环境下设计CPU的基本过程;掌握CPU设计代码的含义以及CPU的工作原理;了解CPU与内存RAM间的连接数据的传输过程;学习在Quartus II环境下建立模型机的具体
2、过程。融会贯通本课程各章节的内容,通过知识的综合运用,加深对计算机系统各模块的工作原理及相互联系的认识。学习设计和调试计算机的基本步骤和方法,提高使用软件仿真工具和集成电路的基本技能。培养科学研究的独立工作能力,取得工程设计与组装调试的实践和经验。 2.要求:以计算机组成与设计书中123页的简化模型为基础,更改其指令系统,形成设计者的CPU,在Quartus II环境下与主存连接,调试程序,观察指令的执行是否达到设计构想。二 处理器的设计思想和设计内容:处理器的字长为16b;包括四种指令格式,格式1、格式2、格式3的指令字长度为8b,格式4的指令字长度为16b;处理器内部的状态机包括6个五个状
3、态。关于CPU:操作码4位,一共设计16条指令,主要包括空操作指令、中断指令、加法指令、减法指令、三种逻辑运算指令、循环移位操作指令,数据传输指令,转移类指令,特权指令等等。关于RAM:地址线设置成16bits,主存空间为64words。书中原CPU的主要修改:(1) 模型机CPU指令集中的逻辑左移与逻辑右移改成逻辑循环右移与逻辑循环左移。(2) 模型机CPU指令集中的or改成not。(3) 模型机CPU指令的执行流程及状态跳转。三 设计处理器的结构和实现方法:(指令格式)格式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四 模型机的指令系统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循环右移PC=PC+1010011SHLC Rx循环左移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五 处理器的状态跳转操作过程:(1) 、模型机每一状态下的操作及状态跳转当前状态执行操作次态与读下一条指令的有关的操作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)循环右移IF OP= shrl THEN Rx ß(Rx)循环左移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) 、简单指令执行状态描述读内存指令:(1) St_0:取指令执行以下操作;1)M_addressß(MAR) 把指令地址送到地址总线2)令Write
13、-Readß0 向内存发出读命令(取指令)3)IR(15.0)ßM_data_in(15.0) 将读出的指令加载于IR(15.0)4)PC=PC+1 至此指令已经全部取出,存在于IR(15.0),为取下一条指令准备地址(2) St_1:NULL 直接跳转到下一状态(3) St_2:MARßIR(10.0)将数据地址加载于MAR(4) St_3:1)M_addressß(MAR)把数据地址送到地址总线2)令Write-Readß0 向内存发出读命令(取数据)3)MARßPC 把下一条指令地址加载于MAR(5) St_4:1)R0
14、3;M_data_in 将来自内存的数据加载于R0,本指令执行完毕2)M_addressß(MAR) 把下一条指令地址送到地址总线3)令Write-Readß0 向内存发出读命令(取下一条指令)4)下一状态跳转到St_0无条件转移指令(1) St_0:取指令执行以下操作;1)M_addressß(MAR) 把指令地址送到地址总线2)令Write-Readß0 向内存发出读命令(取指令)3)IR(15.0)ßM_data_in(15.0) 将读出的指令加载于IR(15.0)4)PC=PC+1 (此语句无用,因为程序计数器后续重新复制达到无条件转移
15、目的)(2) St_1:NULL 直接跳转到下一状态(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 向内存发出读命令(取下一条指令)3)下一状态跳转到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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论