
实验要求:
按照题目要求用硬布线(组合逻辑)控制法设计一个简单模型机的控制单元CU(微操作信号产生电路),决定外部的端口(名称、有效电平)和内部各元件的连接,画出系统框图和逻辑图,设计仿真数据,用VHDL编程和仿真。
主要元件设计:
1.指令译码器
功能要求:3-8译码器。
2.控制单元
功能要求:假设该模型机有不同类型的指令。包括:算术运算、逻辑运算、移位、数据传送、访存操作、转移等。根据每条指令的功能和时序,分析其执行过程中需要在各个阶段产生的全部微操作,导出产生这些微操作控制信号的逻辑。
3.用层次结构设计的方法设计一个控制单元CU(微操作控制信号产生电路)。包括指令译码器和控制单元。
功能要求:能够正确产生不同指令在执行过程中(每个机器周期、每拍)发出的全部微操作。
二、逻辑设计
写该实验的逻辑设计,包括:顶层系统框图,下层各主要元件的系统框图。顶层和下层各主要元件的端口(引脚)描述:端口名称、功能、有效电平、位数等。逻辑图,必须在图中清楚地标出每个内部连接线的Signal(与VHDL程序中的Signal一致)。根据所用的描述方式,可能还需要有:真值表/功能表/逻辑函数等。
1、3-8译码器:
系统框图:
S是工作信号,当S=1时,3-8译码器工作;当S=0时,3-8译码器不工作。A是输入信号,Y是输出信号
S A2 A1 A0 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
1 0 0 0 0 0 0 0 0 0 0 1 加法
1 0 0 1 0 0 0 0 0 0 1 0 与
1 0 1 0 0 0 0 0 0 1 0 0 或
1 0 1 1 0 0 0 0 1 0 0 0 左移
1 1 0 0 0 0 0 1 0 0 0 0 右移
1 1 0 1 0 0 1 0 0 0 0 0 数据传送
1 1 1 0 0 1 0 0 0 0 0 0 取数
1 1 1 1 1 0 0 0 0 0 0 0 无条件转移
0 × × × 0 0 0 0 0 0 0 0
Y(0)<=S and (not A(2)) and (not A(1)) and (not A(0));
Y(1)<=S and (not A(2)) and (not A(1)) and A(0);
Y(2)<=S and (not A(2)) and A(1) and (not A(0));
Y(3)<=S and (not A(2)) and A(1) and A(0);
Y(4)<=S and A(2) and (not A(1)) and (not A(0));
Y(5)<=S and A(2) and (not A(1)) and A(0);
Y(6)<=S and A(2) and A(1) and (not A(0));
Y(7)<=S and A(2) and A(1) and A(0);
2、控制单元:
设计过程:把每条指令的实现分成取指令、分析指令、执行指令三个步骤,每一步由一个机器周期实现,一条指令的实现需要三个机器周期,即M1(取指周期)、M2(分析周期)、M3(执行周期);每个机器周期由三个节拍组成,即T0、T1、T2。如下图所示:
1、加法指令:寄存器R1中的一个数与寄存器R0中的一个数相加,结果放在R1中。
即实现(R0)+(R1)→R1
2、与指令:寄存器R1中的一个数与寄存器R0中的一个数,结果放在R1中。
即实现(R1)and (R0) → R1
3、或指令:寄存器R1中的一个数或寄存器R0中的一个数,结果放在R1中。
即实现(R1)or (R0) → R1
4、逻辑左移指令:寄存器R1中的数左移,移动位数存放在寄存器R0中,结果放在R1中。
即实现(R1)R1
5、逻辑右移指令:寄存器R1中的数左移,移动位数存放在寄存器R0中,结果放在R1中。
即实现(R1)R1
6、数据传送指令:寄存器R0中的数据送到寄存器R1中。即实现(R0)→ R1。
7、取数指令:取出存储器中的一个数(地址在寄存器R0中)送到寄存器R1中。即实现
((R0))→(R1)
8、无条件转移指令:寄存器R1中的地址送到PC中。即实现(R1)→ PC
指令的微操作如下表所示,以教材P122的CPU控制图(省去了M/、ADS)为例:
由于每条指令取指周期的微操作是一样的,所以可以先设计取指周期微操作的节拍安排。
取指周期:T0:PC→AB,W/=0
T1:DB→IR
T2:PC+1
| T0 | T1 | T2 | ||
加法 | M1 | rs1→GR (rs1) → ALU | rd →GR (rd) →ALU | |
| M2 | + | ALU →GR | ||
与 | M1 | rs1→GR (rs1) → ALU | rd →GR (rd) →ALU | |
| M2 | ∧ | ALU →GR | ||
或 | M1 | rs1→GR (rs1) → ALU | rd →GR (rd) →ALU | |
| M2 | ∨ | ALU →GR | ||
左移 | M1 | rs1→GR (rs1) → ALU | rd →GR (rd) →ALU | |
| M2 | ← | ALU →GR | ||
右移 | M1 | rs1→GR (rs1) → ALU | rd →GR (rd) →ALU | |
| M2 | → | ALU →GR | ||
数据传送 | M1 | rs1→GR (rs1) → ALU | ||
| M2 | + | ALU →GR | ||
| 取数 | M1 | rs1→GR (rs1) → ALU + | ALU→AR,AR→AB W/=0 | DB→DR |
| M2 | DR→ALU | + | ALU →GR | |
无条件转移 | M1 | rs1 →GR (rs1) →ALU | ||
| M2 | + | ALU→PC | ||
工作
| 周期 | 节拍 | 微操作命令 | 加法 | 与 | 或 | 左移 | 右移 | 数据 传送 | 取数 | 无条件转移 |
| ADD | AND | OR | SAL | SAR | MOV | LDA | JMP | |||
| 取指周期 | T0 | PC→AB | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| W/=0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | ||
| T1 | DB→IR | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
| T2 | PC+1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
| 分析周期 | T0 | rs1→GR | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| (rs1)→ALU | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | ||
| + | 1 | |||||||||
T1 | ALU→AR | 1 | ||||||||
| AR→AB | 1 | |||||||||
| W/=0 | 1 | |||||||||
T2 | rd→GR | 1 | 1 | 1 | 1 | 1 | ||||
| (rd)→ALU | 1 | 1 | 1 | 1 | 1 | |||||
| DB→DR | 1 | |||||||||
| 执行周期 | T0 | DR→ALU | 1 | |||||||
T1 | + | 1 | 1 | 1 | 1 | |||||
| ∧ | 1 | |||||||||
| ∨ | 1 | |||||||||
| ← | 1 | |||||||||
| → | 1 | |||||||||
T2 | ALU→GR | 1 | 1 | 1 | 1 | 1 | 1 | 1 | ||
| ALU →PC | 1 |
PC→AB = M0·T0
W/=0 = M0·T0+M1·T1·取数
DB→IR = M0·T1
PC+1 = M0 ·T2
rs1→GR = M1 ·T0
(rs1)→ALU = M1 ·T0
+ = M1 ·T0·取数 +M2·T1·(加+传送+取数+转移)
ALU→AR =M1 ·T1 ·取数
AR→AB =M1·T1 ·取数
rd→GR =M1 ·T2·(加法+与+或+左移+右移)
(rd)→ALU = M1 ·T2·(加法+与+或+左移+右移)
DB→DR = M1 ·T2·取数
DR→ALU = M2 ·T0·取数
∧ = M2·T1·与
∨ = M2·T1·或
← = M2·T1·左移
→ = M2·T1·右移
ALU→GR = M2·T2·(加法+与+或+左移+右移+数据传送+取数)
ALU →PC = M2·T2·转移
3、层次结构控制单元:
逻辑图:
三、VHDL程序
--3-8译码器
library ieee;
use ieee.std_logic_11.all;
entity decoder38 is
port( S:in std_logic;
A:in std_logic_vector(2 downto 0);
Y:out std_logic_vector(7 downto 0));
end decoder38;
architecture behave of decoder38 is
begin
process(S)
begin
if S='1' then
Y(0)<=(not A(2)) and (not A(1)) and (not A(0));
Y(1)<=(not A(2)) and (not A(1)) and A(0);
Y(2)<=(not A(2)) and A(1) and (not A(0));
Y(3)<=(not A(2)) and A(1) and A(0);
Y(4)<=A(2) and (not A(1)) and (not A(0));
Y(5)<=A(2) and (not A(1)) and A(0);
Y(6)<=A(2) and A(1) and (not A(0));
Y(7)<=A(2) and A(1) and A(0);
else Y<="00000000";
end if;
end process;
end behave;
--控制单元
--3-8译码器
library ieee;
use ieee.std_logic_11.all;
entity CU is
port( m:in std_logic_vector(2 downto 0);
t:in std_logic_vector(2 downto 0);
d:in std_logic_vector(7 downto 0);
q:out std_logic_vector(18 downto 0));
end CU;
architecture behave of CU is
signal iq:std_logic_vector(7 downto 0);
begin
iq(0)<=not d(7) and not d(6) and not d(5) and not d(4) and not d(3) and not d(2) and not d(1) and d(0);
iq(1)<=not d(7) and not d(6) and not d(5) and not d(4) and not d(3) and not d(2) and d(1) and not d(0);
iq(2)<=not d(7) and not d(6) and not d(5) and not d(4) and not d(3) and d(2) and not d(1) and not d(0);
iq(3)<=not d(7) and not d(6) and not d(5) and not d(4) and d(3) and not d(2) and not d(1) and not d(0);
iq(4)<=not d(7) and not d(6) and not d(5) and d(4) and not d(3) and not d(2) and not d(1) and not d(0);
iq(5)<=not d(7) and not d(6) and d(5) and not d(4) and not d(3) and not d(2) and not d(1) and not d(0);
iq(6)<=not d(7) and d(6) and not d(5) and not d(4) and not d(3) and not d(2) and not d(1) and not d(0);
iq(7)<=d(7) and not d(6) and not d(5) and not d(4) and not d(3) and not d(2) and not d(1) and not d(0);
q(0)<=not m(2) and not m(1) and m(0) and not t(2) and not t(1) and t(0);
q(1)<=(not m(2) and not m(1) and m(0) and not t(2) and not t(1) and t(0))
or (not m(2) and m(1) and not m(0) and not t(2) and t(1) and not t(0) and iq(6));
q(2)<=not m(2) and not m(1) and m(0) and not t(2) and t(1) and not t(0);
q(3)<=not m(2) and not m(1) and m(0) and t(2) and not t(1) and not t(0);
q(4)<=not m(2) and m(1) and not m(0) and not t(2) and not t(1) and t(0);
q(5)<=not m(2) and m(1) and not m(0) and not t(2) and not t(1) and t(0);
q(6)<=(not m(2) and m(1) and not m(0) and not t(2) and not t(1) and t(0) and iq(6)) or
(m(2) and not m(1) and not m(0) and not t(2) and t(1) and not t(0) and (iq(0) or iq(5) or iq(6) or iq(7)));
q(7)<=not m(2) and m(1) and not m(0) and not t(2) and t(1) and not t(0) and iq(6);
q(8)<=not m(2) and m(1) and not m(0) and not t(2) and t(1) and not t(0) and iq(6);
q(9)<=not m(2) and m(1) and not m(0) and t(2) and not t(1) and not t(0) and
(iq(0) or iq(1) or iq(2) or iq(3) or iq(4));
q(10)<=not m(2) and m(1) and not m(0) and t(2) and not t(1) and not t(0) and
(iq(0) or iq(1) or iq(2) or iq(3) or iq(4));
q(11)<=not m(2) and m(1) and not m(0) and t(2) and not t(1) and not t(0) and iq(6);
q(12)<=m(2) and not m(1) and not m(0) and not t(2) and not t(1) and t(0) and iq(6);
q(13)<=m(2) and not m(1) and not m(0) and not t(2) and t(1) and not t(0) and iq(1);
q(14)<=m(2) and not m(1) and not m(0) and not t(2) and t(1) and not t(0) and iq(2);
q(15)<=m(2) and not m(1) and not m(0) and not t(2) and t(1) and not t(0) and iq(3);
q(16)<=m(2) and not m(1) and not m(0) and not t(2) and t(1) and not t(0) and iq(4);
q(17)<=m(2) and not m(1) and not m(0) and t(2) and not t(1) and not t(0)
and (iq(0) or iq(1) or iq(2) or iq(3) or iq(4) or iq(5) or iq(6));
q(18)<=m(2) and not m(1) and not m(0) and t(2) and not t(1) and not t(0) and iq(7);
end behave;
--层次结构控制单元
library ieee;
use ieee.std_logic_11.all;
entity HCU is
port( S:in std_logic;
A:in std_logic_vector(2 downto 0);
M:in std_logic_vector(2 downto 0);
T:in std_logic_vector(2 downto 0);
Q:out std_logic_vector(18 downto 0));
end HCU;
architecture struct of HCU is
signal i:std_logic_vector(7 downto 0);
component decoder38
port( S:in std_logic;
A:in std_logic_vector(2 downto 0);
Y:out std_logic_vector(7 downto 0));
end component;
component CU
port( m:in std_logic_vector(2 downto 0);
t:in std_logic_vector(2 downto 0);
d:in std_logic_vector(7 downto 0);
q:out std_logic_vector(18 downto 0));
end component;
begin
G1:decoder38 port map
(S=>S,A=>A,Y=>i);
G2:CU port map
(d=>i,t=>T,m=>M,q=>Q);
end struct;
四、仿真设计
3-8译码器仿真设计:
设计数据,输出3-8译码器的译码后的8种编码。
| S | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
| A | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 | 101 |
| Y | 00000001 | 00000010 | 00000100 | 00001000 | 00010000 | 00100000 | 01000000 | 10000000 | 00000000 |
设计仿真数据使每一个微操作都可以有效输出:
| m | 001 | 001 | 001 | 010 | 100 |
| t | 001 | 010 | 100 | 001 | 010 |
| d | 00010000 | 00100000 | 10000000 | 01000000 | 00000001 |
| q | 0000000000000000011 | 0000000000000000100 | 0000000000000001000 | 0000000000001110000 | 0000000000001000000 |
| m | 010 | 010 | 010 | 100 | 100 |
| t | 010 | 100 | 100 | 001 | 010 |
| d | 01000000 | 00001000 | 01000000 | 01000000 | 00000010 |
| q | 0000000000110000010 | 0000000011000000000 | 0000000100000000000 | 0000001000000000000 | 0000010000000000000 |
| m | 100 | 100 | 100 | 100 | 100 |
| t | 010 | 010 | 010 | 100 | 100 |
| d | 00000100 | 00001000 | 00010000 | 00000010 | 10000000 |
| q | 0000100000000000000 | 0001000000000000000 | 0010000000000000000 | 010********* | 1000000000000000000 |
设计数据依次输出指令的微操作:
例如:若要输出加法指令需要的所有微操作,则需设置数据如下:
| S | 1 | 1 | 1 | 1 |
| A | 000 | 000 | 000 | 000 |
| M | 001 | 001 | 001 | 010 |
| T | 001 | 010 | 100 | 001 |
| Q | 0000000000000000011 | 0000000000000000100 | 0000000000000001000 | 0000000000000110000 |
| S | 1 | 1 | 1 |
| A | 000 | 000 | 000 |
| M | 010 | 100 | 100 |
| T | 100 | 010 | 100 |
| Q | 0000000011000000000 | 0000000000001000000 | 010********* |
与:
| S | 1 | 1 | 1 | 1 |
| A | 001 | 001 | 001 | 001 |
| M | 010 | 010 | 100 | 100 |
| T | 001 | 100 | 010 | 100 |
| Q | 0000000000000110000 | 0000000011000000000 | 0000010000000000000 | 010********* |
| S | 1 | 1 | 1 | 1 |
| A | 010 | 010 | 010 | 010 |
| M | 010 | 010 | 100 | 100 |
| T | 001 | 100 | 010 | 100 |
| Q | 0000000000000110000 | 0000000011000000000 | 0000100000000000000 | 010********* |
| S | 1 | 1 | 1 | 1 |
| A | 011 | 011 | 011 | 011 |
| M | 010 | 010 | 100 | 100 |
| T | 001 | 100 | 010 | 100 |
| Q | 0000000000000110000 | 0000000011000000000 | 0001000000000000000 | 010********* |
| S | 1 | 1 | 1 | 1 |
| A | 100 | 100 | 100 | 100 |
| M | 010 | 010 | 100 | 100 |
| T | 001 | 100 | 010 | 100 |
| Q | 0000000000000110000 | 0000000011000000000 | 0010000000000000000 | 010********* |
| S | 1 | 1 | 1 |
| A | 101 | 101 | 101 |
| M | 010 | 100 | 100 |
| T | 001 | 010 | 100 |
| Q | 0000000000000110000 | 0000000000001000000 | 010********* |
| S | 1 | 1 | 1 |
| A | 110 | 110 | 110 |
| M | 010 | 010 | 010 |
| T | 001 | 010 | 100 |
| Q | 0000000000001110000 | 0000000000110000010 | 0000000100000000000 |
| S | 1 | 1 | 1 |
| A | 110 | 110 | 110 |
| M | 100 | 100 | 100 |
| T | 001 | 010 | 100 |
| Q | 0000000100000000000 | 0000000000001000000 | 010********* |
| S | 1 | 1 | 1 |
| A | 111 | 111 | 111 |
| M | 010 | 100 | 100 |
| T | 001 | 010 | 100 |
| Q | 0000000000000110000 | 0000000000001000000 | 1000000000000000000 |
3-8译码器时序仿真:
控制单元时序仿真:
层次控制单元时序仿真:
加法:
与:
或:
左移:
右移:
数据传送:
取数:
无条件转移:
实验仿真结果和设计仿真数据时计算的结果吻合,通过这次实验也让我们更好的了解了微操作的概念了以及指令执行的细节之处。
