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

📄 alu.vhd

📁 一个8位微处理器的VHDL代码以及testbench
💻 VHD
字号:
library ieee;use ieee.std_logic_1164.all; -- each module will need to use std_logicuse ieee.numeric_std.all;use work.alu_const.all;entity alu is	port(  a : in std_logic_vector(7 downto 0);	       b : in std_logic_vector(7 downto 0);	       func : in std_logic_vector(3 downto 0);	       cin  : in std_logic;	       cout : out std_logic;	       zero : out std_logic;	       ov   : out std_logic;	       ALU_out : out std_logic_vector(7 downto 0);	       alu_bits: in std_logic_vector(2 downto 0));end entity alu;architecture alu of alu isbegin    process(a, b, func, cin, alu_bits)	    variable ALU_temp_out: std_logic_vector(8 downto 0);  begin     -- main ALU operationcase func is	-- note the use if signed arithmetic	-- when the operation is logical then a '0'	-- is concatinated such that it does not affect the COUT bit		when ALU_add   => ALU_temp_out := std_logic_vector(unsigned(a(7)&a) + unsigned(b(7)&b));	when ALU_and   => ALU_temp_out := std_logic_vector(unsigned('0' & (a and b)));	when ALU_or    => ALU_temp_out := std_logic_vector(unsigned('0' & (a or b)));	when ALU_com   => ALU_temp_out := std_logic_vector(unsigned('0' & (not a)));	when ALU_xor   => ALU_temp_out := std_logic_vector(unsigned('0' & (a xor b)));	when ALU_sub   => ALU_temp_out := std_logic_vector(unsigned(a(7)&a) - unsigned(b(7)&b));	when ALU_dec   => ALU_temp_out := std_logic_vector(unsigned(b(7)&b) - 1);	when ALU_inc   => ALU_temp_out := std_logic_vector(unsigned(b(7)&b) + 1);	when ALU_pass_a => ALU_temp_out := std_logic_vector(unsigned('0' & a));	when ALU_pass_b => ALU_temp_out := std_logic_vector(unsigned('0' & b));	when ALU_pass_z => ALU_temp_out := "000000000";	when ALU_bit_test => 	   for i in 0 to 7 loop         if (to_integer(unsigned(alu_bits)) = i) then            ALU_temp_out(i) := b(i);         else            ALU_temp_out(i) := '0';         end if;      end loop;      ALU_temp_out(8) := '0';	when others    => ALU_temp_out := "XXXXXXXXX";	end case;			ALU_out <= ALU_temp_out(7 downto 0);			-- carry flag	if func = ALU_sub then		cout <= not ALU_temp_out(8);	else		cout <= ALU_temp_out(8);	end if;			-- overflow flag (not used by PIC)	if func=ALU_add or func=ALU_sub then  if ALU_temp_out(8) /= ALU_temp_out(7) then			ov <= '1';	  else			ov <= '0';	  end if;	else			ov <= '0';	end if;			-- zero flag	if ALU_temp_out(7 downto 0) = "00000000"  then 		zero <= '1'; 	else 		zero <= '0';end if;		  end process;end alu;

⌨️ 快捷键说明

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