CODE:1 Verilog code for flip-flop with a positive-edge clock.
// Verilog code for flip-flop with a positive-edge clock.moduleflop (clk, d, q);input clk, d;output q;reg q;always @(posedge clk)beginq <= d;endendmodule
CODE:2 Verilog code for flip-flop with a negative-edge clock and asynchronous clear.
//Verilog code for flip-flop with a negative-edge clock and asynchronous clear.moduleflop (clk, d, clr, q);input clk, d, clr;output q;reg q;always @(negedge clk orposedge clr)beginif (clr)q <=1’b0;elseq <= d;endendmodule
CODE:3 Verilog code for flip-flop with a positive-edge clock and synchronous set.
//Verilog code for flip-flop with a positive-edge clock and synchronous set.moduleflop (clk, d, s, q);input clk, d, s;output q;reg q;always @(posedge clk)beginif (s)q <=1’b1;elseq <= d;endendmodule
CODE:4 Verilog code for flip-flop with a positive-edge clock and clock enable.
//Verilog code for flip-flop with a positive-edge clock and clock enablemoduleflop (clk, d, ce, q);input clk, d, ce;output q;reg q;always @(posedge clk)beginif (ce)q <= d;endendmodule
CODE:5 Verilog code for a 4-bit register with a pos-edge clock, asynchronous set and clock enable.
//Verilog code for a 4-bit register with a positive-edge clock,asynchronous set and clock enable.moduleflop (clk, d, ce, pre, q);input clk, ce, pre;input [3:0] d;output [3:0] q;reg [3:0] q;always @(posedge clk orposedge pre)beginif (pre)q <=4’b1111;elseif (ce)q <= d;endendmodule
CODE:6 Verilog code for a latch with a positive gate
//Verilog code for a latch with a positive gate.modulelatch (g, d, q);input g, d;output q;reg q;always @(g or d)beginif (g)q <= d;endendmodule
CODE:7 Verilog code for a latch with a positive gate and an asynchronous clear.
// Verilog code for a latch with a positive gate and an asynchronous clear.modulelatch (g, d, clr, q);input g, d, clr;output q;reg q;always @(g or d or clr)beginif (clr)q <=1’b0;elseif (g)q <= d;endendmodule
CODE:8 Verilog code for a 4-bit latch with an inverted gate and an asynchronous preset.
// Verilog code for a 4-bit latch with an inverted gate and an asynchronous preset.modulelatch (g, d, pre, q);input g, pre;input [3:0] d;output [3:0] q;reg [3:0] q;always @(g or d or pre)beginif (pre)q <=4’b1111;elseif (~g)q <= d;endendmodule
CODE:9 Verilog code for a tristate element using a combinational process and always block.
// Verilog code for a tristate element using a combinatorial process and always block.modulethree_st (t, i, o);input t, i;output o;reg o;always @(t or i)beginif (~t)o = i;elseo =1’bZ;endendmodule
CODE:10 Verilog code for a tristate element using a concurrent assignment.
// Verilog code for a tristate element using a concurrent assignment.modulethree_st (t, i, o);input t, i;output o;assign o = (~t) ? i: 1’bZ;endmodule
CODE:11 Verilog code for a 4-bit unsigned up counter with asynchronous clear.
// Verilog code for a 4-bit unsigned up counter with asynchronous clear.modulecounter (clk, clr, q);input clk, clr;output [3:0] q;reg [3:0] tmp;always @(posedge clk orposedge clr)beginif (clr)tmp <=4’b0000;elsetmp <= tmp +1’b1;endassign q = tmp;endmodule