Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

fwrite in verilog....

Status
Not open for further replies.

lakshminarayanan

Newbie level 5
Newbie level 5
Joined
Sep 11, 2006
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,339
verilog fwrite

while using the fwrite in verilog....... as mentioned below....
$fwrite(file,"a=%d @=%d",a,addr);
if the value of a is negative i am getting the data in the file as.........for eg....-1 as 65535 but i need to print it as -1 in the file do any one know other format of writting the data so i colud write negative values as -1 in my file.....
 

aji_vlsi

Advanced Member level 2
Advanced Member level 2
Joined
Sep 10, 2004
Messages
643
Helped
85
Reputation
170
Reaction score
12
Trophy points
1,298
Location
Bangalore, India
Activity points
4,944
fwrite verilog

lakshminarayanan said:
while using the fwrite in verilog....... as mentioned below....
$fwrite(file,"a=%d @=%d",a,addr);
if the value of a is negative i am getting the data in the file as.........for eg....-1 as 65535 but i need to print it as -1 in the file do any one know other format of writting the data so i colud write negative values as -1 in my file.....

Using %d should print -1, for example the following code works fine in VCS:

Code:
module fwrite();

  initial begin : b1
    integer file;
    file = $fopen ("a.txt", "w");
    $fwrite (file, "MIN_1 is %d PLUS_1 is %d ", -1, 1);
   $finish;
  end

endmodule

Output is:

Code:
  MIN_1 is          -1 PLUS_1 is           1

HTH
Ajeetha, CVC
www.noveldv.com[/code]
 

nand_gates

Advanced Member level 3
Advanced Member level 3
Joined
Jul 19, 2004
Messages
899
Helped
175
Reputation
350
Reaction score
53
Trophy points
1,308
Activity points
7,037
$fwrite verilog

Checkout this!

Code:
module test;
   integer file;
   reg signed [15:0] a, addr;
   
initial begin
   a = -1;
   addr = 100;
   file = $fopen("test");
   $fwrite(file,"a=%d @=%d",a,addr); 
end
endmodule // test
 

sree205

Advanced Member level 1
Advanced Member level 1
Joined
Mar 13, 2006
Messages
453
Helped
58
Reputation
116
Reaction score
25
Trophy points
1,298
Activity points
4,420
verilog $fwrite

i think if you have declared the variable 'a' as register data type, there is a possibility that it might not show the negative value since it might be unsigned by default. Plz check the fwrite statement with 'a' declared as an integer and see if the same problem occurs.

Also, please provide a feedback on this.
 

lakshminarayanan

Newbie level 5
Newbie level 5
Joined
Sep 11, 2006
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,339
fwrite in verilog

The problem is fixed by the suggestion given by nand_gates........i am using the modelsim simulator in win xp ................
 

rfub

Newbie level 6
Newbie level 6
Joined
Dec 9, 2009
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,391
When I try the code above and simulate using Isim, the output has only one character, instead of "MIN_1 is -1 PLUS_1 is 1", the output is just M. Anyone could tell me how to solve it? Is it because I did the wrong simulation?
Thanks
 

ivlsi

Advanced Member level 3
Advanced Member level 3
Joined
Feb 17, 2012
Messages
883
Helped
17
Reputation
32
Reaction score
16
Trophy points
1,298
Activity points
6,868
What's the difference between $fwrite and $fdisplay?
 

aruipksni

Full Member level 6
Full Member level 6
Joined
May 23, 2013
Messages
345
Helped
68
Reputation
136
Reaction score
66
Trophy points
1,308
Activity points
3,004
What's the difference between $fwrite and $fdisplay?

just copy paste it from "verilog golden reference guide"

"The only difference between $display and $write, is that $display writes out a
newline character at the end of the text, whereas $write does not."
 

ivlsi

Advanced Member level 3
Advanced Member level 3
Joined
Feb 17, 2012
Messages
883
Helped
17
Reputation
32
Reaction score
16
Trophy points
1,298
Activity points
6,868
Thanks! Short and clear :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top