概要
windowsでiverilogやってみた。
nslやってみた。
全加算器、書いてみた。
サンプルコード
declare ha {
input a;
input b;
output c;
output o;
}
module ha {
{
c = a & b;
o = a ^ b;
}
}
declare fa {
input a;
input b;
input c;
output o;
output s;
}
module fa {
ha ha0;
ha ha1;
{
ha0.a = a;
ha0.b = b;
ha1.a = ha0.o;
ha1.b = c;
o = ha1.o;
s = ha0.c | ha1.c;
}
}
テストベンチ
module test;
reg clk,
rst;
reg a,
b,
c;
fa u(.clk(clk), .rst(rst), .a(a), .b(b), .c(c), .o(o), .s(s));
always #1 clk = ~clk;
integer i,
j,
k;
initial
begin
clk = 0;
rst = 1;
#1
rst = 0;
#1
rst = 1;
$display("a b c o s");
$monitor("%b %b %b %b %b", a, b, c, o, s);
for(i = 0; i < 2; i = i + 1) begin
for(j = 0; j < 2; j = j + 1) begin
for(k = 0; k < 2; k = k + 1) begin
a = i;
b = j;
c = k;
#1;
end
end
end
$finish;
end
endmodule
実行結果
a b c o s
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
以上。