Help with string names; How to concatenate a string + number into a 
Author Message
 Help with string names; How to concatenate a string + number into a

Content-Type: multipart/alternative;
 boundary="------------2CA6821356FEDA66288A7456"

--------------2CA6821356FEDA66288A7456
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Inside a verilog_XL verilog testbench module I want to do the following:

`timescale 1ns/100ps

module strings (HSYNC, DEN);

* * *

// initialize counter D-FF outputs
initial begin
      force u1.cnt.n5 = 1;
      force u1.cnt.n6 = 1;
      force u1.cnt.n7 = 1;
       * * *
      force u1.cnt.n98 = 1;
end

// But instead of entering 100 lines I'd like to use strings
// and a for loop such as:

initial begin
      for (i = 5; i < 99; i = i + 1)  // should i be an integer, reg, or ... ?
      begin
        force u1.cnt.n$i = 1; // $i represents adding the ascii value of i to the
      end                     // hierarchal string name of the net to be forced.

end

// In the for loop I'd like to create the names
// u1.cnt.n5, u1.cnt.n6, u1.cnt.n7 ... using the value
// of the index i

* * *

endmodule
?: How can I do something like this?

?: Are there verilog "C" like functions for string manipulation available?
   ( i.e. strcat() , strcmp(), atoi(), strtod() )

?: How do I concatenate 2 strings; or a string and a number into one string.

?: Are there string variables (details please)?

--

Thank you.

Tom Billheimer

                               _   _
%%|`%%%%%   /\  |\ |  /\  |   / \ / `  Thomas P. Billheimer
%%|  `%%%  /--\ | \| /--\ |__ \_/ \_]  High Speed Converters - Greensboro

%%|  '%%%  | \ |__ \  / | / ` |__ (_`  Phone: (336) 605-4146
%%|'%%%%%  |_/ |__  \/  | \_, |__ ._)  Fax:   (336) 605-4187
########################################################################

--------------2CA6821356FEDA66288A7456
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>

<pre></pre>

<pre>Inside a verilog_XL verilog testbench module I want to do the following:

</pre>

<pre>`timescale 1ns/100ps</pre>

<pre>module strings (HSYNC, DEN);

* * *

// initialize counter D-FF outputs
initial begin
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; force u1.cnt.n5 = 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; force u1.cnt.n6 = 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; force u1.cnt.n7 = 1;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * * *
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; force u1.cnt.n98 = 1;
end

// But instead of entering 100 lines I'd like to use strings
// and a for loop such as:

initial begin
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 5; i &lt; 99; i = i + 1)&nbsp; // should i be an integer, reg, or ... ?
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; force u1.cnt.n$i = 1; // $i represents adding the ascii value of i to the
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // hierarchal string name of the net to be forced.

end

// In the for loop I'd like to create the names
// u1.cnt.n5, u1.cnt.n6, u1.cnt.n7 ... using the value
// of the index i

* * *

endmodule
?: How can I do something like this?

?: Are there verilog "C" like functions for string manipulation available?
&nbsp;&nbsp; ( i.e. strcat() , strcmp(), atoi(), strtod() )

?: How do I concatenate 2 strings; or a string and a number into one string.

?: Are there string variables (details please)?

--&nbsp;

Thank you.

Tom Billheimer

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _&nbsp;&nbsp; _&nbsp;
%%|`%%%%%&nbsp;&nbsp; /\&nbsp; |\ |&nbsp; /\&nbsp; |&nbsp;&nbsp; / \ / `&nbsp; Thomas P. Billheimer
%%|&nbsp; `%%%&nbsp; /--\ | \| /--\ |__ \_/ \_]&nbsp; High Speed Converters - Greensboro

%%|&nbsp; '%%%&nbsp; | \ |__ \&nbsp; / | / ` |__ (_`&nbsp; Phone: (336) 605-4146
%%|'%%%%%&nbsp; |_/ |__&nbsp; \/&nbsp; | \_, |__ ._)&nbsp; Fax:&nbsp;&nbsp; (336) 605-4187
########################################################################</pre>
&nbsp;</html>

--------------2CA6821356FEDA66288A7456--



Tue, 29 May 2001 03:00:00 GMT  
 Help with string names; How to concatenate a string + number into a
<snip snip>

Quote:
> ?: How can I do something like this?

  I don't know, as well. It might be useful to know the method.
  Maybe PLI?

Quote:
> ?: Are there verilog "C" like functions for string manipulation available?
>    ( i.e. strcat() , strcmp(), atoi(), strtod() )

  This is what I do in my testbench codes:

  reg [20*8:1] string;

  reg [4:0] region;
  reg [2:0] field;

  string = {"field", field, "_region", region};

  The statement above:

  strcat () is equal to {} operator.
  atoi () is equal to just concatenating the number.

  As a character string can be stored in data type reg, you don't need to
  use atoi, atof, strtod functions. Verilog is powerful enough to handle that.

Quote:
> ?: How do I concatenate 2 strings; or a string and a number into one string.

  See above.

Quote:
> ?: Are there string variables (details please)?

  No. Data types of reg of the length of a multiple of 8 can be used as string
  identifier. See above.

  Utku



Fri, 01 Jun 2001 03:00:00 GMT  
 Help with string names; How to concatenate a string + number into a

Quote:
> // initialize counter D-FF outputs
> initial begin
>       force u1.cnt.n5 = 1;
>       force u1.cnt.n6 = 1;
>       force u1.cnt.n7 = 1;
>        * * *
>       force u1.cnt.n98 = 1;
> end

The answer may be a custom PLI function that takes a string argument.

initial begin
    $custom_force("u1.cnt.n","aa10");
end

Then, do it in C like you described.  Verilog has primitive, if any, inherent string handling functions since it lacks even a true string type.

----------------------------
Eric Decker
Intrinsix Corp



Sun, 03 Jun 2001 03:00:00 GMT  
 Help with string names; How to concatenate a string + number into a

Quote:
> ?: How can I do something like this?

  I don't know, either, with the conventional methods. Maybe PLI?

Quote:
> ?: Are there verilog "C" like functions for string manipulation available?
>    ( i.e. strcat() , strcmp(), atoi(), strtod() )

  /* To represent strings, we need to use reg of length of a multiple of 8.
     Because an ASCII character is represented with 8 bits. We reserve 20
     characters in the declaration below, for safe. */

  reg [20*8:1] string;       // the final string

  reg [7:0] region_ASCII;    // intermediate identifier
  reg [7:0] field_ASCII;     // intermediate identifier

  reg [4:0] region;          // variable to be converted into ASCII
  reg [2:0] field;           // variable to be converted into ASCII

  `define `HIGH 1'b1
  `define `LOW  1'b0

  initial
   begin
    region_ASCII [7:0] = {{3{`LOW}}, region [4:0]} + 48;
    field_ASCII [2:0] = {{5{`LOW}}, field [2:0]} + 48;
    string = {"field", field_ASCII, "_region", region_ASCII};
   end

  strcat () in C: {} operator in Verilog.

  strcmp () in C : (if string1 == string2) if clause in Verilog.

  itoa () in C: intermediate manipulations above.

  atoi () in C :

  reg [7:0] character;

  initial
   character = "4";

  assign some_signal [2:0] = character [2:0]; // automatic atoi.

  As you can see, a data type can be assigned from a part select of a string.
  A string is actually a "string" of bits. So, there isn't any atoi concept
  necessary in Verilog. This mechanism is the same as:

  char *c;
  *c = "4";

  printf ("%d", c);    // although c is a type of char

  or

  char c = '4';
  printf ("%d", c);

  All are the same.

  strlen () in C:

  I think this can only be done in PLI.

Quote:

> ?: How do I concatenate 2 strings; or a string and a number into one string.

  See above.

Quote:
> ?: Are there string variables (details please)?

  No. Data types of reg of the length of a multiple of 8 can be used as string
  identifier. See above.

  A few weeks ago I posted about the same question. Michael McNamara sent
  me the Verilog source below (thank you again, Michael!):

  "How about the following.  Without using the PLI, the function
  num_2_str returns the hexidecimal representation of it's argument as a
  verilog string.  Extend it for your purposes; as coded handles numbers
  up to 32 bits wide, and returns the number using the characters
  0123456789abcdef.  The function has intimate knowledge of the ASCII
  codes for these numbers and letters; but then Verilog doesn't support
  any other character set anyway."

     function [8*8:1] num_2_str;
      input [31:0] num;
      reg [31:0] i, shft;
      reg [3:0] byte;
      reg [7:0] bite;
      begin
         num_2_str = 0;
         for (i = 0; i < 8; i = i + 1) begin
            shft = i*4;
            byte = num>>shft;
            if (byte < 10)
              bite = 8'h30 + byte;      // 0x30 is '0'
            else
              bite = 8'h61 + (byte-10); // 0x61 is 'a' Use 0x41 for 'A'
            num_2_str = num_2_str | bite << (shft*2);
         end // for (i = 0; i < 8; i = i + 1)
      end
   endfunction // num_2_str

I don't know your application but strings I generated in this way without PLI
are used to open binary testvector files with parametric names. These files
are then passed into a script (mostly Perl or C) which manipulates them.

Utku.



Sun, 03 Jun 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. concatenating strings and numbers

2. BUG: Scientific Number to String/String to Number

3. number to string .... string to number

4. VPREXX Help? Adding number to string number

5. number's to string -) tcp-ip -) scan from string problem

6. Using scan from string to convert a string into a number

7. Ada String Issue: String within Strings

8. string = string(i:j) // string(k:n)

9. Concatenating strings..simple question.

10. Concatenate String in method

11. how to concatenate strings

12. DOS awk concatenate escaped strings ....

 

 
Powered by phpBB® Forum Software