Design of 4 Bit Adder cum Subtractor using Loops (Behavior Modeling Style) -
Output Waveform : 4 Bit Adder cum Subtractor |
VHDL Code -
-------------------------------------------------------------------------------
--
-- Title : adder_subtractor_4bit
-- Design : vhdl_upload2
-- Author : Naresh Singh Dobal
-- Company : nsdobal@gmail.com
-- VHDL Programs & Exercise with Naresh Singh Dobal.
--
-------------------------------------------------------------------------------
--
-- File : 4 Bit adder cum subtractor using loop.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity adder_subtractor_4bit is
port(
sel : in STD_LOGIC;
a : in STD_LOGIC_VECTOR(3 downto 0);
b : in STD_LOGIC_VECTOR(3 downto 0);
dout : out STD_LOGIC_VECTOR(3 downto 0)
);
end adder_subtractor_4bit;
architecture adder_subtractor_arc of adder_subtractor_4bit is
begin
add_sub : process (a,b,sel) is
variable l : std_logic_vector (3 downto 0) ;
variable s : std_logic_vector (4 downto 0) ;
begin
l := b xor (sel & sel & sel & sel);
s(0) := sel;
for i in 0 to 3 loop
dout(i) <= a(i) xor l(i) xor s(i);
s(i+1) := (a(i) and l(i)) or (l(i) and s(i)) or (s(i) and a(i));
end loop;
end process add_sub;
end adder_subtractor_arc;
No comments:
Post a Comment