VHDL and signed numbers

Discussion in 'VHDL' started by salman sheikh, Dec 17, 2004.

  1. Is there any way I can read in a file of negative and positive integers
    into my VHDL testbench and convert them to hex values? Or does anybody
    have a program to convert them?

    Salman
     
    salman sheikh, Dec 17, 2004
    #1
    1. Advertising

  2. salman sheikh

    Alan Fitch Guest

    "salman sheikh" <> wrote in message
    news:cpvh5j$qo$...
    > Is there any way I can read in a file of negative and positive

    integers
    > into my VHDL testbench and convert them to hex values? Or does

    anybody
    > have a program to convert them?
    >
    > Salman


    You can read in integers using textio, and just reading into
    an integer.

    e.g.

    use STD.TEXTIO.all;

    ....

    process
    variable L : LINE;
    variable I : INTEGER;
    variable OK : BOOLEAN;
    file F : TEXT;
    status : FILE_OPEN_STATUS;
    begin
    file_open(status, F, READ_MODE, "vectors.txt");

    assert status OPEN_OK report "file open failure - Doh!";

    while not ENDFILE(F) loop
    READLINE(F, L);
    assert L'LENGTH!=0 report "that's a short line!";
    READ(L, I, OK);
    assert OK report "file read error - Doh!";
    report "I read the value " & INTEGER'IMAGE(I);

    -- convert to hex here...
    wait for 10 ns; -- or whatever
    end;

    wait;
    end process;

    Unfortunately converting to hex is not that easy.
    Probably the most straightforward way is to write the values
    to a line in the correct format, and then read them back.
    There are procedures HREAD and HWRITE in IEEE.STD_LOGIC_TEXTIO
    which you can use.

    However I would first ask why you want hex and why you are starting
    with integers? Can you actually put hex in the file instead?

    regards
    Alan

    --
    Alan Fitch
    Consultant

    DOULOS - Developing Design Know-how
    VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project
    Services

    Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24
    1AW, UK
    Tel: +44 (0)1425 471223 mail:

    Fax: +44 (0)1425 471573 Web:
    http://www.doulos.com

    The contents of this message may contain personal views which are not
    the
    views of Doulos Ltd., unless specifically stated.
     
    Alan Fitch, Dec 20, 2004
    #2
    1. Advertising

  3. salman sheikh

    John LeVieux Guest

    An Excel spreadsheet can be used to convert integers into hex values.
    Create one cell as an integer (I'll refer to the location as
    "Integer_Cell_ID"). Define the cell next to it using the function
    formula: =DEC2HEX("Integer_Cell_ID",3).

    Note that the "3" in the formula will give a 3 digit hex value
    (000-FFF).

    John

    Alan Fitch wrote:
    > "salman sheikh" <> wrote in message
    > news:cpvh5j$qo$...
    > > Is there any way I can read in a file of negative and positive

    > integers
    > > into my VHDL testbench and convert them to hex values? Or does

    > anybody
    > > have a program to convert them?
    > >
    > > Salman

    >
    > You can read in integers using textio, and just reading into
    > an integer.
    >
    > e.g.
    >
    > use STD.TEXTIO.all;
    >
    > ...
    >
    > process
    > variable L : LINE;
    > variable I : INTEGER;
    > variable OK : BOOLEAN;
    > file F : TEXT;
    > status : FILE_OPEN_STATUS;
    > begin
    > file_open(status, F, READ_MODE, "vectors.txt");
    >
    > assert status OPEN_OK report "file open failure - Doh!";
    >
    > while not ENDFILE(F) loop
    > READLINE(F, L);
    > assert L'LENGTH!=0 report "that's a short line!";
    > READ(L, I, OK);
    > assert OK report "file read error - Doh!";
    > report "I read the value " & INTEGER'IMAGE(I);
    >
    > -- convert to hex here...
    > wait for 10 ns; -- or whatever
    > end;
    >
    > wait;
    > end process;
    >
    > Unfortunately converting to hex is not that easy.
    > Probably the most straightforward way is to write the values
    > to a line in the correct format, and then read them back.
    > There are procedures HREAD and HWRITE in IEEE.STD_LOGIC_TEXTIO
    > which you can use.
    >
    > However I would first ask why you want hex and why you are starting
    > with integers? Can you actually put hex in the file instead?
    >
    > regards
    > Alan
    >
    > --
    > Alan Fitch
    > Consultant
    >
    > DOULOS - Developing Design Know-how
    > VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project
    > Services
    >
    > Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24
    > 1AW, UK
    > Tel: +44 (0)1425 471223 mail:
    >
    > Fax: +44 (0)1425 471573 Web:
    > http://www.doulos.com
    >
    > The contents of this message may contain personal views which are not
    > the
    > views of Doulos Ltd., unless specifically stated.
     
    John LeVieux, Dec 20, 2004
    #3
  4. salman sheikh

    John LeVieux Guest

    An Excel spreadsheet can be used to convert integers into hex values.
    Create one cell as an integer (I'll refer to the location as
    "Integer_Cell_ID"). Define the cell next to it using the function
    formula: =DEC2HEX("Integer_Cell_ID",3).

    Note that the "3" in the formula will give a 3 digit hex value
    (000-FFF).

    John

    Alan Fitch wrote:
    > "salman sheikh" <> wrote in message
    > news:cpvh5j$qo$...
    > > Is there any way I can read in a file of negative and positive

    > integers
    > > into my VHDL testbench and convert them to hex values? Or does

    > anybody
    > > have a program to convert them?
    > >
    > > Salman

    >
    > You can read in integers using textio, and just reading into
    > an integer.
    >
    > e.g.
    >
    > use STD.TEXTIO.all;
    >
    > ...
    >
    > process
    > variable L : LINE;
    > variable I : INTEGER;
    > variable OK : BOOLEAN;
    > file F : TEXT;
    > status : FILE_OPEN_STATUS;
    > begin
    > file_open(status, F, READ_MODE, "vectors.txt");
    >
    > assert status OPEN_OK report "file open failure - Doh!";
    >
    > while not ENDFILE(F) loop
    > READLINE(F, L);
    > assert L'LENGTH!=0 report "that's a short line!";
    > READ(L, I, OK);
    > assert OK report "file read error - Doh!";
    > report "I read the value " & INTEGER'IMAGE(I);
    >
    > -- convert to hex here...
    > wait for 10 ns; -- or whatever
    > end;
    >
    > wait;
    > end process;
    >
    > Unfortunately converting to hex is not that easy.
    > Probably the most straightforward way is to write the values
    > to a line in the correct format, and then read them back.
    > There are procedures HREAD and HWRITE in IEEE.STD_LOGIC_TEXTIO
    > which you can use.
    >
    > However I would first ask why you want hex and why you are starting
    > with integers? Can you actually put hex in the file instead?
    >
    > regards
    > Alan
    >
    > --
    > Alan Fitch
    > Consultant
    >
    > DOULOS - Developing Design Know-how
    > VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project
    > Services
    >
    > Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24
    > 1AW, UK
    > Tel: +44 (0)1425 471223 mail:
    >
    > Fax: +44 (0)1425 471573 Web:
    > http://www.doulos.com
    >
    > The contents of this message may contain personal views which are not
    > the
    > views of Doulos Ltd., unless specifically stated.
     
    John LeVieux, Dec 20, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kingsley Oteng

    Representing signed numbers in VHDL

    Kingsley Oteng, May 4, 2004, in forum: VHDL
    Replies:
    0
    Views:
    752
    Kingsley Oteng
    May 4, 2004
  2. kyrpa83
    Replies:
    1
    Views:
    626
    kyrpa83
    Oct 17, 2007
  3. blackpadme
    Replies:
    4
    Views:
    1,270
    rickman
    Sep 7, 2008
  4. KJ
    Replies:
    0
    Views:
    496
  5. Rob1bureau
    Replies:
    1
    Views:
    813
    joris
    Feb 27, 2010
Loading...

Share This Page