-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCUnit.vhdl
More file actions
executable file
·101 lines (100 loc) · 3.38 KB
/
CUnit.vhdl
File metadata and controls
executable file
·101 lines (100 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
-------------------------------------------------------
--! @file CUnit.vhdl
--! @author Kunal Singhal and Swapnil Palash
--! @brief This file for the implementation of a Control Unit for the processor
-------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
--!This is the unit that generates the control signals.
entity CUnit is
port(
--! The 32-bit instruction coming from the Instruction fetch Unit.
Instruction: in std_logic_vector(31 downto 0);
--! boolean which states whether the instruction is 'mov'
isMov: out boolean;
--! boolean which states whether the instruction is 'st'
isSt: out boolean;
--! boolean which states whether the instruction is 'ld'
isLd: out boolean;
--! boolean which states whether the instruction is 'beq'
isBeq: out boolean;
--! boolean which states whether the instruction is 'bgt'
isBgt: out boolean;
--! boolean which the instruction has an immediate as the arguments.
isImmediate: out boolean;
--! boolean whether something has to be written into the register file.
isWb: out boolean;
--! boolean whether the statement is a direct branching one(b, ret, call)
isUBranch: out boolean;
--! boolean which states whether the instruction is 'ret'
isRet: out boolean;
--! boolean which states whether the instruction is 'call'
isCall: out boolean;
--! This vector stores all the states with each 3-bit value corresponding to one of the instructions.
aluS: out std_logic_vector(2 downto 0));
end entity CUnit;
--! CU is the architectural description of the Control Unit
architecture CU of CUnit is
--! A vector containing 5 bits of the instruction marking the instruction type.
signal op_code: std_logic_vector(4 downto 0);
--! The immediate bit
signal I: std_logic;
begin
--! Extracting the opcode from the 32-bit instruction.
op_code<=Instruction(31 downto 27);
--! Extracting the immediate bit from the 32-bit instruction.
I<= Instruction(26);
--! This part is executed whenever there is a change in op_code or I,ie, the type or argument changes.
process (op_code, I)
--! Comparing the op_code to the predefined values, storing it in aluS and generating the control signals is done via if-else.
begin
isMov<=false; isSt<=false; isLd<=false; isBeq<=false; isBgt<=false; isImmediate<=false; isWb<=false; isUBranch<=false;isRet<=false;isCall<=false;
aluS<="111";
if(I='1') then
isImmediate<=true;
else null;
end if;
if(op_code="00000") then --add
aluS<="000";
isWb<=true;
elsif(op_code="00001") then --sub
aluS<="001";
isWb<=true;
elsif(op_code="00101") then --cmp
aluS<="100";
elsif(op_code="00110") then --and
aluS<="010";
isWb<=true;
elsif(op_code="00111") then --or
aluS<="011";
isWb<=true;
elsif(op_code="01000") then --not
aluS<="101";
isWb<=true;
elsif(op_code="01010") then --lsl
aluS<="110";
isWb<=true;
elsif(op_code="01001") then --mov
isMov<=true;
isWb<=true;
elsif(op_code="01110") then --ld
isLd<=true;
isWb<=true;
aluS<="000";
elsif(op_code="01111") then --st
isSt<=true;
aluS<="000";
elsif(op_code="10000") then --beq
isBeq<=true;
elsif(op_code="10001") then --bgt
isBgt<=true;
elsif(op_code="10010") then --b
isUBranch<=true;
elsif(op_code="10011") then --call
isCall<=true;isUBranch<=true;
elsif(op_code="10100") then --ret
isRet<=true;isUBranch<=true;
else null;
end if;
end process;
end CU;