📄 addsub_cy.vhd
字号:
-------------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
-----------------------------ENTITY DECLARATION--------------------------------
entity addsub_cy is
generic (DWIDTH : integer := 4);
port (opa_i : in std_logic_vector(DWIDTH-1 downto 0); -- Operand A
opb_i : in std_logic_vector(DWIDTH-1 downto 0); -- Operand B
addsub_i : in std_logic; -- Add or subtract command
cy_i : in std_logic; -- Carry input
cy_o : out std_logic; -- Carry/borrow bit
rslt_o : out std_logic_vector(DWIDTH-1 downto 0)); -- Result
end addsub_cy;
-------------------------------------------------------------------------------
architecture rtl of addsub_cy is
begin
-- purpose: Simple adder/subtractor with carry/borrow
-- type : combinational
-- inputs : opa_i, opb_i, addsub_i
-- outputs: cy_o, rslt_o
p_addsub: process (opa_i, opb_i, addsub_i, cy_i)
variable v_a : unsigned(DWIDTH downto 0);
variable v_b : unsigned(DWIDTH downto 0);
variable v_result : std_logic_vector(DWIDTH+1 downto 0);
begin -- process p_addsub
v_a(DWIDTH downto 1) := unsigned(opa_i);
v_b(DWIDTH downto 1) := unsigned(opb_i);
if addsub_i = '1' then
v_a(0) := '1';
v_b(0) := cy_i;
v_result := conv_unsigned(v_a,DWIDTH+2) + v_b;
else
v_a(0) := '0';
v_b(0) := cy_i;
v_result := conv_unsigned(v_a,DWIDTH+2) - v_b;
end if;
cy_o <= v_result(DWIDTH+1);
rslt_o <= v_result(DWIDTH downto 1);
end process p_addsub;
end rtl;
-------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -