概要
高位合成言語アセンブラを作る。
練習問題、2bit乗算器、やってみた。
コードを書く。
make 12
in 0 3
and 0 2 4
and 1 2 5
and 1 3 11
and 0 3 6
xor 5 6 10
and 5 6 7
xor 4 7 9
and 4 7 8
out 8 11
コンパイル結果
module x(input a, input b, input c, input d, output i, output j, output k, output l);
assign e = a & c;
assign f = b & c;
assign l = b & d;
assign g = a & d;
assign k = f ^ g;
assign h = f & g;
assign j = e ^ h;
assign i = e & h;
endmodule
module testbench;
reg a, b, c, d;
x u(.a(a), .b(b), .c(c), .d(d), .i(i), .j(j), .k(k), .l(l));
initial
begin
$display("a b c d i j k l ");
$monitor("%b %b %b %b %b %b %b %b ", a, b, c, d, i, j, k, l);
a = 0; b = 0; c = 0; d = 0; #10;
a = 0; b = 0; c = 0; d = 1; #10;
a = 0; b = 0; c = 1; d = 0; #10;
a = 0; b = 0; c = 1; d = 1; #10;
a = 0; b = 1; c = 0; d = 0; #10;
a = 0; b = 1; c = 0; d = 1; #10;
a = 0; b = 1; c = 1; d = 0; #10;
a = 0; b = 1; c = 1; d = 1; #10;
a = 1; b = 0; c = 0; d = 0; #10;
a = 1; b = 0; c = 0; d = 1; #10;
a = 1; b = 0; c = 1; d = 0; #10;
a = 1; b = 0; c = 1; d = 1; #10;
a = 1; b = 1; c = 0; d = 0; #10;
a = 1; b = 1; c = 0; d = 1; #10;
a = 1; b = 1; c = 1; d = 0; #10;
a = 1; b = 1; c = 1; d = 1; #10;
$finish;
end
endmodule
成果物
真理値表で確認。
成果物
回路図で確認。
成果物
実行結果
a b c d i j k l
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0
0 0 1 1 0 0 0 0
0 1 0 0 0 0 0 0
0 1 0 1 0 0 0 1
0 1 1 0 0 0 1 0
0 1 1 1 0 0 1 1
1 0 0 0 0 0 0 0
1 0 0 1 0 0 1 0
1 0 1 0 0 1 0 0
1 0 1 1 0 1 1 0
1 1 0 0 0 0 0 0
1 1 0 1 0 0 1 1
1 1 1 0 0 1 1 0
1 1 1 1 1 0 0 1
以上。