4 bit adder in ghdl

OP #2845590
Hi,
I am trying to run the below example with error like
adder.vhdl:30:21: no function declarations for operator "+"
ghdl: compilation error

I am not able to recognise this error.
Can you please let me know where I am making mistake?

Also if the problem is with library then I have uncommented it and got 
different error like.

adder.vhdl:6:10: primary unit "std_logic_arith" not found in library 
"ieee"
adder.vhdl:7:10: primary unit "std_logic_unsigned" not found in library 
"ieee"


1
------Adder-------------------------------------------
2

3
library ieee;
4
use ieee.std_logic_1164.all;
5
use ieee.numeric_std.all;
6
--use ieee.std_logic_arith.all;
7
--use ieee.std_logic_unsigned.all;
8

9
-------------------------------------------------------
10

11
entity ADDER IS
12

13
generic( n: natural:=4);
14

15
port (A: in std_logic_vector(n-1 downto 0);
16
      B: in std_logic_vector(n-1 downto 0);
17
      CARRY: out std_logic;
18
      SUM: out std_logic_vector(n-1 downto 0)  
19
  );
20
end ADDER;
21

22
------------------------------------------------------
23
architecture behaviour of ADDER is
24

25
signal result:std_logic_vector(n downto 0);
26
 
27
begin
28

29
  --result <= ('0' & A)+('0' & B);
30
        result <= A + B;
31
  SUM <= result(n-1 downto 0);
32
  CARRY <= result(n);
33
end behaviour;
34

35
---------------------------------------------------------
36
---------TestBench--------------------------------------
37
---------------------------------------------------------
38

39
library ieee;
40
use ieee.std_logic_1164.all;
41
--use ieee.std_logic_unsigned.all;
42
--use ieee.std_logic_arith.all;
43
----------------------------------------------------------
44
entity ADDER_TB is        -- entity declaration
45
end ADDER_TB;
46
---------------------------------------------------------
47
architecture struct of ADDER_TB is 
48

49
component ADDER is
50
    port(  A:  in std_logic_vector(3 downto 0);
51
    B:  in std_logic_vector(3 downto 0);   
52
    CARRY:  out std_logic;          
53
    SUM:  out std_logic_vector(3 downto 0)
54
    );
55
    end component;
56

57
    signal A, B:  std_logic_vector(3 downto 0):="0000";
58
    signal CARRY:  std_logic;
59
    signal SUM:    std_logic_vector(3 downto 0):="0000";
60

61
begin
62

63
  result : ADDER port map(A => A,B => B,CARRY => CARRY,SUM => SUM);
64

65
   process
66
     begin
67
  
68
  --case1
69
  A<="0000";
70
  B<="0000";
71
  wait for 5 ns;
72

73
  ---case2
74
  A<="0000";
75
  B<="0010";
76
  wait for 5 ns;
77

78
  ---case3
79
  A<="0010";
80
  B<="0100";
81
  wait for 5 ns;
82

83
  ----case4
84
  A<="0110";
85
  B<="1001";
86
  wait for 5 ns;
87

88
  ----case5
89
  A<="1101";
90
  B<="0111";
91
  wait;
92
   end process;
93
end struct;

Regards,
Fahim
Moderator (Company: Titel) #2845593
You cannot add two std_logic_vectors with the numeric_std!

You must add two unsigned values (defined in numeric_std) and therefore 
some casts are necessary:
1
signal result: unsigned(n downto 0);
2

3
   result <= unsigned(A) + unsigned(B);
4
   SUM    <= std_logic_vector(result(n-1 downto 0));


BTW:
You could add two vectors with std_logic_unsigned and std_logic_arith, 
but its strongly not recommended to use those old synopsys libs!
OP #2845645
Thanks Miller.

Just one question if I have to use unsigned then it is neccessary to use 
ieee.std_logic_unsigned.all; correct?

But when I am doing so I am getting the below error.

adder.vhdl:6:10: primary unit "std_logic_unsigned" not found in library 
"ieee"

Regards
Fahim
OP #2845661
Thanks Miller.

Just one question if I have to use unsigned then it is neccessary to use
ieee.std_logic_unsigned.all; correct?

But when I am doing so I am getting the below error.

adder.vhdl:6:10: primary unit "std_logic_unsigned" not found in library
"ieee"

Regards
Fahim
OP #2845687
With -fexplicit  it is giving me same error however with --ieee=synopsys 
i am getting error but different one.

adder.vhdl:28:18: no declaration for "unsigned"
ghdl: compilation error

So I remove the unsigned part and run it with --ieee=synopsys and it 
works for me.

Thanks!!!!!!!!!!
Moderator (Company: Titel) #2845706
Fahim Khan wrote:
> Just one question if I have to use unsigned then it is neccessary to use
> ieee.std_logic_unsigned.all; correct?
You should NOT use ieee.std_logic_unsigned.all at all!

The datatypes unsigend and also signed are already defined in 
numeric_std.

Reply

A question of your own? This thread is over 14 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.