CPU设计源代码(VHDL)

一、通用寄存器组部分设计regfile
1 寄存器reg
library ieee;
use ieee.std_logic_1164.all;

entity reg is port
 (reset : in std_logic;
   d_input : in std_logic_vector(15 downto 0);
  clk : in std_logic;
  write : in std_logic;
 sel : in std_logic;
 q_output : out std_logic_vector(15 downto 0)
 );
end reg;

architecture a of reg is 
begin
 process(reset,clk)
 begin
  if reset = '0' then
   q_output <= x"0000";
  elsif clk'event and clk = '0' then
   if sel = '1' and write ='1' then
    q_output <= d_input;
   end if;
  end if;
 end process;
end a;
2 2-4译码器
library ieee;
use ieee.std_logic_1164.all;

entity decoder_2_to_4 is port
 (sel : in std_logic_vector(1 downto 0);
  sel00 : out std_logic;
  sel01 : out std_logic;
  sel02 : out std_logic;
  sel03 : out std_logic
 );
end decoder_2_to_4;

architecture behavioral of decoder_2_to_4 is 
begin
 sel00 <= (not sel(1)) and (not sel(0));
 sel01 <= (not sel(1)) and sel(0);
 sel02 <= sel(1) and (not sel(0));
 sel03 <= sel(1) and sel(0);
end behavioral;
3 4选1选择器
library ieee;
use ieee.std_logic_1164.all;

entity mux_4_to_1 is port
 (input0,input1,input2,input3 : in std_logic_vector(15 downto 0);
  sel : in std_logic_vector(1 downto 0);
  out_put : out in std_logic_vector(15 downto 0)
 );
end mux_4_to_1;

architecture behavioral of mux_4_to_1 is 
begin
mux : process(sel,input0,input1,input2,input3)
begin
 case sel is when "00" => out_put <=input0;
   when "01" => out_put <=input1;
   when "10" => out_put <=input2;
   when "11" => out_put <=input3;
 end case;
end process;
end behavioral;
4 通用寄存器组regfile
library ieee;
use ieee.std_logic_1164.all;

entity regfile is port
 ( DR : in std_logic_vector(1 downto 0);
   SR : in std_logic_vector(1 downto 0);
   reset : in std_logic;
   write : in std_logic;
   clk : in std_logic;
   d_input : in std_logic_vector(15 downto 0);
   change_z : in std_logic;
   change_c : in std_logic;
   c_in : in std_logic;
   z_in : in std_logic;
   output_DR : out std_logic_vector(15 downto 0);
   output_SR : out std_logic_vector(15 downto 0);
   c_out : out std_logic;
   z_out : out std_logic
 );
end regfile;

architecture struct of regfile is 

signal reg00,reg01,reg02,reg03 : std_logic_vector(15 downto 0);
signal sel00,sel01,sel02,sel03 : std_logic;

begin
z_c_proc : process(reset,clk)
begin
 if reset = '0' then
  z_out <= '0';
  c_out <= '0';
 elsif clk'event and clk = '0' then
  if change_z ='1' then
   z_out = z_in;
  end if;
  if change_c = '1' then
   c_out = c_in;
  end if;
 end if;
end process;
Areg00 : reg port map (
  reset => reset,
  d_input => d_input;
  clk => clk;
  write => write;
  sel => sel00;
  q_output => reg00;
  ) ;
Areg01 : reg port map (
  reset => reset,
  d_input => d_input,
  clk => clk,
  write => write,
  sel => sel01,
  q_output => reg01
  ) ;
Areg03 : reg port map (
  reset => reset,
  d_input => d_input,
  clk => clk,
  write => write,
  sel => sel03,
  q_output => reg03
  ) ;
Areg04 : reg port map (
  reset => reset,
  d_input => d_input,
  clk => clk,
  write => write,
  sel => sel04,
  q_output => reg04
  ) ;
des_decoder:decoder_2_to_4 port map(
   sel => DR,
   sel00 =>sel00,
   sel01 => sel01,
   sel02 => sel02,
   sel03 => sel03
   );
muxA : mux_4_to_1 port map(
    input0 => reg00;
    input1 => reg01;
    input2 => reg02;
    input3 => reg03;
    sel => DR;
    out_put => output_DR
    );
muxB : mux_4_to_1 port map(
    input0 => reg00;
    input1 => reg01;
    input2 => reg02;
    input3 => reg03;
    sel => SR;
    out_put => output_SR
    );
end struct;

转载于:https://www.cnblogs.com/mysystem/archive/2013/01/09/2852460.html

  • 0
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值