MahmoudHassan
Full Member level 6
i need to design adder 8 bit so that if the addition of the two numbers is larger than 255 then the output is 255
if less than 255 then the output is the sum
my design is to take the carry output into multiplexer 's select so that if carry =1 select "11111111" and if carry =0 output is the sum
but simulation is wrong any help
the vhdl code
library ieee;
use ieee.std_logic_1164.all;
entity sai_add is
--generic ( n:natural:=8);
port( a,b:in std_logic_vector (7 downto 0);
cin : in std_logic;
--cout : out std_logic;
z : out std_logic_vector (7 downto 0));
end sai_add;
architecture struct of sai_add is
component adder
generic (n : natural :=8);
port( A,B : in std_logic_vector (n-1 downto 0);
sum : out std_logic_vector (n-1 downto 0);
cin : std_logic;
cout : out std_logic);
end component;
signal temp1:std_logic;
signal temp2,temp3,temp4,temp5 : std_logic_vector (7 downto 0);
begin
L:adder
generic map (n=>8)
port map (A,B,temp2,cin,temp1);
--temp1 <= cout ;
temp5<= temp2 and not(temp1&"1111111");
temp3<="11111111";
temp4<= (temp1 & "1111111") and temp3;
z<= temp4 or temp5;
end struct;
===================================Adder component
library ieee;
use ieee.std_logic_1164.all;
entity adder is
generic (n : natural :=8);
port( A,B : in std_logic_vector (n-1 downto 0);
sum : out std_logic_vector (n-1 downto 0);
cin : std_logic;
cout : out std_logic);
end adder;
architecture struct of adder is
component fulladder
port (A,B,C:in std_logic;sum,carry_outut std_logic);
end component;
signal temp : std_logic_vector ( n downto 0);
begin
cout <= temp;
temp(0) <= cin;
la:for i in n-1 downto 0 generate
fa:fulladder port map (A(i),B(i),temp(i),sum(i),temp(i+1));
end generate;
end struct;
=================== the complete project in the attached files it programed on max Plus in the attached files
if less than 255 then the output is the sum
my design is to take the carry output into multiplexer 's select so that if carry =1 select "11111111" and if carry =0 output is the sum
but simulation is wrong any help
the vhdl code
library ieee;
use ieee.std_logic_1164.all;
entity sai_add is
--generic ( n:natural:=8);
port( a,b:in std_logic_vector (7 downto 0);
cin : in std_logic;
--cout : out std_logic;
z : out std_logic_vector (7 downto 0));
end sai_add;
architecture struct of sai_add is
component adder
generic (n : natural :=8);
port( A,B : in std_logic_vector (n-1 downto 0);
sum : out std_logic_vector (n-1 downto 0);
cin : std_logic;
cout : out std_logic);
end component;
signal temp1:std_logic;
signal temp2,temp3,temp4,temp5 : std_logic_vector (7 downto 0);
begin
L:adder
generic map (n=>8)
port map (A,B,temp2,cin,temp1);
--temp1 <= cout ;
temp5<= temp2 and not(temp1&"1111111");
temp3<="11111111";
temp4<= (temp1 & "1111111") and temp3;
z<= temp4 or temp5;
end struct;
===================================Adder component
library ieee;
use ieee.std_logic_1164.all;
entity adder is
generic (n : natural :=8);
port( A,B : in std_logic_vector (n-1 downto 0);
sum : out std_logic_vector (n-1 downto 0);
cin : std_logic;
cout : out std_logic);
end adder;
architecture struct of adder is
component fulladder
port (A,B,C:in std_logic;sum,carry_outut std_logic);
end component;
signal temp : std_logic_vector ( n downto 0);
begin
cout <= temp;
temp(0) <= cin;
la:for i in n-1 downto 0 generate
fa:fulladder port map (A(i),B(i),temp(i),sum(i),temp(i+1));
end generate;
end struct;
=================== the complete project in the attached files it programed on max Plus in the attached files