精品简单CPU系统设计及实现.docx

上传人:b****7 文档编号:10023220 上传时间:2023-02-08 格式:DOCX 页数:26 大小:663.25KB
下载 相关 举报
精品简单CPU系统设计及实现.docx_第1页
第1页 / 共26页
精品简单CPU系统设计及实现.docx_第2页
第2页 / 共26页
精品简单CPU系统设计及实现.docx_第3页
第3页 / 共26页
精品简单CPU系统设计及实现.docx_第4页
第4页 / 共26页
精品简单CPU系统设计及实现.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

精品简单CPU系统设计及实现.docx

《精品简单CPU系统设计及实现.docx》由会员分享,可在线阅读,更多相关《精品简单CPU系统设计及实现.docx(26页珍藏版)》请在冰豆网上搜索。

精品简单CPU系统设计及实现.docx

精品简单CPU系统设计及实现

 

简单CPU系统设计及实现

数字电路综合实验报告

 

简单CPU系统设计与实现

1设计课题的任务要求

设计一个简单的CPU及其外部模块,能够完成机器代码的输入、存储、执行和结果显示。

基本要求:

指令要求至少有空指令,跳转指令,加法指令,存取数据指令。

利用自己设计的指令系统编写一段机器语言,可以完成求两个小于256的数的最大公约数。

机器语言通过拨码开关和按键逐条输入,通过程序执行开关控制程序执行,最后在数码管或LED灯上显示结果。

提高要求:

设计并实现其它指令。

2系统设计

2.1设计思路

设计的简易CPU系统主要由指令存储器(可以通过拨码和按键读入指令)、控制器、内部寄存器、内存以及ALU构成。

设计过程重点考虑如下事项:

读/写寄存器,读/写存储器以及执行指令。

通过执行读入的指令以及编写好的求两个数的最大公约数的程序来测试该系统的功能。

2.2总体框图

2.2.1系统总体框图

由设计思路,可绘制如下的简单CPU系统总体框图:

最终在quartusII中连接好的CPU系统图如下所示(其中的ACC属于ALU部件):

2.2.2系统状态转移图

如上图,系统共有3个状态:

S0、S1、S2。

分别为S0:

在这一状态,通过拨码和按键录入要执行的指令。

S1:

在这一状态,CPU执行程序,即S0录入的指令。

S2:

在这一状态,CPU执行完全部程序,等待再次执行或等待录入指令。

2.2.3求解最大公约数的程序框图

设a,b为给定的两个整数,用辗转相减法求解他们的最大公约数:

 

 

 

 

 

2.3分块设计

2.3.1DIV(分频器)

DIV将电路板所提供的时钟分频,产生CPU工作所需要的时钟以及数码管扫描所需要的时钟。

2.3.2MCU(控制器)

MCU用来产生系统内部所有寄存器、运算单元所需的控制信号,以及执行各条指令所需要的微操作。

它是整个系统设计的核心所在。

2.3.3ALU(算术逻辑运算单元)

ALU完成数据的算术和逻辑运算。

ALU有5个输入端和2个输出端,其中一个操作数固定来自累加器acc(具体编程时可用变量或信号表示),另一个操作数来自端口mbr_in(通过数据总线接到寄存器MBR)。

参加运算的操作数在ALU中进行规定的操作运算,运算结束后,一方面将结果送至累加器,同时将操作结果的特征状态送标志寄存器。

2.3.4MAR(地址寄存器)

MAR存放着要被读取或写入的内存单元地址。

其中,读操作时,CPU从内存读。

而写操作时,CPU把数据写入内存。

2.3.5MBR(缓冲寄存器)

MBR存放了将要存储到内存的数据或者从内存中读取的最新数据。

MBR连接到系统总线中的地址总线。

2.3.6RAM(随机存取存储器)

RAM有着相对独立的输入输出管脚,在本系统设计中它作为内存使用。

它不是CPU内部的寄存器,不属于CPU的一部分。

但要测试所设计的CPU的性能,需要把RAM加进系统设计中。

2.3.7SMG(数码管显示)

SMG负责将运算结果转化为BCD码形式,然后用数码馆显示。

 

3仿真波形及波形分析

 

根据波形图可以看出状态机的运行,其中一个状态占两个时钟周期。

该仿真相当于CPU执行指令的时序图,反映了程序运行情况。

还包括了辗转相减法的仿真,和rst的清零仿真。

可以看出该CPU系统的仿真结果正确,达到下载的要求。

 

4源程序(含注释)

各个部件对应的源程序如下(最后的连接是用图形连接完成的):

4.1DIV(分频器)

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityDIVis

port

clk_in:

instd_logic;

clk_out1:

outstd_logic;

clk_out2:

outstd_logic

);

endDIV;

architecturebehaveofDIVis

signaltmp:

std_logic_vector(15downto0);

begin

process(clk_in,tmp)

begin

if(clk_in'eventandclk_in='1')then

tmp<=tmp+1;

endif;

clk_out1<=tmp(0);

clk_out2<=tmp

(1);

endprocess;

endbehave;

4.2MCU(控制器)

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityMCUis

port

clk:

instd_logic;

start:

instd_logic;

opcode:

instd_logic_vector(3downto0);

cmp:

instd_logic;

ctr:

outstd_logic_vector(10downto0)

);

endMCU;

architecturebehaveofMCUis

begin

process(clk,start)

variablestatus:

std_logic_vector(4downto0):

="00000";

begin

if(start='1')then

status:

="00001";

elsif(clk'eventandclk='1')then

casestatusis

when"00001"=>ctr<="00010000000";status:

=status+1;--MBR<-RAM

when"00010"=>ctr<="00001000000";status:

=status+1;--MAR<-MBR

when"00011"=>--DECODING

caseopcodeis

when"0001"=>status:

="00100";ctr<="00100000000";--Store--MBR<-ACC

when"0010"=>status:

="00101";ctr<="00010000000";--Load--MBR<-RAM

when"0011"=>status:

="00111";ctr<="00010000000";--Add--MBR<-RAM

when"0100"=>status:

="01001";ctr<="00010000000";--Sub--MBR<-RAM

when"0101"=>status:

="11111";ctr<="00000000011";--SHL--ACC<-ACC<<1

when"0110"=>status:

="11111";ctr<="00000000100";--SHR--ACC<-ACC>>1

when"0111"=>status:

="01011";ctr<="00010000000";--And--MBR<-RAM

when"1000"=>status:

="01101";ctr<="00010000000";--Or--MBR<-RAM

when"1001"=>status:

="11111";ctr<="00000000111";--Not--ACC<-NOTACC

when"1010"=>status:

="00001";ctr<="00000000000";--Jump

when"1011"=>if(cmp='0')then--JumpZ

status:

="00001";ctr<="00000100000";

else

status:

="00001";ctr<="00000000000";

endif;

when"1100"=>status:

="11111";ctr<="10000000000";--Smg

when"1111"=>status:

="00000";ctr<="00000000000";--Halt

whenothers=>ctr<="00000000000";status:

="11111";

endcase;

when"00100"=>ctr<="01000000000";status:

="11111";--Store--RAM<-MBR

when"00101"=>ctr<="00000011111";status:

=status+1;--Load--BR<-MBR;ACC<-0

when"00110"=>ctr<="00000000001";status:

="11111";--ACC<-ACC+BR

when"00111"=>ctr<="00000010000";status:

=status+1;--Add--BR<-MBR

when"01000"=>ctr<="00000000001";status:

="11111";--ACC<-ACC+BR

when"01001"=>ctr<="00000010000";status:

=status+1;--Sub--BR<-MBR

when"01010"=>ctr<="00000000010";status:

="11111";--ACC<-ACC-BR

when"01011"=>ctr<="00000010000";status:

=status+1;--And--BR<-MBR

when"01100"=>ctr<="00000000101";status:

="11111";--ACC<-ACCANDBR

when"01101"=>ctr<="00000010000";status:

=status+1;--Or--BR<-MBR

when"01110"=>ctr<="00000000110";status:

="11111";--ACC<-ACCORBR

when"01111"=>ctr<="00000010000";status:

=status+1;--Mutiply--BR<-MBR

when"10000"=>ctr<="00000001000";status:

="11111";--ACC<-ACC*BR

when"11111"=>ctr<="00000100000";status:

="00001";--PC<-PC+1;MAR<-PC

when"00000"=>ctr<="00000000000";status:

="00000";

whenothers=>ctr<="00000000000";status:

="00001";

endcase;

endif;

endprocess;

endbehave;

4.3ALU(算术逻辑运算单元)

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityALUis

port

clk:

instd_logic;

rst:

instd_logic;

mbr_in:

instd_logic_vector(11downto0);

mbr_e:

instd_logic;

ctrl:

instd_logic_vector(3downto0);

overflow:

outstd_logic;

acc:

outstd_logic_vector(11downto0)

);

endALU;

architecturebehaveofALUis

begin

process(clk,rst)

variablebr:

std_logic_vector(11downto0);

variabledata_acc:

std_logic_vector(11downto0);

begin

if(clk'eventandclk='1')then

if(rst='1')then

acc<="000000000000";

br:

="000000000000";

data_acc:

="000000000000";

elsif(mbr_e='1')then

br:

=mbr_in;

elsenull;

endif;

casectrlis

when"1111"=>acc<="000000000000";

data_acc:

="000000000000";

when"0001"=>data_acc:

=data_acc+br;

when"0010"=>data_acc:

=data_acc-br;

when"0011"=>data_acc:

=data_acc(10downto0)&'0';

when"0100"=>data_acc:

='0'&data_acc(11downto1);

when"0101"=>data_acc:

=data_accandbr;

when"0110"=>data_acc:

=data_accorbr;

when"0111"=>data_acc:

=notdata_acc;

whenothers=>null;

endcase;

endif;

acc<=data_acc;

overflow<=data_acc(11);

endprocess;

endbehave;

4.4MAR(地址寄存器)

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityMARis

port

clk:

instd_logic;

rst:

instd_logic;

mbr_low:

instd_logic_vector(7downto0);

mbr_e:

instd_logic;

add:

instd_logic;

mar:

outstd_logic_vector(7downto0)

);

endMAR;

architecturebehaveofMARis

begin

process(clk,rst)

variablepc:

std_logic_vector(7downto0);

variablemar_mid:

std_logic_vector(7downto0);

begin

if(clk'eventandclk='1')then

if(rst='1')then

pc:

="00000000";

mar_mid:

="00000000";

elsif(mbr_e='1')then

pc:

=mar_mid;

mar_mid:

=mbr_low;

elsif(add='1')then

pc:

=pc+1;

mar_mid:

=pc;

elsenull;

endif;

endif;

mar<=mar_mid;

endprocess;

endbehave;

4.5MBR(缓冲寄存器)

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityMBRis

port

clk:

instd_logic;

ram_in:

instd_logic_vector(11downto0);

acc_in:

instd_logic_vector(11downto0);

ram_e:

instd_logic;

acc_e:

instd_logic;

rst:

instd_logic;

mbr:

outstd_logic_vector(11downto0)

);

endMBR;

architecturebehaveofMBRis

begin

process(clk,rst)

begin

if(clk'eventandclk='1')then

if(rst='1')then

mbr<="000000000000";

elsif(acc_e='1')then

mbr<=acc_in;

elsif(ram_e='1')then

mbr<=ram_in;

elsenull;

endif;

endif;

endprocess;

endbehave;

4.6RAM(随机存取存储器)

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityRAMis

port

clk_ram:

instd_logic;

w_r:

instd_logic;

code_e:

instd_logic;

mbr_in:

instd_logic_vector(11downto0);

mar_in:

instd_logic_vector(7downto0);

ram_in:

instd_logic_vector(7downto0);

ram_out:

outstd_logic_vector(11downto0);

ram_outt:

outstd_logic_vector(7downto0)

);

endRAM;

architecturebehaveofRAMis

begin

process(clk_ram)

typetableisarray(0to20)ofstd_logic_vector(11downto0);

variableram:

table;

variablei:

integerrange0to31:

=0;

variablej:

std_logic:

='0';

variablecode_e1:

std_logic;

begin

if(clk_ram'eventandclk_ram='1')then

if(code_e='1'andcode_e1='0'andj='0')then

ram(i)(11downto8):

=ram_in(3downto0);

ram_outt(7downto4)<="1000";

ram_outt(3downto0)<=ram(i)(11downto8);

j:

='1';

elsif(code_e='1'andcode_e1='0'andj='1')then

ram(i)(7downto0):

=ram_in(7downto0);

ram_outt<=ram(i)(7downto0);

j:

='0';

i:

=i+1;

elsif(w_r='1')then

ram(conv_integer(mar_in)):

=mbr_in;

elsif(w_r='0')then

ram_out<=ram(conv_integer(mar_in));

elsenull;

endif;

code_e1:

=code_e;

endif;

endprocess;

endbehave;

4.7SMG(数码管显示)

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

useieee.std_logic_arith.all;

 

entitySMGis

port

clk:

instd_logic;

smg_en:

instd_logic;

n:

instd_logic_vector(11downto0);

count:

outstd_logic_vector(6downto0);

count_en:

outstd_logic_vector(5downto0)

);

endSMG;

architecturebehaveofSMGis

signala_temp:

std_logic_vector(3downto0);

signaln1,n2,n3:

std_logic_vector(3downto0);

begin

p1:

process(n)

variablea:

integerrange0to127;

variableb,c,d:

integerrange0to9;

begin

a:

=conv_integer(n);

d:

=amod10;

c:

=(a/10)mod10;

b:

=a/100;

n1<=conv_std_logic_vector(b,4);

n2<=conv_std_logic_vector(c,4);

n3<=conv_std_logic_vector(d,4);

endprocess;

p2:

process(clk)

variabletemp:

integer:

=4;

variabletmp:

std_logic_vector(1downto0);

variablergs:

std_logic;

begin

ifclk'eventandclk='1'then

tmp:

=tmp+1;

if(smg_en='1')then

temp:

=0;

elsenull;

endif;

if(tmp

(1)='1'andrgs='0')then

iftemp=2thentemp:

=0;

elsetemp:

=temp+1;

endif;

casetempis

when0=>count_en<="011111";a_temp<=n1;

when1=>count_en<="101111";a_temp<=n2;

when2=>count_en<="110111";a_temp<=n3;

whenothers=>count_en<="111111";

endcase;

endif;

rgs:

=tmp

(1);

endif;

endprocess;

p3:

process(a_temp)

begin

casea_tempis

when"0000"=>count<="1111110";

when"0001"=>count<="0110000";

when"0010"=>count<="1101101";

when"0011"=>count<="1111001";

w

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 解决方案

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1