Professional Documents
Culture Documents
The Single Cycle CPU Project
The Single Cycle CPU Project
The Single Cycle CPU Project
register state value). When ld = 1, the register will load the input D to Q; when ld = 0, it keeps its
current Q value. Complete the following VHDL code for the register.
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------entity register32 is
port(
clr: in std_logic;
-- async. clear
clk: in std_logic;
-- clock
ld: in std_logic;
-- load
D: in std_logic_vector(31 downto 0); -- data input
Q: out std_logic_vector(31 downto 0) ); -- data output
end entity register32;
---------------------------------------------------architecture register32_arch of register32 is
begin
-- fill in your code here
end architecture register32_arch;
Use the given waveform file register32.vwf (available on Blackboard) to simulate your register32
design. Submit your code and simulation result in your project report.
Create a new project named pc_update to implement the subcircuit shown in Figure 3 (with the
inputs/outputs shown outside the dotted box).
I_word_4: out
I_word_5: out
I_word_6: out
I_word_7: out
end entity instr_mem;
std_logic_vector(31
std_logic_vector(31
std_logic_vector(31
std_logic_vector(31
downto
downto
downto
downto
0);
0);
0);
0) );
);
end component mem_word;
type RAM is array (integer range <>) of std_logic_vector (31 downto 0);
signal instr_word: RAM (0 to 7); -- eight instruction words
begin
-- instr_word(0) initialized to lw $1, 0($0) ;hex instr code: 8C010000
mem_word_0: mem_word
port map( sel => '1', WE => init, RE => '1',
Din => "10001100000000010000000000000000",
Dout => instr_word(0), Q => I_word_0 );
-- instr_word(1) initialized to lw $2, 4($0) ;hex instr code: 8C020004
mem_word_1: mem_word
port map( sel => '1', WE => init, RE => '1',
Din => "10001100000000100000000000000100",
Dout => instr_word(1), Q => I_word_1 );
-- instr_word(2) initialized to add $3, $1, $2 ;hex instr code: 00221820
mem_word_2: mem_word
port map( sel => '1', WE => init, RE => '1',
Din => "00000000001000100001100000100000",
Dout => instr_word(2), Q => I_word_2 );
-- instr_word(3) initialized to sw $3, 8($0) ;hex instr code: AC030008
mem_word_3: mem_word
port map( sel => '1', WE => init, RE => '1',
Din => "10101100000000110000000000001000",
Dout => instr_word(3), Q => I_word_3 );
-- instr_word(4) initialized to sub $4, $2, $1 ;hex instr code: 00412022
mem_word_4: mem_word
port map( sel => '1', WE => init, RE => '1',
Din => "00000000010000010010000000100010",
Dout => instr_word(4), Q => I_word_4 );
-- instr_word(5) initialized to and $5, $1, $2 ;hex instr code: 00222824
mem_word_5: mem_word
port map( sel => '1', WE => init, RE => '1',
Din => "00000000001000100010100000100100",
Dout => instr_word(5), Q => I_word_5 );
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------entity mem_word is
port(
sel: in std_logic; -- memory word select
WE: in std_logic; -- write enable
RE: in std_logic; -- read enable
Din: in std_logic_vector(31 downto 0); -- input word
Dout: out std_logic_vector(31 downto 0); -- output word
Q: out std_logic_vector(31 downto 0) -- state
-- (for testing purpose)
);
end entity mem_word;
---------------------------------------------------architecture mem_word_arch of mem_word is
signal Din_not, Sin, Rin: std_logic_vector(31 downto 0);
signal Qa, Qb: std_logic_vector(31 downto 0);
begin
Sin(0)
Sin(1)
Sin(2)
Sin(3)
Sin(4)
Sin(5)
Sin(6)
Sin(7)
Sin(8)
Sin(9)
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
and
and
and
and
and
and
and
and
and
and
Din(0)
Din(1)
Din(2)
Din(3)
Din(4)
Din(5)
Din(6)
Din(7)
Din(8)
Din(9)
and
and
and
and
and
and
and
and
and
and
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
Sin(10)
Sin(11)
Sin(12)
Sin(13)
Sin(14)
Sin(15)
Sin(16)
Sin(17)
Sin(18)
Sin(19)
Sin(20)
Sin(21)
Sin(22)
Sin(23)
Sin(24)
Sin(25)
Sin(26)
Sin(27)
Sin(28)
Sin(29)
Sin(30)
Sin(31)
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
<=
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
sel
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
Din(10)
Din(11)
Din(12)
Din(13)
Din(14)
Din(15)
Din(16)
Din(17)
Din(18)
Din(19)
Din(20)
Din(21)
Din(22)
Din(23)
Din(24)
Din(25)
Din(26)
Din(27)
Din(28)
Din(29)
Din(30)
Din(31)
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
WE;
Reg_word_1: out
Reg_word_2: out
Reg_word_3: out
Reg_word_4: out
Reg_word_5: out
Reg_word_6: out
Reg_word_7: out
end entity reg_file;
std_logic_vector(31
std_logic_vector(31
std_logic_vector(31
std_logic_vector(31
std_logic_vector(31
std_logic_vector(31
std_logic_vector(31
downto
downto
downto
downto
downto
downto
downto
0);
0);
0);
0);
0);
0);
0) );
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------entity data_mem is
port( MemRead: in std_logic; -- read enable
MemWrite: in std_logic; -- write enable
Addr: in std_logic_vector(31 downto 0); -- address input
WriteData: in std_logic_vector(31 downto 0); -- data input
ReadData: out std_logic_vector(31 downto 0); -- data output
-- the following signals are for initialization
-- and testing purposes
init: in std_logic; -- initialization control signal
-- the following 8 outputs are only for simulation purpose
-- they are corresponding to the eight data words
-- in data memory
D_word_0: out std_logic_vector(31 downto 0); -- data word in
-- memory location 0
D_word_1: out std_logic_vector(31 downto 0);
D_word_2: out std_logic_vector(31 downto 0);
D_word_3: out std_logic_vector(31 downto 0);
10
D_word_4: out
D_word_5: out
D_word_6: out
D_word_7: out
);
end entity data_mem;
std_logic_vector(31
std_logic_vector(31
std_logic_vector(31
std_logic_vector(31
downto
downto
downto
downto
0);
0);
0);
0)
type RAM is array (integer range <>) of std_logic_vector (31 downto 0);
signal data_word: RAM (0 to 7);
begin
with init select
cond <= (others => '0') when '0',
(others => '1') when others;
with Addr(4 downto 2) select
active_mem <= "10000000" when
"01000000" when
"00100000" when
"00010000" when
"00001000" when
"00000100" when
"00000010" when
"00000001" when
"000",
"001",
"010",
"011",
"100",
"101",
"110",
others;
11
12
Create a new project named alu_control to implement the ALU control unit. The inputs of
alu_control are: a 2-bit control input ALUOp; a 6-bit control input Funct. The output is a 4-bit
ALU control signal ALUCtrl. Use Table 4.12 in text to determine the input, output codes, and
their relationship. Complete the following VHDL code for the ALU control unit. Then use the
given waveform file alu_control.vwf (available on Blackboard) to simulate your alu_control
design. Submit your code and simulation result in your project report.
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------entity alu_control is
port( ALUOp: in std_logic_vector(1 downto 0);
Funct: in std_logic_vector(5 downto 0);
ALUCtrl: out std_logic_vector(3 downto 0));
end entity alu_control;
---------------------------------------------------architecture alu_control_arch of alu_control is
begin
-- fill in your code here
end architecture alu_control_arch;
13
Create a new project named control to implement the control unit. The input of control is a 6-bit
control input Opcode. The outputs are: a 1-bit control output RegDst; a 1-bit control output
ALUSrc; a 1-bit control output MemtoReg; a 1-bit control output RegWrite; a 1-bit control output
MemRead; a 1-bit control output MemWrite; a 2-bit control output ALUOp. Use Table 4.18 in text
to determine the input-output relationship. Complete the following VHDL code for the control
unit. Then use the given waveform file control.vwf (available on Blackboard) to simulate your
control design. Submit your code and simulation result in your project report.
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------entity control is
port(
Opcode:
RegDst:
ALUSrc:
MemtoReg:
RegWrite:
MemRead:
MemWrite:
ALUOp:
end entity control;
14
entity cpu is
port(
clk: in std_logic; -- clock input
MemWriteAllow: in std_logic; -- use this external input bit to and
-- with MemWrite signal to make sure
-- both Addr and WriteData have become
-- stable when write enable is asserted
-- for data memory. This signal is active
-- in the third fourth portion of each cycle.
-- the following signals are only used for
-- testing and simulation purpose
incH_ldL: in std_logic; -- increment PC = PC + 4 when high,
-- load PCInput when low
PCInput: in std_logic_vector (31 downto 0); -- external input for PC
init: in std_logic; -- initialization control signal
_word_0: out std_logic_vector(31 downto 0); -- instr word in
-- instruction memory location 0
I_word_1: out std_logic_vector(31 downto 0);
I_word_2: out std_logic_vector(31 downto 0);
I_word_3: out std_logic_vector(31 downto 0);
I_word_4: out std_logic_vector(31 downto 0);
I_word_5: out std_logic_vector(31 downto 0);
I_word_6: out std_logic_vector(31 downto 0);
I_word_7: out std_logic_vector(31 downto 0);
Reg_word_0: out std_logic_vector(31 downto 0); -- reg word 0
Reg_word_1: out std_logic_vector(31 downto 0);
Reg_word_2: out std_logic_vector(31 downto 0);
Reg_word_3: out std_logic_vector(31 downto 0);
Reg_word_4: out std_logic_vector(31 downto 0);
Reg_word_5: out std_logic_vector(31 downto 0);
Reg_word_6: out std_logic_vector(31 downto 0);
Reg_word_7: out std_logic_vector(31 downto 0);
D_word_0: out std_logic_vector(31 downto 0); -- data word in
-- data memory location 0
D_word_1: out std_logic_vector(31 downto 0);
D_word_2: out std_logic_vector(31 downto 0);
D_word_3: out std_logic_vector(31 downto 0);
D_word_4: out std_logic_vector(31 downto 0);
D_word_5: out std_logic_vector(31 downto 0);
D_word_6: out std_logic_vector(31 downto 0);
D_word_7: out std_logic_vector(31 downto 0) );
end entity cpu;
---------------------------------------------------architecture cpu_arch of cpu is
begin
-- fill in your code here
end architecture cpu_arch;
15
16