數位電路之CPU設計一

banxia_hnu_zjw發表於2020-10-27

@3-8譯碼器與指令譯碼器

3-8譯碼器與指令譯碼器

1、實驗方法

採用基於FPGA進行數字邏輯電路設計的方法。
採用的軟體工具是Quartus II。

2、實驗步驟

1、新建,編寫原始碼。
(1).選擇儲存項和晶片型別:【File】-【new project wizard】-【next】(設定檔案路徑+設定project name為xor2)-【next】(設定檔名xor2.vhd—在【add】)-【properties】(type=AHDL)-【next】(family=FLEX10K;name=EPF10K10TI144-4)-【next】-【finish】
(2).新建:【file】-【new】(第二個AHDL File)-【OK】
2、寫好原始碼,儲存檔案(xor2.vhd)。
3、編譯與除錯。確定原始碼檔案為當前工程檔案,點選【processing】-【start compilation】進行檔案編譯,編譯成功。
4、波形模擬及驗證。新建一個vector waveform file。按照程式所述插入a,b,c三個節點(a、b為輸入節點,c為輸出節點)。(操作為:右擊 -【insert】-【insert node or bus】-【node finder】(pins=all;【list】)-【>>】-【ok】-【ok】)。任意設定a,b的輸入波形…點選儲存按鈕儲存。(操作為:點選name(如:A))-右擊-【value】-【clock】(如設定period=200;offset=0),同理設定name B(如120,,60),儲存)。然後【start simulation】,出name C的輸出圖。
5、時序模擬或功能模擬。
6、檢視RTL Viewer:【Tools】-【netlist viewer】-【RTL viewer】。

3-8譯碼器

在這裡插入圖片描述
在這裡插入圖片描述

library lcdf_vhdl,ieee;
use ieee.std_logic_1164.all,lcdf_vhdl.func_prims.all;

entity zjw2018 is
port (A:in std_logic_vector(0 to 2);
      D:out std_logic_vector(0 to 7));
end zjw2018;

architecture structural of zjw2018 is

signal A0_n,A1_n,A2_n,and00_out,and01_out,and02_out,and03_out,and10_out,and11_out,
and12_out,and13_out,and14_out,and15_out,and16_out,and17_out:std_logic;

begin
inv_0:not1 port map(in1 => A(0),out1 => A0_n);
inv_1:not1 port map(A(1),A1_n);
inv_2:not1 port map(A(2),A2_n);

and_00:and_2 port map(A0_n,A1_n,and00_out);
and_01:and_2 port map(A(0),A1_n,and01_out);
and_02:and_2 port map(A0_n,A(1),and02_out);
and_03:and_2 port map(A(0),A(1),and03_out);

and_10:and_2 port map(and10_out,A2_n,D(0));
and_11:and_2 port map(and11_out,A2_n,D(1));
and_12:and_2 port map(and12_out,A2_n,D(2));
and_13:and_2 port map(and13_out,A2_n,D(3));
and_14:and_2 port map(and10_out,A(2),D(4));
and_15:and_2 port map(and11_out,A(2),D(5));
and_16:and_2 port map(and12_out,A(2),D(6));
and_17:and_2 port map(and13_out,A(2),D(7));

end structural;

指令譯碼器

在這裡插入圖片描述
在這裡插入圖片描述

library ieee;
use ieee.std_logic_1164.all;
entity zjw is
	port(EN:in std_logic;
	IR: in std_logic_vector(7 downto 0);
	order: out std_logic_vector(3 downto 0);
	RA,RB: out std_logic_vector(1 downto 0);
	MOVA,MOVB,MOVC,ADD,SUB,AND0,NOT0,SHR,SHL,JMP,JZ,JC,IN0,OUT0,NOP,HEAL: out std_logic);
end zjw;

architecture dec of zjw is
signal instruct: std_logic_vector(3 downto 0);
signal R1, R2: std_logic_vector(1 downto 0);
begin
	order <= instruct;
	RA <= R2;
	RB <= R1;
	instruct <= IR(7 downto 4);
	R1 <= IR(3 downto 2);
	R2 <= IR(1 downto 0);
	MOVA <= '1' when instruct & EN = "00111" and (R1 /= "11" and R2 /= "11") else '0';
	MOVB <= '1' when instruct & R1 & EN = "1111111" else '0';
	MOVC <= '1' when instruct & R2 & EN = "1111111" else '0';
	ADD <= '1' when instruct & EN = "10011" else '0';
	SUB <= '1' when instruct & EN = "01101" else '0';
	AND0 <= '1' when instruct & EN = "11101" else '0';
	NOT0 <= '1' when instruct & EN = "01011" else '0';
	SHR <= '1' when instruct & EN & R2= "1010100" else '0';
	SHL <= '1' when instruct & EN & R2= "1010111" else '0';
	JMP <= '1' when IR & EN = "000100001" else '0';
	JZ <= '1' when IR & EN = "000100011" else '0';
	JC <= '1' when IR & EN = "000100101" else '0';
	IN0 <= '1' when instruct & EN = "00101" else '0';
	OUT0 <= '1' when instruct & EN = "01001" else '0';
	NOP <= '1' when instruct & EN = "01111" else '0';
	HEAL <= '1' when instruct & EN = "10001" else '0';
end dec;

指令集

在這裡插入圖片描述

相關文章