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

📄 iscas.vhd

📁 含有各类寄存器
💻 VHD
字号:
--	Package File Template
--
--	Purpose: This package defines supplemental types, subtypes, 
--		 constants, and functions 


library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

package ISCAS is

  	type iarray is array(natural range<>) of integer;
	procedure ripple_adder (a,b : in std_logic_vector; Cin: in std_logic; 
  								  sum : inout std_logic_vector; Cout: out std_logic);
	procedure carry_select_adder (groupa: iarray; a,b : in std_logic_vector; Cin: in std_logic; 
  								  sum : inout std_logic_vector; Cout: out std_logic);

end ISCAS;


package body ISCAS is

  function xor3  (a,b,c : in std_logic  ) return std_logic is

  begin
    return (a xor b xor c); 
  end xor3;

  procedure ripple_adder  (a,b : in std_logic_vector; Cin: in std_logic; 
  		sum : inout std_logic_vector; Cout: out std_logic) is
   variable C: std_logic_vector((a'high - a'low +1) downto 0); 
  begin
    C(0) := Cin;
	 For i in 0 to (a'high - a'low) loop
	 	sum(i + sum'low) := xor3(a(i + a'low), C(i), b(i + b'low));
		C(i+1) :=(a(i + a'low)and b(i + b'low)) or (C(i) and (a(i + a'low) or b(i + b'low)));
	 end loop;
	 Cout := C(C'high);
  end ripple_adder;

  procedure carry_select_adder  (groupa: iarray; a,b : in std_logic_vector; Cin: in std_logic; 
  								  sum : inout std_logic_vector; Cout: out std_logic) is
--   variable high_index_K : constant;      								  
   variable low_index, high_index : integer;
	variable temp_sum_a, temp_sum_b : std_logic_vector(sum'range);
	variable carry_select : std_logic_vector(groupa'range);
	variable carry_zero : std_logic_vector(groupa'low to groupa'high -1);
	variable carry_one  : std_logic_vector(groupa'low to groupa'high -1);

  begin
    low_index := 0;
	 For i in (groupa'low) to (groupa'high) loop
	 	high_index := (groupa(i) - 1) + low_index;
--		high_index_K := high_index;
  		if (i = 0) then
		ripple_adder(a(high_index downto low_index), b(high_index downto low_index),
	 					 Cin, sum(high_index downto low_index), carry_select(0));
		else
		ripple_adder(a(high_index downto low_index), b(high_index downto low_index),
	 					 '0', temp_sum_a(high_index downto low_index), carry_zero(i -1));
		ripple_adder(a(high_index downto low_index), b(high_index downto low_index),
	 					 '1', temp_sum_b(high_index downto low_index), carry_one(i -1));
		
		if carry_select(i-1)='0' then
			sum(high_index downto low_index):=temp_sum_a(high_index downto low_index);
		else
			sum(high_index downto low_index):=temp_sum_b(high_index downto low_index);
		end if;
			carry_select(i):=((carry_select(i-1) and carry_one(i-1)) or carry_zero(i-1));
		end if;
			low_index:= high_index + 1;
		end loop;
		Cout:= carry_select(groupa'high);
		end carry_select_adder;

end ISCAS;

⌨️ 快捷键说明

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