Verilog-Anzeigeaufgaben
Anzeigesystemaufgaben werden hauptsächlich verwendet, um Informations- und Debug-Meldungen anzuzeigen, um den Ablauf der Simulation aus Protokolldateien zu verfolgen, und helfen auch beim schnelleren Debuggen. Es gibt verschiedene Gruppen von Anzeigeaufgaben und Formaten, in denen sie Werte drucken können.
Aufgaben anzeigen/schreiben
Syntax
Beide $display
und $write
Argumente in der Reihenfolge anzeigen, in der sie in der Argumentliste erscheinen.
$display(<list_of_arguments>);
$write(<list_of_arguments>);
$write
fügt das Zeilenumbruchzeichen
nicht an bis zum Ende seiner Zeichenfolge, während $display
tut und kann aus dem unten gezeigten Beispiel gesehen werden.
Beispiel
module tb;
initial begin
$display ("This ends with a new line ");
$write ("This does not,");
$write ("like this. To start new line, use newline char
");
$display ("This always start on a new line !");
end
endmodule
Simulationsprotokoll ncsim> run This ends with a new line This does not,like this. To start new line, use newline char Hi there ! ncsim: *W,RNQUIE: Simulation is complete.
Verilog-Stroboskope
$strobe
gibt die Endwerte von Variablen am Ende des aktuellen Delta-Zeitschritts aus und hat ein ähnliches Format wie $display
.
module tb;
initial begin
reg [7:0] a;
reg [7:0] b;
a = 8'h2D;
b = 8'h2D;
#10; // Wait till simulation reaches 10ns
b <= a + 1; // Assign a+1 value to b
$display ("[$display] time=%0t a=0x%0h b=0x%0h", $time, a, b);
$strobe ("[$strobe] time=%0t a=0x%0h b=0x%0h", $time, a, b);
#1;
$display ("[$display] time=%0t a=0x%0h b=0x%0h", $time, a, b);
$strobe ("[$strobe] time=%0t a=0x%0h b=0x%0h", $time, a, b);
end
endmodule
Beachten Sie, dass $strobe
zeigt den aktualisierten Endwert der Variable b zum Zeitpunkt 10ns, was 0x2E ist , und $display
nimmt das erst im nächsten Simulationsdelta bei 11ns auf.
ncsim> run [$display] time=10 a=0x2d b=0x2d [$strobe] time=10 a=0x2d b=0x2e [$display] time=11 a=0x2d b=0x2e [$strobe] time=11 a=0x2d b=0x2e ncsim: *W,RNQUIE: Simulation is complete. ncsim> exit
Kontinuierliche Monitore von Verilog
$monitor
hilft beim automatischen Ausdrucken von Variablen- oder Ausdruckswerten, wenn sich die Variable oder der Ausdruck in ihrer Argumentliste ändert. Es erzielt einen ähnlichen Effekt wie der Aufruf von $display
jedes Mal, wenn eines seiner Argumente aktualisiert wird.
module tb;
initial begin
reg [7:0] a;
reg [7:0] b;
a = 8'h2D;
b = 8'h2D;
#10; // Wait till simulation reaches 10ns
b <= a + 1; // Assign a+1 value to b
$monitor ("[$monitor] time=%0t a=0x%0h b=0x%0h", $time, a, b);
#1 b <= 8'hA4;
#5 b <= a - 8'h33;
#10 b <= 8'h1;
end
endmodule
Beachten Sie, dass $monitor
ist wie eine Aufgabe, die erzeugt wird, um im Hintergrund des Haupt-Threads ausgeführt zu werden, der Wertänderungen seiner Argumentvariablen überwacht und anzeigt. Ein neuer $monitor
Aufgabe kann während der Simulation beliebig oft ausgegeben werden.
ncsim> run [$monitor] time=10 a=0x2d b=0x2e [$monitor] time=11 a=0x2d b=0xa4 [$monitor] time=16 a=0x2d b=0xfa [$monitor] time=26 a=0x2d b=0x1 ncsim: *W,RNQUIE: Simulation is complete.
Verilog-Formatspezifikationen
Um Variablen innerhalb von Anzeigefunktionen auszugeben, geeignete Formatbezeichner müssen für jede Variable angegeben werden.
module tb;
initial begin
reg [7:0] a;
reg [39:0] str = "Hello";
time cur_time;
real float_pt;
a = 8'h0E;
float_pt = 3.142;
$display ("a = %h", a);
$display ("a = %d", a);
$display ("a = %b", a);
$display ("str = %s", str);
#200 cur_time = $time;
$display ("time = %t", cur_time);
$display ("float_pt = %f", float_pt);
$display ("float_pt = %e", float_pt);
end
endmodule
Simulationsprotokoll ncsim> run a = 0e a = 14 a = 00001110 str = Hello time = 200 float_pt = 3.142000 float_pt = 3.142000e+00 ncsim: *W,RNQUIE: Simulation is complete.
Verilog-Escape-Sequenzen
Einige Zeichen gelten als besonders, da sie für andere Anzeigezwecke wie Zeilenumbrüche, Tabulatoren und Seitenvorschübe stehen. Um diese Sonderzeichen zu drucken , muss jedes Auftreten solcher Zeichen escaped werden .
module tb;
initial begin
$write ("Newline character
");
$display ("Tab character stop");
$display ("Escaping " %%");
/*
// Compilation errors
$display ("Without escaping "); // ERROR : Unterminated string
$display ("Without escaping ""); // ERROR : Unterminated string
*/
end
endmodule
Simulationsprotokoll ncsim> run Newline character Tab character stop Escaping " % ncsim: *W,RNQUIE: Simulation is complete.
Verilog