FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-17-2007, 04:14 PM
Guest
 
Posts: n/a
Default Strings in Verilog

How can we represent the following line in Verilog?

type STR4_ARRAY is array (2 downto 0) of string(1 to 4);


Actually its a part of a VHDL tb code. It seems that the owner of the
code has used "type" to declare the strings which are basically state
mnemonics. He also displays the string in the waveforms. He is also
doing some encodings from these strings.

Is same kind of operation possible using Verilog? When I try to do
something like

reg [8*4:0] string ; ---> It just gives me the ascii value not the
strings.


Thanks
Trescot

Reply With Quote
  #2 (permalink)  
Old 09-17-2007, 09:35 PM
Kevin Neilson
Guest
 
Posts: n/a
Default Re: Strings in Verilog

[email protected] wrote:
> How can we represent the following line in Verilog?
>
> type STR4_ARRAY is array (2 downto 0) of string(1 to 4);
>
>
> Actually its a part of a VHDL tb code. It seems that the owner of the
> code has used "type" to declare the strings which are basically state
> mnemonics. He also displays the string in the waveforms. He is also
> doing some encodings from these strings.
>
> Is same kind of operation possible using Verilog? When I try to do
> something like
>
> reg [8*4:0] string ; ---> It just gives me the ascii value not the
> strings.
>
>
> Thanks
> Trescot
>

Srings in Verilog are not treated any differently than other types. You
can use a register as a string like this:

reg [32*8-1:0] string = "Hello World"; // 32-char string
initial $display ("The string is %s",string);

You can use this to assign string names to states for display in a
simulator. To display a string name in the Modelsim wave window, set
the radix of the wave to ASCII; otherwise it will just show up as a hex
value. The simulator doesn't know automatically that the value is meant
to be a string.

If your tools support SystemVerilog, I recommend the use of the
enumerated types for state names.
-Kevin
Reply With Quote
  #3 (permalink)  
Old 09-18-2007, 06:37 PM
Guest
 
Posts: n/a
Default Re: Strings in Verilog

On Sep 17, 3:35 pm, Kevin Neilson
<[email protected]> wrote:
> [email protected] wrote:
> > How can we represent the following line in Verilog?

>
> > type STR4_ARRAY is array (2 downto 0) of string(1 to 4);

>
> > Actually its a part of a VHDL tb code. It seems that the owner of the
> > code has used "type" to declare the strings which are basically state
> > mnemonics. He also displays the string in the waveforms. He is also
> > doing some encodings from these strings.

>
> > Is same kind of operation possible using Verilog? When I try to do
> > something like

>
> > reg [8*4:0] string ; ---> It just gives me the ascii value not the
> > strings.

>
> > Thanks
> > Trescot

>
> Srings in Verilog are not treated any differently than other types. You
> can use a register as a string like this:
>
> reg [32*8-1:0] string = "Hello World"; // 32-char string
> initial $display ("The string is %s",string);
>
> You can use this to assign string names to states for display in a
> simulator. To display a string name in the Modelsim wave window, set
> the radix of the wave to ASCII; otherwise it will just show up as a hex
> value. The simulator doesn't know automatically that the value is meant
> to be a string.
>
> If your tools support SystemVerilog, I recommend the use of the
> enumerated types for state names.
> -Kevin



I have a procedure in VHDL which basically converts an integer to
string data and then concatenate it with another string to form an ID
shown as below.

ID = "S"+ Int2str(Din,Dout); // function call where ID is string
data

// Actual Function
procedure Int2str( Din : in integer range 0 to 9;
Dout : out string
) is


type DIGIT_2_CHAR is array(0 to 9) of character;
constant to_char : DIGIT_2_CHAR := ('0','1','2','3','4',
'5','6','7','8','9');
begin
Dout := to_char(Din);
end Int2str


I have no idea how this can be implemented in Verilog as there is no
"type" in Verilog. I tried something like this but it didn't work.

reg [(8*1)-1:0] Din ;

Dout = "Din" ; // it will show Din, but not the actual value
// if I try Dout = Din its giving junk data.

So how can I concatenate string with integer and treat the output as
string.


Thanks


Reply With Quote
  #4 (permalink)  
Old 09-19-2007, 06:54 PM
Kevin Neilson
Guest
 
Posts: n/a
Default Re: Strings in Verilog

[email protected] wrote:
> On Sep 17, 3:35 pm, Kevin Neilson
> <[email protected]> wrote:
>> [email protected] wrote:
>>> How can we represent the following line in Verilog?
>>> type STR4_ARRAY is array (2 downto 0) of string(1 to 4);
>>> Actually its a part of a VHDL tb code. It seems that the owner of the
>>> code has used "type" to declare the strings which are basically state
>>> mnemonics. He also displays the string in the waveforms. He is also
>>> doing some encodings from these strings.
>>> Is same kind of operation possible using Verilog? When I try to do
>>> something like
>>> reg [8*4:0] string ; ---> It just gives me the ascii value not the
>>> strings.
>>> Thanks
>>> Trescot

>> Srings in Verilog are not treated any differently than other types. You
>> can use a register as a string like this:
>>
>> reg [32*8-1:0] string = "Hello World"; // 32-char string
>> initial $display ("The string is %s",string);
>>
>> You can use this to assign string names to states for display in a
>> simulator. To display a string name in the Modelsim wave window, set
>> the radix of the wave to ASCII; otherwise it will just show up as a hex
>> value. The simulator doesn't know automatically that the value is meant
>> to be a string.
>>
>> If your tools support SystemVerilog, I recommend the use of the
>> enumerated types for state names.
>> -Kevin

>
>
> I have a procedure in VHDL which basically converts an integer to
> string data and then concatenate it with another string to form an ID
> shown as below.
>
> ID = "S"+ Int2str(Din,Dout); // function call where ID is string
> data
>
> // Actual Function
> procedure Int2str( Din : in integer range 0 to 9;
> Dout : out string
> ) is
>
>
> type DIGIT_2_CHAR is array(0 to 9) of character;
> constant to_char : DIGIT_2_CHAR := ('0','1','2','3','4',
> '5','6','7','8','9');
> begin
> Dout := to_char(Din);
> end Int2str
>
>
> I have no idea how this can be implemented in Verilog as there is no
> "type" in Verilog. I tried something like this but it didn't work.
>
> reg [(8*1)-1:0] Din ;
>
> Dout = "Din" ; // it will show Din, but not the actual value
> // if I try Dout = Din its giving junk data.
>
> So how can I concatenate string with integer and treat the output as
> string.
>
>
> Thanks
>
>

Here's a way to convert an integer to a string and to concatenate it
with the letter "s":

module strconcat();
reg [8*32-1:0] String;
parameter DIGITS = "9876543210";
integer din;
initial
begin
din = 4;
String = {"S",DIGITS[din*8+:8]};
$display ("The concatenated string is %s",String);
end
endmodule

results:

vsim> run
# The concatenated string is S4

I think "string" is a reserved word in SystemVerilog which is why I
capitalized it. The conversion just uses din as an index into the
80-bit array DIGITS and extracts eight bits to concatenate with "S".
-Kevin
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
strings in verilog rik Verilog 5 11-04-2006 10:28 PM


All times are GMT +1. The time now is 04:44 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved