Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

substraction in vhdl

Status
Not open for further replies.

jojo26

Newbie level 5
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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top