高位合成言語アセンブラを作る。 その10

#概要

高位合成言語アセンブラを作る。
練習問題、やってみた。

#3bit加算器を作れ。

```
make 18
in 0 5
wire 6 13
xor 0 3 14
and 0 3 6
xor 1 4 7
and 1 4 8
xor 6 7 15
and 6 7 9
or 8 9 10
xor 2 5 11
and 2 5 12
xor 10 11 16
and 10 11 13
or 12 13 17
out 14 17
```

#真理値表を表示。

![無題.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/0d82e16b-1443-5c50-c771-057a8bf19384.jpeg)


#成果物

https://embed.plnkr.co/plunk/Lvw8FtpmrWm4PMAe

#回路図を表示。

![無題.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/1a9d2dc9-9747-18f2-7530-72554e2d79e2.jpeg)


#成果物

https://embed.plnkr.co/plunk/GEaZOnZHFcPV3Tge

#コンパイルして、生成したverilog

```
module x(input a, input b, input c, input d, input e, input f, output o, output p, output q, output r);
    assign o = a ^ d;
    assign g = a & d;
    assign h = b ^ e;
    assign i = b & e;
    assign p = g ^ h;
    assign j = g & h;
    assign k = i | j;
    assign l = c ^ f;
    assign m = c & f;
    assign q = k ^ l;
    assign n = k & l;
    assign r = m | n;
endmodule

module testbench;
    reg a, b, c, d, e, f;
    x u(.a(a), .b(b), .c(c), .d(d), .e(e), .f(f), .o(o), .p(p), .q(q), .r(r));
    initial
    begin
        $display("a b c d e f o p q r ");
        $monitor("%b %b %b %b %b %b %b %b %b %b ", a, b, c, d, e, f, o, p, q, r);
        a = 0; b = 0; c = 0; d = 0; e = 0; f = 0; #10;
        a = 0; b = 0; c = 0; d = 0; e = 0; f = 1; #10;
        a = 0; b = 0; c = 0; d = 0; e = 1; f = 0; #10;
        a = 0; b = 0; c = 0; d = 0; e = 1; f = 1; #10;
        a = 0; b = 0; c = 0; d = 1; e = 0; f = 0; #10;
        a = 0; b = 0; c = 0; d = 1; e = 0; f = 1; #10;
        a = 0; b = 0; c = 0; d = 1; e = 1; f = 0; #10;
        a = 0; b = 0; c = 0; d = 1; e = 1; f = 1; #10;
        a = 0; b = 0; c = 1; d = 0; e = 0; f = 0; #10;
        a = 0; b = 0; c = 1; d = 0; e = 0; f = 1; #10;
        a = 0; b = 0; c = 1; d = 0; e = 1; f = 0; #10;
        a = 0; b = 0; c = 1; d = 0; e = 1; f = 1; #10;
        a = 0; b = 0; c = 1; d = 1; e = 0; f = 0; #10;
        a = 0; b = 0; c = 1; d = 1; e = 0; f = 1; #10;
        a = 0; b = 0; c = 1; d = 1; e = 1; f = 0; #10;
        a = 0; b = 0; c = 1; d = 1; e = 1; f = 1; #10;
        a = 0; b = 1; c = 0; d = 0; e = 0; f = 0; #10;
        a = 0; b = 1; c = 0; d = 0; e = 0; f = 1; #10;
        a = 0; b = 1; c = 0; d = 0; e = 1; f = 0; #10;
        a = 0; b = 1; c = 0; d = 0; e = 1; f = 1; #10;
        a = 0; b = 1; c = 0; d = 1; e = 0; f = 0; #10;
        a = 0; b = 1; c = 0; d = 1; e = 0; f = 1; #10;
        a = 0; b = 1; c = 0; d = 1; e = 1; f = 0; #10;
        a = 0; b = 1; c = 0; d = 1; e = 1; f = 1; #10;
        a = 0; b = 1; c = 1; d = 0; e = 0; f = 0; #10;
        a = 0; b = 1; c = 1; d = 0; e = 0; f = 1; #10;
        a = 0; b = 1; c = 1; d = 0; e = 1; f = 0; #10;
        a = 0; b = 1; c = 1; d = 0; e = 1; f = 1; #10;
        a = 0; b = 1; c = 1; d = 1; e = 0; f = 0; #10;
        a = 0; b = 1; c = 1; d = 1; e = 0; f = 1; #10;
        a = 0; b = 1; c = 1; d = 1; e = 1; f = 0; #10;
        a = 0; b = 1; c = 1; d = 1; e = 1; f = 1; #10;
        a = 1; b = 0; c = 0; d = 0; e = 0; f = 0; #10;
        a = 1; b = 0; c = 0; d = 0; e = 0; f = 1; #10;
        a = 1; b = 0; c = 0; d = 0; e = 1; f = 0; #10;
        a = 1; b = 0; c = 0; d = 0; e = 1; f = 1; #10;
        a = 1; b = 0; c = 0; d = 1; e = 0; f = 0; #10;
        a = 1; b = 0; c = 0; d = 1; e = 0; f = 1; #10;
        a = 1; b = 0; c = 0; d = 1; e = 1; f = 0; #10;
        a = 1; b = 0; c = 0; d = 1; e = 1; f = 1; #10;
        a = 1; b = 0; c = 1; d = 0; e = 0; f = 0; #10;
        a = 1; b = 0; c = 1; d = 0; e = 0; f = 1; #10;
        a = 1; b = 0; c = 1; d = 0; e = 1; f = 0; #10;
        a = 1; b = 0; c = 1; d = 0; e = 1; f = 1; #10;
        a = 1; b = 0; c = 1; d = 1; e = 0; f = 0; #10;
        a = 1; b = 0; c = 1; d = 1; e = 0; f = 1; #10;
        a = 1; b = 0; c = 1; d = 1; e = 1; f = 0; #10;
        a = 1; b = 0; c = 1; d = 1; e = 1; f = 1; #10;
        a = 1; b = 1; c = 0; d = 0; e = 0; f = 0; #10;
        a = 1; b = 1; c = 0; d = 0; e = 0; f = 1; #10;
        a = 1; b = 1; c = 0; d = 0; e = 1; f = 0; #10;
        a = 1; b = 1; c = 0; d = 0; e = 1; f = 1; #10;
        a = 1; b = 1; c = 0; d = 1; e = 0; f = 0; #10;
        a = 1; b = 1; c = 0; d = 1; e = 0; f = 1; #10;
        a = 1; b = 1; c = 0; d = 1; e = 1; f = 0; #10;
        a = 1; b = 1; c = 0; d = 1; e = 1; f = 1; #10;
        a = 1; b = 1; c = 1; d = 0; e = 0; f = 0; #10;
        a = 1; b = 1; c = 1; d = 0; e = 0; f = 1; #10;
        a = 1; b = 1; c = 1; d = 0; e = 1; f = 0; #10;
        a = 1; b = 1; c = 1; d = 0; e = 1; f = 1; #10;
        a = 1; b = 1; c = 1; d = 1; e = 0; f = 0; #10;
        a = 1; b = 1; c = 1; d = 1; e = 0; f = 1; #10;
        a = 1; b = 1; c = 1; d = 1; e = 1; f = 0; #10;
        a = 1; b = 1; c = 1; d = 1; e = 1; f = 1; #10;
        $finish;
    end
endmodule



```

#成果物

https://embed.plnkr.co/plunk/IVBRJ6Fy2aj8i3kS

#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