représentation nombre négatif en simulation lors différence
Publié : 08 mars 2007 11:26
salut ,
mon problème est que je veux faire une simple différence entre deux entiers
et lors de la simulation je trouves pas mon résultat (s'il s'agit d'un résultat négatif ) le moins en simulation :
par exemple si je fais 3 - 4 = -1
en simulation je touves comme résultat 1 et non pas -1 comment représenté le moins .
------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity difference is
Port ( clk : in STD_LOGIC;
Y_act : in STD_LOGIC_VECTOR (7 downto 0);
Y_suiv : in STD_LOGIC_VECTOR (7 downto 0);
Y_eps : out STD_LOGIC_VECTOR (7 downto 0));
end difference;
architecture arch_difference of difference is
signal opn,res:STD_LOGIC_VECTOR (7 downto 0);
begin
process(clk)
begin
-- Calcul des Y epsilons
if Y_suiv < Y_act then --- si on va avoir un résultat négatif on va utiliser le complément a 2
opn <= (not Y_act) + 1;--- complément à 1et ajout de 1
res <= Y_suiv + opn;
Y_eps <= not(res - 1);
else
Y_eps <= Y_suiv - Y_act;
end if;
end process;
end arch_difference;
---------------------------------------------------------------------------------------------
et merci bien
mon problème est que je veux faire une simple différence entre deux entiers
et lors de la simulation je trouves pas mon résultat (s'il s'agit d'un résultat négatif ) le moins en simulation :
par exemple si je fais 3 - 4 = -1
en simulation je touves comme résultat 1 et non pas -1 comment représenté le moins .
------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity difference is
Port ( clk : in STD_LOGIC;
Y_act : in STD_LOGIC_VECTOR (7 downto 0);
Y_suiv : in STD_LOGIC_VECTOR (7 downto 0);
Y_eps : out STD_LOGIC_VECTOR (7 downto 0));
end difference;
architecture arch_difference of difference is
signal opn,res:STD_LOGIC_VECTOR (7 downto 0);
begin
process(clk)
begin
-- Calcul des Y epsilons
if Y_suiv < Y_act then --- si on va avoir un résultat négatif on va utiliser le complément a 2
opn <= (not Y_act) + 1;--- complément à 1et ajout de 1
res <= Y_suiv + opn;
Y_eps <= not(res - 1);
else
Y_eps <= Y_suiv - Y_act;
end if;
end process;
end arch_difference;
---------------------------------------------------------------------------------------------
et merci bien