Si su simulador admite la sintaxis de SystemVerilog, aquí hay una función que puede usarse para mostrar enteros de hasta 64 bits. Los valores más amplios requieren múltiples llamadas a la función. La función puede mostrar valores como binarios, decimales o hexadecimales.
module tb;
function string fmt (longint num, string radix, int width = 1);
// Convert integer input into a string with underscores
// for $display. For example: 12345 -> 12_345.
// radix should be [d|h|b].
// width can be used for zero-padding on the left.
// Any x/z passed into num gets converted to 0.
// Reals passed into num are rounded to an integer.
// Values greater than 64-bit are truncated.
int pos, chars;
string str, str2, fmtstr;
str2 = "";
fmtstr = {"%0", $sformatf("%0d", width), radix};
str = $sformatf(fmtstr, num);
chars = (radix == "d") ? 3 : 4;
pos = 0;
for (int i = str.len()-1; i>=0; i--) begin
pos++;
str2 = {str.getc(i), str2};
if (pos % chars == 0) str2 = {"_", str2};
end
// Remove any leading underscore
if (str2.getc(0) == "_") begin
str2 = str2.substr(1, str2.len()-1);
end
return str2;
endfunction
reg [127:0] big;
reg [ 63:0] data;
initial begin
data = 64'hfeed1234;
$display(fmt(data, "h"));
$display(fmt(98765, "d"));
$display(fmt(33, "b", 8));
big = 128'h123456789abcdef0777788889999aaaa;
$display({fmt(big[127:64], "h"), "_", fmt(big[63:0], "h", 16)});
end
endmodule
/*
Output:
feed_1234
98_765
0010_0001
1234_5678_9abc_def0_7777_8888_9999_aaaa
*/