Verilog 如何在文件中写入负整数?

Verilog 如何在文件中写入负整数?,verilog,Verilog,我在Verilog中有一个ALU,我想把ALU的输出写入一个文件。我正在使用以下代码: $fwrite(File,"La salida es: %d",uut.ALUOutput); 我的输出向量大小为32位(有符号)。该操作是正确的,但当ALUOutput为负数时,在文件中,输出将以无符号整数的形式保存 例如,在负数的文件中,我得到了以下不正确的表示: 4294967264 但是,我想得到以下结果: -32 如何在文件中写入负数?使用$signed(,第11.7节“签名表达式”): mo

我在Verilog中有一个ALU,我想把ALU的输出写入一个文件。我正在使用以下代码:

$fwrite(File,"La salida es: %d",uut.ALUOutput);
我的输出向量大小为32位(有符号)。该操作是正确的,但当
ALUOutput
为负数时,在文件中,输出将以无符号整数的形式保存

例如,在负数的文件中,我得到了以下不正确的表示:

4294967264
但是,我想得到以下结果:

-32
如何在文件中写入负数?

使用
$signed
(,第11.7节“签名表达式”):

module tb;

integer f1;
reg signed [31:0] ALUOutput;

initial begin
    f1 = $fopen("foo.txt", "w");
    ALUOutput = -32;
    $fwrite(f1, "ALUOutput: %d",  $signed(ALUOutput));
    $fdisplay(f1);
    ALUOutput = 32;
    $fwrite(f1, "ALUOutput: %d",  $signed(ALUOutput));
    $fdisplay(f1);
    $fclose(f1);
end

endmodule

/*

foo.txt:
ALUOutput:         -32
ALUOutput:          32
*/