概要
blocklyでverilog、やってみた。
練習問題、やってみた。
練習問題
全加算器を書いて、iverilogで検証せよ。
写真
生成したコード
module x (input a, input b, input c, output d, output e);
wire w0;
wire w1;
wire w2;
assign w0 = (a ^ b);
assign d = (w0 ^ c);
assign w1 = (w0 & c);
assign w2 = (a & b);
assign e = (w1 | w2);
endmodule
テストベンチを書く。
module test;
reg a, b, c;
wire d, e;
x u(.a(a), .b(b), .c(c), .d(d), .e(e));
initial
begin
$display(" a b c d e");
$monitor(" %b %b %b %b %b", a, b, c, d, e);
#10
a = 0;
b = 0;
c = 0;
#10
a = 0;
b = 0;
c = 1;
#10
a = 0;
b = 1;
c = 0;
#10
a = 0;
b = 1;
c = 1;
#10
a = 1;
b = 0;
c = 0;
#10
a = 1;
b = 0;
c = 1;
#10
a = 1;
b = 1;
c = 0;
#10
a = 1;
b = 1;
c = 1;
#10;
$finish;
end
endmodule
iverilogでコンパイル実行
>iverilog block2.v
>vvp a.out
a b c d e
x x x x x
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
block2.v:53: $finish called at 90 (1s)
生成したフローのxml
<xml xmlns="http://www.w3.org/1999/xhtml">
<variables>
<variable type="" id="kVo~|WbMj?w*jRaeu?IZ">w0</variable>
<variable type="" id="aK`hj)H0(K^,p~WGOQM?">d</variable>
<variable type="" id="c3#ZGedh.Q+LvFE+z92#">w1</variable>
<variable type="" id="wMdqw@6I7M-~PFkDh,7v">a</variable>
<variable type="" id="]wH}w0D?XRXn4i7NX^Wq">b</variable>
<variable type="" id="`2Qn{%MFf)jQ.ws3-{wH">w2</variable>
<variable type="" id="US6mg:+!q~Nw!qA4u~S)">c</variable>
<variable type="" id="bOL!B%_{Sxh:-mj1$=p8">e</variable>
</variables>
<block type="module_dec" id="4SExhY1)y(jwDTBa0Nj+" x="20" y="5">
<field name="modName">x</field>
<field name="varNames">input a, input b, input c, output d, output e</field>
<next>
<block type="wire_block" id="DLVr9Gy7V=6nHHkC8#=}">
<field name="NAME">w0</field>
<next>
<block type="wire_block" id="vCDpUQtcx$ncFS1z7Ix-">
<field name="NAME">w1</field>
<next>
<block type="wire_block" id="GXZa,hE^y5`K8aP8hne6">
<field name="NAME">w2</field>
<next>
<block type="assign_block" id="PVW_J{B2Etv`jhQBz+6a">
<field name="var" id="kVo~|WbMj?w*jRaeu?IZ" variabletype="">w0</field>
<value name="NAME">
<block type="logic_operation" id="bzrS@SuPHa6[u4Z8qCcx">
<field name="OP">XOR</field>
<value name="A">
<block type="variables_get" id="7|XE?mj@rQxxElU2O!pR">
<field name="VAR" id="wMdqw@6I7M-~PFkDh,7v" variabletype="">a</field>
</block>
</value>
<value name="B">
<block type="variables_get" id=")``^8jto}#fr@})(^)s$">
<field name="VAR" id="]wH}w0D?XRXn4i7NX^Wq" variabletype="">b</field>
</block>
</value>
</block>
</value>
<next>
<block type="assign_block" id=")LcG*M$p/U[rnkpUdQ7p">
<field name="var" id="aK`hj)H0(K^,p~WGOQM?" variabletype="">d</field>
<value name="NAME">
<block type="logic_operation" id="~(g5x,]UFm-?r1)%?+K^">
<field name="OP">XOR</field>
<value name="A">
<block type="variables_get" id="h3]cA!k%*CER9U0Cr;[G">
<field name="VAR" id="kVo~|WbMj?w*jRaeu?IZ" variabletype="">w0</field>
</block>
</value>
<value name="B">
<block type="variables_get" id="*_=(57`VJ*w~L(f`$P7_">
<field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">c</field>
</block>
</value>
</block>
</value>
<next>
<block type="assign_block" id="y=s7.#Fa:/yI|B-s~0ng">
<field name="var" id="c3#ZGedh.Q+LvFE+z92#" variabletype="">w1</field>
<value name="NAME">
<block type="logic_operation" id="k84Y*q%%*OuS4WJBN}66">
<field name="OP">AND</field>
<value name="A">
<block type="variables_get" id="#|Y47^dhpRSJfT^F%dMZ">
<field name="VAR" id="kVo~|WbMj?w*jRaeu?IZ" variabletype="">w0</field>
</block>
</value>
<value name="B">
<block type="variables_get" id="U]ga2-yDa8uNi%%Q.`6T">
<field name="VAR" id="US6mg:+!q~Nw!qA4u~S)" variabletype="">c</field>
</block>
</value>
</block>
</value>
<next>
<block type="assign_block" id="3k`qSVgIa0[vnq8s~ek-">
<field name="var" id="`2Qn{%MFf)jQ.ws3-{wH" variabletype="">w2</field>
<value name="NAME">
<block type="logic_operation" id="A#l8VoF|}G[lR5(BWwc|">
<field name="OP">AND</field>
<value name="A">
<block type="variables_get" id="NM)T.*fJ*E[Fo|P_sEju">
<field name="VAR" id="wMdqw@6I7M-~PFkDh,7v" variabletype="">a</field>
</block>
</value>
<value name="B">
<block type="variables_get" id="c0qkS6Mwp+$@m/XzuYJn">
<field name="VAR" id="]wH}w0D?XRXn4i7NX^Wq" variabletype="">b</field>
</block>
</value>
</block>
</value>
<next>
<block type="assign_block" id="+glnw9t|nq#QHNXwMBqs">
<field name="var" id="bOL!B%_{Sxh:-mj1$=p8" variabletype="">e</field>
<value name="NAME">
<block type="logic_operation" id="77svh7Mb?nlGqY*`ZdSc">
<field name="OP">OR</field>
<value name="A">
<block type="variables_get" id="tAgiVzzz^K2:S;`j}n^a">
<field name="VAR" id="c3#ZGedh.Q+LvFE+z92#" variabletype="">w1</field>
</block>
</value>
<value name="B">
<block type="variables_get" id="@u)(Wzb#fvS:L9=,UzdI">
<field name="VAR" id="`2Qn{%MFf)jQ.ws3-{wH" variabletype="">w2</field>
</block>
</value>
</block>
</value>
<next>
<block type="end_module" id="ODsu=)XrOwDd2b~P;iY-"></block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</xml>
以上。