- Joined
- Apr 19, 2009
- Messages
- 3
- Reaction score
- 0
Hello everybody!
I am struggling with this project.
I need to design a Full Adder circuit which has 8-bit 2's complement numbers as input and which is capable of adding them. Also I need to have an overflow flag in order to detect if overflow occurs.
This is my code:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
--entity declaration
entity FA_OF is
port (A, B : in signed(7 downto 0);
Cin : in signed;
sum : out signed(7 downto 0);
Cout : out signed;
overflow_flag : out signed);
end entity FA_OF;
--architecture body
architecture ARCH2 of FA_OF is
begin
process
begin
sum <= (A xor B) xor Cin;
Cout <= ((A and B) or ( (A xor B) and Cin));
--overflow control
--if the most significant bit of A is equal to the MSB of B
--check that they have the same sign as the MSB of Cout has
--otherwise assume that overflag occurs
--and set flag to be HIGH
if (A(7) = B(7)) and (a(7) /= Cout) then
overflow_flag <= '1';
else overflow_flag <= '0';
end if;
wait;
end process;
end ARCH2;
----
here to find out the overflow I am taking the Most significant bit of A and B. If they are equal then compare it to the Carry. If they are not equal then overflow occurs.
I am not sure on with type use, signed, unsigned, etc.. not sure of it at all.
Also how can I get the MSB of a signed number? By saying 7 downto 6 for example I get 2 numbers instead of 1.
Also I think I am not actually considering the Full adder for 8 bit but only for 1 bit. How can I change it to work for 8 - bit? I am actually getting crazy with this..
Can anyone help me?
Thank you
Salvador
I am struggling with this project.
I need to design a Full Adder circuit which has 8-bit 2's complement numbers as input and which is capable of adding them. Also I need to have an overflow flag in order to detect if overflow occurs.
This is my code:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
--entity declaration
entity FA_OF is
port (A, B : in signed(7 downto 0);
Cin : in signed;
sum : out signed(7 downto 0);
Cout : out signed;
overflow_flag : out signed);
end entity FA_OF;
--architecture body
architecture ARCH2 of FA_OF is
begin
process
begin
sum <= (A xor B) xor Cin;
Cout <= ((A and B) or ( (A xor B) and Cin));
--overflow control
--if the most significant bit of A is equal to the MSB of B
--check that they have the same sign as the MSB of Cout has
--otherwise assume that overflag occurs
--and set flag to be HIGH
if (A(7) = B(7)) and (a(7) /= Cout) then
overflow_flag <= '1';
else overflow_flag <= '0';
end if;
wait;
end process;
end ARCH2;
----
here to find out the overflow I am taking the Most significant bit of A and B. If they are equal then compare it to the Carry. If they are not equal then overflow occurs.
I am not sure on with type use, signed, unsigned, etc.. not sure of it at all.
Also how can I get the MSB of a signed number? By saying 7 downto 6 for example I get 2 numbers instead of 1.
Also I think I am not actually considering the Full adder for 8 bit but only for 1 bit. How can I change it to work for 8 - bit? I am actually getting crazy with this..
Can anyone help me?
Thank you
Salvador