substraction in vhdl

Status
Not open for further replies.

jojo26

Newbie level 5
Joined
Jan 27, 2017
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
80
hey i'm a newbie ,i want to have a simple substraction between two std logic vectors so i converted them into signed,but when i tested this code it didn't work correctly for example 8 +(-5) gave me (-1021) istead of 3 !!!

PHP:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity sub is 

port (  
    clk         : in    std_logic;
    rst         : in    std_logic;  
    a,b    : in    std_logic_vector (10 downto 0);
    c   : out  std_logic_vector (11 downto 0)  
);
end sub;

architecture beh of sub is
signal p1,p2,p3 :signed (11 downto 0);

begin
  p1 <= signed ('0'& a) ;
  p2 <= signed ('0'& b) ;
    process (clk, rst)
        begin
            if (rst = '1') then
                p3 <= "000000000000";
            elsif (clk'event and clk='1') then  
          
                
                    p3 <= p1 + p2;

            end if;             
    end process;
    c<= std_logic_vector(p3);
end beh;

the compilation is working.
thanks a lot
regards
jojo26
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…