how to show a number in output text?

A

Amit

Guest
Hello group,

I'm learning to write a testbench so in part of the code I increment
a variable to count number of errors during simulation.

now, I need to know how I can print out a message showing number of
detected errors as following:

Found n error(s).

where n is the value in the counter variable.

Any help is appreciated.

p.s. I thought using & to concatenate would work but no

report "Found " & err_cnt & " error(s)" !!!! (wrong)
 
On Sun, 30 Nov 2008 02:21:04 -0800 (PST), Amit wrote:

now, I need to know how I can print out a message showing number of
detected errors as following:

Found n error(s).

p.s. I thought using & to concatenate would work but no

report "Found " & err_cnt & " error(s)" !!!! (wrong)
Almost. Wrong because err_cnt is not a string.

If err_cnt is an integer, which I guess it is, try:

report "Found " & integer'image(err_cnt) & " error(s)";

Alternatively:

-- need this package to do file I/O
use std.textio.all;
...
-- a variable to construct your lines of text
variable L: line;
...
-- build up your line of text using write() calls
write(L, string'("Found "));
write(L, err_cnt);
write(L, string'(" error(s)");
-- send the line of text to the console, on
-- automatically-opened file OUTPUT:
writeline(OUTPUT, L);

--
Jonathan Bromley, Consultant

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

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
On Sun, 30 Nov 2008 02:21:04 -0800 (PST), Amit <amit.kohan@gmail.com>
wrote:

Hello group,

I'm learning to write a testbench so in part of the code I increment
a variable to count number of errors during simulation.

p.s. I thought using & to concatenate would work but no

report "Found " & err_cnt & " error(s)" !!!! (wrong)
Concatenation works perfectly ... on strings, but err_cnt isn't a
string.

What you need depends on the type of err_cnt.
If it is integer, simply
report "Found " & integer'image(err_cnt) & " error(s)"
will do.

- Brian
 
On 30 נובמבר, 14:30, Brian Drummond <brian_drumm...@btconnect.com>
wrote:
On Sun, 30 Nov 2008 02:21:04 -0800 (PST), Amit <amit.ko...@gmail.com
wrote:



Hello group,

I'm learning to write a testbench so in part of the code I increment
a variable to count number of errors during simulation.
p.s. I thought using & to concatenate would work but no

report "Found " & err_cnt & " error(s)"   !!!!  (wrong)

Concatenation works perfectly ... on strings, but err_cnt isn't a
string.

What you need depends on the type of err_cnt.
If it is integer, simply
report "Found " & integer'image(err_cnt)  & " error(s)"
will do.

- Brian
Some examples (from an AHB monitor VHDL code) at
h--p://bknpk.no-ip.biz/AHB_MON/ahb_mon_1.html
You may also find this page intresting as well:
http://bknpk.no-ip.biz/I2C/leon_2.html
VHDL component to generate VCD waves to replace GHDL VCD wave dump
option
 
Amit wrote:

Found n error(s).

where n is the value in the counter variable.

Any help is appreciated.

p.s. I thought using & to concatenate would work but no

report "Found " & err_cnt & " error(s)" !!!! (wrong)
Currently what you have to do is (as others have noted):
report "Found " & integer'image(err_cnt) & " error(s)"

IN VHDL-2008 (which some vendors are starting to look at) you can do this:

report "Found " & to_string(err_cnt) & " error(s)"

The "to_string" function is overloaded for EVERY type, so you can use it
on STD_LOGIC_VECTOR, UNSIGNED, Boolean, etc...
 
On Nov 30, 5:44 pm, David Bishop <dbis...@vhdl.org> wrote:
Amit wrote:
Found n error(s).

where n is the value in the counter variable.

Any help is appreciated.

p.s. I thought using & to concatenate would work but no

report "Found " & err_cnt & " error(s)"   !!!!  (wrong)

Currently what you have to do is (as others have noted):
report "Found " & integer'image(err_cnt) & " error(s)"

IN VHDL-2008 (which some vendors are starting to look at) you can do this:

report "Found " & to_string(err_cnt) & " error(s)"

The "to_string" function is overloaded for EVERY type, so you can use it
on STD_LOGIC_VECTOR, UNSIGNED, Boolean, etc...


Thanks to all for your comments and help.

Regards,
Amit
 

Welcome to EDABoard.com

Sponsor

Back
Top