SOC课程实验
寄存器RN设计
一、功能分析
1、读寄存器操作
clk_RN 上升沿有效,Ri_EN低电平有效,读信号RDRi高电平有效,选择RS寄存器,输出data[7…0]。
2、写寄存器操作
clk_RN 上升沿有效,Ri_EN低电平有效,写信号WRRi高电平有效,选择RD寄存器,data[7…0]-> RD 。
二、程序代码
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity module_Rn is port(
clk_Rn,nreset,Ri_EN,RDRi,WRRi,RS,RD:in std_logic;
data:in std_logic_vector(7 downto 0);
datao: out std_logic_vector(7 downto 0);
regs,regd: out std_logic_vector(7 downto 0));
end entity module_Rn;
architecture behavior of module_Rn is
signal reg0,reg1:std_logic_vector(7 downto 0);
begin
process(nreset,clk_Rn)
begin
if(nreset='1')then
reg0<="11110000";
reg1<=(others=>'0');
datao<=(others=>'Z');
else
if(clk_Rn'event and clk_Rn='1' and Ri_EN='1')then
if(RDRi='1')then
if(RS='1')then
regs<=reg0;
datao<=reg0;
else
datao<=reg1;
end if;
elsif(WRRi='1')then
if(RD='1')then
reg0<=data;
regd<=data;
else
reg1<=data;
end if;
end if;
end if;
end if;
end process;
end architecture behavior;