⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decoder_unit.vhd

📁 CPU代码-VHDL语言
💻 VHD
字号:
-- 指令译码部分decoder_unit
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;


entity decoder_unit is
	port   (IR:			 in std_logic_vector(15 downto 0);
		  	SR: 		 out std_logic_vector(3 downto 0); ----源寄存器号(编址)
			DR: 		 out std_logic_vector(3 downto 0);
			op_code:	 out std_logic_vector(3 downto 0); -- 控制ALU进行16种运算操作的3位编码

		  	zj_instruct: out std_logic;---- "JNZ ADR"指令
		  	cj_instruct: out std_logic;-----   JNC ADR"指令
		  	lj_instruct: out std_logic;-----   JMP ADR"指令
		  	DRWr: 		 buffer std_logic;  --为1时,写DR寄存器
			Mem_Write:   out std_logic;--- 存储器写操作,存储器的地址是源寄存器的内容
		  	DW_intruct:  buffer std_logic;---- 双字指令的标志,以便"pc+2"。
		    change_z:    out std_logic;---- 可能改变z(结果为0)标志
			change_c:    out std_logic;
            sel_memdata: out std_logic;   --为1表示本条指令写入目的寄存器的值来自读存储器
		  	r_sjmp_addr:  out std_logic_vector(15 downto 0) --相对转移地址
		    );
end decoder_unit;

architecture behav of decoder_unit is
begin
SR <= IR(7 downto 4);----赋值(源寄存器的号)
DR <= IR(11 downto 8);---目的
sel_memdata <= IR(15) and IR(14) and (not IR(13)); ---为1表示本条指令写入目的寄存器的值来自读存储器(不是通用R)
change_z <= not IR(15) and IR(1);-- 为1表示本条指令可能改变z(结果为0)标志
change_c <= not IR(15) and IR(2);

DRWr_proc: process(IR)  ---- DRWr的赋值:为1表示在t3的下降沿将本条指令的执行结果写入目的寄存器,

begin
	if IR(15) = '0' then   --算术逻辑指令
	    if IR(0) ='1' then
			DRWr <= '1';  --- DRWr为1时,写DR寄存器
	    else
			DRWr <= '0';    --nop操作
		end if;
	elsif IR(14) = '1' and IR(13) = '0' then   
		DRWr <= '1';  ---存储指令
	else
		DRWr <= '0'; ---转移指令
	end if;
end process;
 
sj_addr_proc:	process(IR)  --条件转移指令的相对转移地址从8位扩展到16位
begin
	if (IR(15)='1' and IR(14)='0' and (IR(13)or IR(12))='1') then
	if IR(7) ='1' then
		r_sjmp_addr <= "11111111" & IR(7 downto 0);
	else
		r_sjmp_addr <= "00000000" & IR(7 downto 0);
	end if;
  end if;
end process;

M_instruct:process(IR)  
begin
	case IR(15 downto 12) is          
		when "1000" | "1100" =>          --jmp addr;mvrd  dr,data   
            Mem_Write <= '0';              ---为1表示本条指令有存储器写操作,为0读
			DW_intruct <= '1';            --- 为1表示本条指令是双字指令
		when "1110" =>                  -- str sr,dr
			Mem_Write <= '1';
			DW_intruct <= '0';
		when others =>
			Mem_Write <= '0';
			DW_intruct <= '0';
	end case;
end process;

ALUOP_CODE_PROC:	process(IR)  
begin
   	if IR(15) = '0' then  ---  IR15 为0 时运算指令
		op_code <= IR(14 downto 12)&IR(3);
	else
		op_code <= "0111"; 
	end if;
end process;


instruct_PROC:	process(IR)   ----判断是那种转移指令,并产生相应信号
begin
   	case IR(15 downto 12) is
		when "1000" => --jmp adr
			zj_instruct <= '0';
			cj_instruct <= '0';
			lj_instruct <= '1';
		when "1001" => --jnc addr
			zj_instruct <= '0';
			cj_instruct <= '1';    --- 为1表示本条指令是条"JNC ADR"指令。
			lj_instruct <= '0';
		when "1010" => --jnz addr
			zj_instruct <= '1';
			cj_instruct <= '0';
			lj_instruct <= '0';
		when others =>
			zj_instruct <= '0';
			cj_instruct <= '0';
			lj_instruct <= '0';
	end case;
end process;

end behav;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -