Re: Query related to escaped character in verilog

From: Shalom.Bresticker@freescale.com
Date: Wed Feb 09 2005 - 12:10:08 PST

  • Next message: Shalom.Bresticker@freescale.com: "Re: Query related to escaped character in verilog"

    Neil,

    I looked at this more when I got home, and I thought about it more as well.

    What 17.1.1.7 says is that leading "zeroes" are not printed.
    It does not say anything about spaces.

    If you look at parallel language in 17.1.1.3, it says that when printing
    decimal values (i.e., numbers in decimal format),
    "leading zeroes are suppressed and replaced by spaces.
    In other radices, leading zeroes are always displayed."

    "Other radices" means other integral numeric formats.
    Strings are like decimal formats. The leading zeroes are not printed, but
    space is left for them.
    Only when you use a %0s format are the leading spaces omitted.

    The most basic test, which I should have thought of earlier, is

    reg[31:0] r = "" ;

    $display ("%s", r, "cucu");

    This will always give you " cucu" and never "cucu".
    This shows that the zero bytes are printed as spaces.

    But it's also true that the LRM does not say explicitly how \0 should be
    printed and it should.

    A harder question is how should other nonprinting characters be printed?
    (a self-contradiction, of course)

    And 4.2.3.2 explicitly says that leading NULs are not ignored:
    "Padding can affect the results of comparison and concatenation operations".

    Shalom

    On Wed, 9 Feb 2005, Neil Korpusik wrote:

    > The results that Shalom is showing appear to be incorrect. The leading space
    > appears to be inconsistent with what is stated in 17.1.1.7
    >
    > Even though the LRM doesn't explicitly state what character to print when
    > a \0 is embedded within a string, it appears from 17.1.1.7 that the NUL
    > character should not be treated like a string terminator, as shown in one of
    > the outputs shown by Kausik.
    >
    > Printing a blank for an embedded NUL character seems to be the most appropriate
    > thing to do. Ignoring leading NUL characters seems to be the most consistent
    > with the rules for the comparison and concatenation operators (4.2.3.2).
    >
    > 4.2.3.2 String value padding and potential problems
    >
    > "When strings are assigned to variables, the values stored shall be padded
    > on the left with zeros."
    >
    > "The comparison and cancatenation operators shall not distinguish between
    > zeros resulting from padding and the original string characters (\0, ASCII
    > NUL)."
    >
    > 17.1.1.7 String format
    >
    > "No termination character or value is required at the end of a string, and
    > leading zeros are never printed."
    >
    >
    > Neil
    >
    >
    >
    > Shalom Bresticker wrote:
    > > The three simulators I have access to all print " s a", with leading space
    > > before the "s".
    > >
    > > Shalom
    > >
    > >
    > > Kausik Datta wrote:
    > >
    > >
    > >>Hi,
    > >>I have one query related to use of escaped character in verilog.
    > >>
    > >>Let's take the following example:
    > >>
    > >>reg [31:0] a;
    > >>
    > >>initil
    > >>begin
    > >> a = "s\0a";
    > >> #5 $diaplay("%s\n", a);
    > >>end
    > >>
    > >>Some tool print this one as "s a".
    > >>and some tool print as "s"
    > >>
    > >>Which one is the correct output? LRM doesn't say anything about this.
    > >>
    > >>Thanks
    > >>Kausik Datta
    > >>
    > >>
    > >
    > >
    > > --
    > > Shalom Bresticker Shalom.Bresticker @freescale.com
    > > Design & Verification Methodology Tel: +972 9 9522268
    > > Freescale Semiconductor Israel, Ltd. Fax: +972 9 9522890
    > > POB 2208, Herzlia 46120, ISRAEL Cell: +972 50 5441478
    > >
    > > [ ]Freescale Internal Use Only [ ]Freescale Confidential Proprietary
    > >
    > >
    > >
    >
    >

    -- 
    Shalom Bresticker                        Shalom.Bresticker @freescale.com
    Design & Verification Methodology                    Tel: +972 9  9522268
    Freescale Semiconductor Israel, Ltd.                 Fax: +972 9  9522890
    POB 2208, Herzlia 46120, ISRAEL                     Cell: +972 50 5441478
      
    [ ]Freescale Internal Use Only      [ ]Freescale Confidential Proprietary
    


    This archive was generated by hypermail 2.1.4 : Wed Feb 09 2005 - 11:52:05 PST and
    sponsored by Boyd Technology, Inc.