Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
endmodule
its i'portant that $ou in(lude also these lines in $our initial +lo(" 0for ever$ arra$ $ou
defined6) in order to +e a+le to see the arra$ signals in -TK&ave.
module Test;
integer i;
...
initial begin
$dumpfile("my_dumpfile.vcd");
$dumpvars(0, my_module_name);
for(i = 0; i < M; i = i + 1)
$dumpvars(1, full.path.to.array.data[i]);
end
...
endmodule
It%s pro+a+le that the last a(tion will result a &arning t$pe li"e that +elow during the (o'pilation!
You don%t need to worr$.
VCD warning: array word cpu_tb.cpu0.cpu_dp.data_mem.data[39] will
conflict with an escaped identifier.
Opening VCD files with GTKWave
You (an open o ,<D file either fro' ter'inal or +$ the -7I! In this guide I%ll use as 'u(h as I (an
the ter'inal wa$! It%s 'ore (at(h$ and for sure it%ll save as useful ti'e) espe(iall$ when we test a
hardware design! So here we go.
$ gtkwave my_dumpfile.vcd
As $ou (an see) there aren%t an$ waves in the &ave window! That%s +e(ause the user has to (hoose
whi(h signals want to see! In order to (hoose the signal $ou want to see) $ou should go in the left
window with the SST na'e! Here $ou (an see $our hardware hierar(h$! B$ (li("ing the ? of ever$
instan(e) $ou (an see the signals that are related with that instan(e! Then $ou (an dragCdrop the')
or (op$Cpaste the' in the Signals window! ,oilD/ Here are the wavefor's!
NOT! "hen I close and re#open $T%"a&e with the same '() file* the signals that I ha&e chosen
+efore are lost. Should I alwa,s spend all this time +, onl, inserting signals to +e shown-
The answer is Eof (ourse not/F! After $ou have de(ided on the signals $ou want to +e shown $ou
(an (li(" File Write Save File As and save a file with a !gt"w ending! Let%s sa$ for this ea'ple
(onfig!gt"w! 9ro' now and then $ou (an open it with $our !v(d file and get instantl$ to the point)
whi(h is de+ugging G6 .
$ gtkwave my_dumpfile.vcd config.gtkw
A etter view on things
Now $ou are a+le to see the values of the signals in a faster wa$! But how a+out the interpretationH
The values of the signals are in heade(i'al for'at and all waves are (olored green! Yes/ You (an
(hange these properties!
You (an (hange the' +$ right1(li("ing on the signals and (hoosing Data For!at or Color For!at!
You are free to eperi'ent with these options! &hen $ou have the desired opti(al result $ou (an
save $our (onfiguration +$ going File Write Save File!
All (r$stal (lear until now!!!
Ta"e GTKWave # #o$r side
&hen $ou right1(li(" on a signal and espe(iall$ in the Data For!at option $ou (an see the (hoi(e
Translate Filter File! &e%ll sti(" with that option for the rest of this guide! It%s a ver$ powerful
option) +ut it goes +$ the 'ost ti'es as there%s not there!
&ith that option $ou (an translate the values of the signals in a 'ore hu'an wa$! You (an do this
+$ writing a !tt translation filter! It isn%t as (o'ple as it sounds! Let%s see an ea'ple.
You write a *I>S pro(essor in ,erilog! You have a Iegister 9ile with the register of this
ar(hite(ture! You don%t want to see the na'es of the' as he nu'+ers) even as de(i'al! So $ou (an
si'pl$ write a !tt file li"e this.
00 $0 - $zero
01 $1 - $at
02 $2 - $v0
...
The first (olu'n represents the heade(i'al values that a signal that represents registers (an have!
The se(ond 'ore (o'ple (olu'n is what we want to see instead of the first (olu'n! And that%s it/!
Now we onl$ have to go to the signal we want to (hange) right1(li(" on it) (hoose Data For!at
Translate Filter File %nale and Select! Then $ou have to +rowse to the filter $ou wrote)
(hoose it and hit OK! ,oilD/ 0*a"e sure that the data for'at is in he +efore $ou (hoose the filter6!
Now $ou (an save again $our (onfiguration! You%re read$ to go/
In that wa$ $ou (an filter whatever $ou want! 9ro' registers% na'es and op(odes to full
instru(tions/ 9ull instru(tionsHHH
Supposing that we tal" a+out a *I>S i'ple'entation) we initialiJe the Instru(tion *e'or$ arra$
with the verilog (o''and $readmemb() fro' a file! This file 'ust +e of su(h for'at.
@0 000000_01000_00100_01001_00000_100000 // add $t1, $t0, $a0
@4 101011_01011_01001_0000000000000101 // sw $t1, 5($t3)
@8 100011_01011_10010_0000000000000101 // lw $s2, 5($t3)
@c 000000_01000_10011_01001_00000_101010 // slt $t1, $t0, $s3
@10 000100_01001_10010_1111111111111011 // beq $t1, $s2, -5
where the first (olu'n is the address in he of the (o''and 0in *I>S ever$ address ta"es 3@ +its6
and the se(ond (olu'n is the +inar$ representation of the *I>S asse'+l$ instru(tion! You (an
in(lude so'e <?? st$le (o''ents if $ou li"e to!
This spe(ial (o''and is used li"e that in an initial +lo(".
$readmemb("program.mbin", full.path.to.data);
Before we (ontinue with '$ favorite part) let%s 'a"e our life a lot easier!
&a"efile' O$r est friend
Let%s (reate a si'ple 'a"e file with what we saw up to here! The s(enario is that we have a design
in ,erilog and we want to run it and see the wavefor's instantl$) without tou(hing the 'ouse at all.
CC = iverilog
FLAGS = -Wall -Winfloop
library_input: one.v two.v testbench.v
$(CC) $(FLAGS) -o test one.v two.v testbench.v
vvp test
gtkwave my_dumpfile.vcd config.gtkw
The 'a"efile should +e in the sa'e dire(tor$ with the other !v) !v(d and !gt"w files in our ea'ple!
You si'pl$ ee(ute this "ind of s(ript +$ ;ust t$ping 'a"e in the ter'inal!
$ make
Now) when $ou want to run $our verilog (ode $ou (an ;ust t$pe make and ever$thing (o'es up for
$ou!
(o pain (o gain
Now (o'es the last +ut the +est part! How (an $ou represent the instru(tions in -TK&ave fro' the
'o'ent $ou have to (hange the' fro' test to testH It%s ti'e (onsu'ing! It%s also ti'e (onsu'ing to
(onvert an instru(tion to its +inar$ representation in order to test the pro(essor! There are so'e
online (onverters) +ut the$ restri(t $ou in the wa$ that $ou (annot insert a whole progra' and get its
+inar$! 9urther'ore) its +oring to fill the file with addresses 0K8) K5) L6! There are ti'es $ou
want to run a +ig progra') and $ou spend the M ti'e in (onverting it in a for'at that
$readmemb() (an read it!
9or this reason there%s no solution +ut to develop $our own parser! You%ll spend a few hours to finish
it) +ut the results will save $ou a lot 'ore hours in the testing of $our (ode! 9or 'e I developed a
*I>S asse'+l$ to *I>S +inar$ parser! I na'ed it *AS*BIN and wor"s li"e this. It ta"es as first
argu'ent the !'as' asse'+l$ file 0input6) and as a se(ond argu'ent the !'+in +inar$ file 0output6.
$ ./masmbin input.masm output.mbin
In this stage) it (an ta"e @ options.
-c
Shows in .mbin file in comments the parsed instruction
-f filter.txt
Outputs a .txt filter file for GTKWave
So as $ou see) this parser does another ;o+ with the right option. It (reates the filter that we wanted
to represent the values of signals in -TK&ave as higher level instru(tions!
Now we%re going to put ever$thing together and have a ni(e *I>S asse'+l$ si'ulator!
Let%s start fro' the (onventions $ou should ta"e.
In Nread'e'+06) the file 'ust +e the sa'e 0for our ea'ple) program.m+in6
The filter for our instru(tions in -TK&ave should have a sta+le na'e 0for our ea'ple)
translate.instruction.t/t6
O") now lets write our final 'a"efile.
CC = iverilog
FLAGS = -Wall -Winfloop
library_input: one.v two.v testbench.v
$(CC) $(FLAGS) -o test one.v two.v testbench.v
./masmbin -c -f translate_instruction.txt program.masm
program.mbin
vvp test
gtkwave my_dumpfile.vcd config.gtkw
Now) ever$thing is in pla(e! You (an edit the progra'!'as' file as $ou want) save it) and ee(ute
'a"e! Ever$thing will (o'e up auto'ati(all$!
If $ou want to download the new version of *AS*BIN $ou (an do so at
https'))dl.dropo*$sercontent.co!)$)+,-,./0.)&12S3as!3to3in3parser3v/.-.tar.g4!
9or the previous version refer to the githu+ repositor$.
https.##githu+!(o'#gon233@#*I>S1as'1to1+in1parser