Forum Discussion
Altera_Forum
Honored Contributor
13 years agoI'm sorry, i missed that! Here is the code for Overflow flag.
I'm extending the in bytes and compare the sign bit of the extendend sum and the old sum.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package OF_DET is
function detect_overflow(Tmp, A, B : in signed(7 downto 0)) return std_logic;
function detect_zero(Tmp : in signed(7 downto 0)) return std_logic;
end;
package body OF_DET is
function detect_overflow(Tmp, A, B : in signed(7 downto 0)) return std_logic is
variable Tmp_xtnd : signed(8 downto 0);
variable A_xtnd : signed(8 downto 0);
variable B_xtnd : signed(8 downto 0);
variable same_sign : std_logic;
variable plus_minus : std_logic;
begin
Tmp_xtnd := (Tmp(7) & Tmp); --resize(Tmp, 9);
A_xtnd := (A(7) & A); --resize(A, 9);
B_xtnd := (B(7) & B); --resize(A, 9);
same_sign := (A(7) xor B(7));
if (same_sign = '0') then
Tmp_xtnd := A_xtnd + B_xtnd;
if (Tmp_xtnd(8) /= Tmp(7) ) then --Tmp_xtnd(7)
return '1';
else
return '0';
end if;
else
return '0';
end if;
end detect_overflow;
function detect_zero(Tmp : in signed(7 downto 0)) return std_logic is
begin
if (Tmp = 0) then
return '1';
else
return '0';
end if;
end detect_zero;
end OF_DET;