VHDL and signed numbers

S

salman sheikh

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
 
A

Alan Fitch

salman sheikh said:
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:
(e-mail address removed)
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.
 
J

John LeVieux

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
 
J

John LeVieux

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top