How do I handle this sprintf() in verilog-XL?

F

Frank

Guest
What I need is to have "slot0, slot1, slot2", etc in the file name.
In the simulation, k isn't inserted into the string.

for(k = 0; k <= 3; k = k + 1) begin
task_bpsk_b({{"../../cpp/tv/tx_tv_110/bpsk_tx_input_slot"}, {k},
{".dat"}});
end


Thanks in advance.
 
You have a couple of problems with what you are doing. First, the
integer value 1 is not the same thing as the ASCII character "1". The
ASCII character "1" is encoded with the numeric value 49. To convert a
small integer to an ASCII character, you need to add 48, the ASCII
encoding for "0".

Second, assuming that k is an integer, it is 32 bits wide. That means
that if you put the entire value of k in the middle of your string, you
have not just put in the one byte for the character you want. You have
also inserted 3 bytes of zeroes in the middle of your string.
Depending on what gets done with the string, those might or might not
get ignored. If the string gets processed by routines written in C,
those bytes might get treated as string terminators. To be safe, you
should only be inserting 1 byte into the middle of your string.
 
<sharp@cadence.com> wrote in message
news:1125603902.104805.118220@g44g2000cwa.googlegroups.com...
You have a couple of problems with what you are doing. First, the
integer value 1 is not the same thing as the ASCII character "1". The
ASCII character "1" is encoded with the numeric value 49. To convert a
small integer to an ASCII character, you need to add 48, the ASCII
encoding for "0".

Second, assuming that k is an integer, it is 32 bits wide. That means
that if you put the entire value of k in the middle of your string, you
have not just put in the one byte for the character you want. You have
also inserted 3 bytes of zeroes in the middle of your string.
Depending on what gets done with the string, those might or might not
get ignored. If the string gets processed by routines written in C,
those bytes might get treated as string terminators. To be safe, you
should only be inserting 1 byte into the middle of your string.
Thank you sharp.
My code segment is in an Initial statement. Is there any functions in
verilog to insert this
integer parameter into the middle of the string in generic verilof? I am not
using any APIs.

initial begin
for(k = 0; k <= 3; k = k + 1) begin
task_bpsk_b({{"../../cpp/tv/tx_tv_110/bpsk_tx_input_slot"}, {k},
{".dat"}});
end
end

PS:
I was aware of using shell scripts to write multiple task_bpsk_b() into a
file and using
an include statement, but it's not what I want right now.
 
"Frank" <Francis.invalid@hotmail.com> wrote in message
news:4317ab62@news.starhub.net.sg...
sharp@cadence.com> wrote in message
news:1125603902.104805.118220@g44g2000cwa.googlegroups.com...
You have a couple of problems with what you are doing. First, the
integer value 1 is not the same thing as the ASCII character "1". The
ASCII character "1" is encoded with the numeric value 49. To convert a
small integer to an ASCII character, you need to add 48, the ASCII
encoding for "0".
Oh, I got my way thru this method, creating
.../../cpp/tv/tx_tv_110/bpsk_tx_input_slot0.dat
alone is fine, but I met problem when I use substring on the filename.

for(k = 0; k <= 3; k = k + 1) begin
task_bpsk_b({{"../../cpp/tv/tx_tv_110/bpsk_tx_input_slot"}, {k + 48},
{".dat"}});
end
 
Again, you might need to put your k + 48 into a 1-byte-wide variable
before concatenating it into the name, to avoid putting a bunch of zero
bytes into the middle of the name string. Or use k[7:0] + 8'd48.

The ideal way to build this name would be with the Verilog-2001 $swrite
system function, but that is not supported in Verilog-XL.
 
Hi,

For sending 'variable' to one of a set of different files using the
value k as an indicator of which file to go to I do a case like this in
verilog 2001 code:

case (k)
1 : $fdisplay(file_1_fp,"%d",variable);
2 : $fdisplay(file_2_fp,"%d",variable);
....
endcase

and elsewhere in the code, probably at reset time, I make each file
pointer associate with a specific file name that includes the 1, 2, 3,
etc in its filename.

Hope this is what you need.

RAUL
 

Welcome to EDABoard.com

Sponsor

Back
Top