5

Using numeric_std and vhdl93, I cant seems to figure out how to add a std_logic signal to a std_logic_vector.

library ieee;
use ieee.numeric_std.all;

signal in_a, out1: std_logic_vector(3 downto 0);
signal s1 : std_logic;

out1 <= std_logic_vector(signed(in_a) + s1);
1
  • 4
    Unless you are required to use std_logic_vector, it is much preferable to use signed or unsigned directly, especially for signals, but also for ports. This avoids the need for casts everywhere, and helps document what signals are used for. Positive numeric values (counters, addresses): unsigned. Positive or negative numeric values (data): signed. Non-numeric data (control signals, aggregates): std_logic(_vector). Commented Sep 9, 2013 at 11:16

1 Answer 1

6
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity add_std_logic is
end entity;

architecture foo of add_std_logic is
   signal in_a, out1: std_logic_vector(3 downto 0);
   signal s1 : std_logic;
   signal s1v:  std_logic_vector(0 to 0);
begin

    s1v <= (others => s1);

    out1 <= std_logic_vector(signed(in_a) + signed(s1v));

end architecture;

architecture fum of add_std_logic is
   signal in_a, out1: std_logic_vector(3 downto 0);
   signal s1 : std_logic;
   subtype s1v is  std_logic_vector(0 to 0);
begin

    out1 <= std_logic_vector(signed(in_a) + ( s1 & ""));

end architecture;

And of course you could move in_a, s1 and out1 to the port.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks: I see the trick is to create a vector of length 1: ( s1 & "")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.