您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 计算机设计与实践-CPU-代码(含19条指令)
时钟管理模块entityclk_ctrlisport(Clk:instd_logic;Rst:instd_logic;k:outstd_logic_vector(3downto0));endclk_ctrl;architectureBehavioralofclk_ctrlissignaltmp:std_logic_vector(3downto0);beginprocess(Clk,Rst,tmp)beginifRst='1'then--rst=1复位;--k=0000;tmp=0001;elsifClk='1'andClk'eventthentmp(0)=tmp(3);tmp(3downto1)=tmp(2downto0);endif;endprocess;k=tmp;endBehavioral;取指模块entityirgetisPort(Rst:inSTD_LOGIC;--复位;Pcback:inSTD_LOGIC_VECTOR(15downto0);--PC回写;Pcbacka:inSTD_LOGIC;--PC回写允许;k1:inSTD_LOGIC;--时钟控制;Order:inSTD_LOGIC_VECTOR(15downto0);--指令Pcout:outSTD_LOGIC_VECTOR(15downto0);--PC输出;Orderout:outSTD_LOGIC_VECTOR(15downto0);--指令输出;AddrFlag:outSTD_LOGIC);--访址标志endirget;architectureBehavioralofirgetissignaltmpPC:std_logic_vector(15downto0);--指令地址;signalIR:std_logic_vector(15downto0);--指令寄存器;beginprocess(Rst,Pcback,Pcbacka,k1,order,tmpPc)beginifRst='1'thentmpPc=0000000000000000;elsifk1='1'thenPcout=tmpPc;AddrFlag='1';--第一个节拍高电平取指;elsifPcbacka='1'thentmpPc=Pcback;--pc回写允许---endif;--AddrFlag='0';elseAddrFlag='0';endif;Orderout=Order;--指令存入指令寄存器;endprocess;--Orderout=IR;--得到指令,准备送往后面的模块;endBehavioral;运算模块entityCPU_operationisPort(k2:inSTD_LOGIC;--时钟控制;k3:inSTD_LOGIC;--时钟控制;第三个时钟高电平改变标志寄存器的值;order:inSTD_LOGIC_VECTOR(15downto0);--命令输入;Pcin:inSTD_LOGIC_VECTOR(15downto0);--pc输入;Rst:inSTD_LOGIC;--复??;Rwb:inSTD_LOGIC_VECTOR(7downto0);--回写数据;Rwba:inSTD_LOGIC;--回?丛市???高电平有效Aluout:outSTD_LOGIC_VECTOR(15downto0);--计算结果输出;addr:outSTD_LOGIC_VECTOR(15downto0)--内存?刂??);endCPU_operation;architectureBehavioralofCPU_operationistyperegisarray(0to7)ofstd_logic_vector(7downto0);signalsreg:reg;signalF9:std_logic_vector(8downto0);--判断结果是否进位、是否为零;signalsregflag:std_logic_vector(1downto0);--标志寄存器;beginprocess(Rwb,Rwba,k2,order,sreg,Pcin,sregflag,F9)beginifRwba='1'thensreg(conv_integer(order(10downto8)))=Rwb;--回写endif;ifRst='1'thensreg(7)=00000000;sreg(6)=00000000;F9(8)='0';endif;ifk2='1'thencaseorder(15downto11)iswhen00000=--movRi,ImAluout(7downto0)=order(7downto0);Aluout(15downto8)=11111111;when00001=--LDARi,Xaddr(15downto8)=sreg(7);addr(7downto0)=order(7downto0);Aluout(15downto8)=11111111;when00010=--STARi,XAluout(7downto0)=sreg(conv_integer(order(10downto8)));Aluout(15downto8)=11111111;addr(7downto0)=order(7downto0);addr(15downto8)=sreg(7);when00011=--movRi,RjAluout(7downto0)=sreg(conv_integer(order(2downto0)));Aluout(15downto8)=11111111;when00100=--movRi,(Rj)addr(7downto0)=sreg(conv_integer(order(2downto0)));addr(15downto8)=sreg(7);when00101=--movRi,[R7//R6+x]addr=sreg(7)&sreg(6)+order(7downto0);when00110=--Adc,Ri,ImAluout(7downto0)=sreg(conv_integer(order(10downto8)))+order(7downto0)+sregflag(1);F9=('0'&sreg(conv_integer(order(10downto8))))+('0'&order(7downto0));Aluout(15downto8)=11111111;when00111=--Adc,Ri,Rj,Ri+Rj+Cy-RiAluout(7downto0)=sreg(conv_integer(order(10downto8)))+sreg(conv_integer(order(2downto0)))+sregflag(1);F9=('0'&sreg(conv_integer(order(10downto8))))+('0'&order(7downto0));Aluout(15downto8)=11111111;when01000=--SBBRi,ImAluout(7downto0)=sreg(conv_integer(order(10downto8)))-order(7downto0)-sregflag(1);F9=('0'&sreg(conv_integer(order(10downto8))))-('0'&order(7downto0));Aluout(15downto8)=11111111;when01001=--SBBRi,Rj,Ri-Rj-Cy-RiAluout(7downto0)=sreg(conv_integer(order(10downto8)))-sreg(conv_integer(order(2downto0)))-sregflag(1);F9=('0'&sreg(conv_integer(order(10downto8))))-('0'&order(7downto0));Aluout(15downto8)=11111111;when01010=--ANDRi,ImAluout(7downto0)=sreg(conv_integer(order(10downto8)))andorder(7downto0);F9(7downto0)=(sreg(conv_integer(order(10downto8))))and(order(7downto0));Aluout(15downto8)=11111111;when01011=--ANDRi,RjAluout(7downto0)=sreg(conv_integer(order(10downto8)))andsreg(conv_integer(order(2downto0)));F9(7downto0)=sreg(conv_integer(order(10downto8)))andorder(7downto0);Aluout(15downto8)=11111111;when01100=--ORRi,ImAluout(7downto0)=sreg(conv_integer(order(10downto8)))ororder(7downto0);F9(7downto0)=(sreg(conv_integer(order(10downto8))))or(order(7downto0));Aluout(15downto8)=11111111;when01101=--ORRi,RjAluout(7downto0)=sreg(conv_integer(order(10downto8)))orsreg(conv_integer(order(2downto0)));F9(7downto0)=(sreg(conv_integer(order(10downto8))))or(order(7downto0));Aluout(15downto8)=11111111;when10000=--JMPAddrAluout=sreg(7)&order(7downto0);when10001=--JZsignifsregflag(0)='1'theniforder(7)='0'thenAluout=Pcin+(00000000&order(7downto0));elseAluout=Pcin+(11111111&order(7downto0));endif;elseAluout=Pcin;endif;when10010=--JCsignifsregflag(1)='1'theniforder(7)='0'thenAluout=Pcin+(00000000&order(7downto0));elseAluout=Pcin+(11111111&order(7downto0));endif;elseAluout=Pcin;endif;whenothers=NULL;endcase;endif;endprocess;process(k3,F9,order)beginifrst='1'thensregflag(0)='0';sregflag(1)='0';elsifk3='1'thencaseorder(15downto12)iswhen0011|0101|0100|0110=sregflag(1)=F9(8);ifF9(7downto0)=00000000thensregflag(0)='1';elsesregflag(0)='0';endif;when0111=sregflag(0)=order(11);whenothers=null;endcase;endif;endprocess;endBehavioral;存储管理模块entityCPU_MomeryisPort(k3:i
本文标题:计算机设计与实践-CPU-代码(含19条指令)
链接地址:https://www.777doc.com/doc-6585941 .html