Interested In VHDL Training? Click Here

0 votes
in VHDL by (240 points)

How do you do strings in VHDL?

2 Answers

0 votes
by (260 points)

Most often - VHDL strings are used in 2 scenarios :

1. During simulation :

Printing messages to the console and when reading and writing to files while simulating.

2. During synthesis :

Strings are also used to pass easy to read properties when compiling generic code.

Example :

entity some_entity is

generic
(
speed : string ; -- can be "fast" or "slow". ) ;

port
(
clock : std_logic ;
counter : unsigned ( 15 downto 0 ) ;
)

end some_entity ;

architecture rtl_some_entity of some_entity is

begin

generate_slow_counter : if speed = "slow"
generate
counting : process ( clock ) is
begin
if rising_edge ( clock ) then
counter <= counter + 1 ;
end if ;
end process counting ;
end generate ;

generate_fast_counter : if speed = "fast"
generate
counting : process ( clock ) is
begin
if rising_edge ( clock ) then
counter <= counter + 2 ;
end if ;
end process counting ;
end generate ;

end architecture rtl_some_entity ;
0 votes
by (300 points)

A string is an array of Character type elements. The type string is defined in the Standard package. The size of the string array must be specified at the time of declaration and it is important to remember that strings cannot have an index value of '0'. The index must always have a positive value. Strings are used for 'testbench' and cannot be used for synthesis. They are primarily useful for displaying messages during simulation. To explain the syntax, here is an example string declaration:

constant Exstring : String(1 to 25) := "This is an Example string";

The name of the string is Exstring and it is 25 characters long. Notice that the index starts from '1' and not '0'. Double quotation marks are used for strings and single quotation marks for characters. Different operations that can be performed on strings are : "=", "/=", "<", "<=", ">", ">=" and "&". A concatenation operator can be used to concatenate two strings. It is also possible to concatenate two characters or one character and a string.

Want to improve your VHDL skills?

Click Here - Sign Up For VHDL Training

© 2022 by Hardware Coder. User contributions are licensed under cc by-sa 4.0 with attribution required. Attribution means a link to the question, answer, user, etc on this site.

This site is owned and operated by Hardware Coder in McKinney, Texas.

Send Us A Message
About Us

By using this site, you agree to the following:

Privacy Policy
Terms and Conditions
DMCA Policy
Earnings Disclaimer
Legal Disclaimer

...