2009年9月28日 星期一

行為層作法

module top;

integer ia, ib;
reg a, b;
wire c;

xor x1(c,a,b);

initial
begin
for(ia = 0;ia <= 1;ia = ia + 1)
begin
a=ia;
for(ib = 0;ib <= 1;ib = ib + 1)
begin
b=ib;
#10 $display("a = %d b = %d c = %d", a, b, c);
end
end
end
endmodule

系統時脈模組

1module mux(OUT, A, B, SEL);
2output OUT;
3input A, B, SEL;

5not I5 (sel_n SEL);
6and I6 (sel_a, A, SEL);
7and I7 (sel_b, sel_n, B);

9or I4 (out, sel_a, sel_b);
10 endmodule

2009年9月21日 星期一

使用Verilog基礎語言

module top;
wire a,b;
reg c;
system_clock #100 clock1(a);
system_clock #50 clock2(b);
always#1 c=a&b;
endmodule
module system_clock(clk);
parameter PERIOD=100;output clk;
reg clk;initialclk=0;
alwaysbegin#(PERIOD/2)clk=~clk;
#(PERIOD-PERIOD/2)clk=~clk;
endalways@(posedge clk)if($time>1000)#(PERIOD-1)$stop;
endmodule