1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-11-02

#概要

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

#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

#成果物

#回路図を表示。

無題.jpg

#成果物

#コンパイルして、生成した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



#成果物

#実行結果


a b c d e f o p q r
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 1 0
0 0 0 0 1 0 0 1 0 0
0 0 0 0 1 1 0 1 1 0
0 0 0 1 0 0 1 0 0 0
0 0 0 1 0 1 1 0 1 0
0 0 0 1 1 0 1 1 0 0
0 0 0 1 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1 0 0 1
1 1 1 0 1 1 1 0 1 1
1 1 1 1 0 0 0 0 0 1
1 1 1 1 0 1 0 0 1 1
1 1 1 1 1 0 0 1 0 1
1 1 1 1 1 1 0 1 1 1


以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?