Skip to content

Instantly share code, notes, and snippets.

@gibiansky
gibiansky / mux.v
Created November 25, 2012 06:15
Verilog Module Declaration
// Our input and output signals are all one bit.
// We could make them more than one bit; the only
// thing that would change is we would have to write
// e.g "input [0:N] a" instead of "input a".
module mux(input a, input b, input select, output out);
// Verilog code goes here
endmodule
@gibiansky
gibiansky / mux.v
Created November 25, 2012 06:18
Verilog Multiplexer
module mux(input a, input b, input select, output out);
assign out = select ? a : b;
endmodule
@gibiansky
gibiansky / mux_test.v
Created November 25, 2012 06:19
Verilog Multiplexer Testbench
module mux_test;
reg a, b, s;
wire out;
mux my_mux(a, b, s, out);
initial begin
a <= 0;
b <= 1;
@gibiansky
gibiansky / mux_test.v
Created November 25, 2012 06:21
Verilog Register and Wire Declarations
reg a, b, s;
wire out;
@gibiansky
gibiansky / mux_test.v
Created November 25, 2012 06:23
Verilog Mux Declaration
mux my_mux(a, b, s, out);
@gibiansky
gibiansky / mux_test.v
Created November 25, 2012 06:24
Verilog Initial Statement
initial begin
// Simulation code
end
@gibiansky
gibiansky / mux_test.v
Created November 25, 2012 06:24
Verilog Non-Blocking Assignments
a <= 0;
b <= 1;
s <= 0;
@gibiansky
gibiansky / mux_test.v
Created November 25, 2012 06:25
Verilog Display Statement
#1;
$display("In: %b, %b select %b. Out %b.", a, b, s, out);
#1;
@gibiansky
gibiansky / fib.v
Created December 9, 2012 21:46
Verilog Fibonacci Module
module fib(input clock, reset, input [5:0] n, output ready, output [31:0] value)
// Computational circuit
endmodule
@gibiansky
gibiansky / fib.v
Created December 9, 2012 21:50
Verilog Fibonacci Module
module fib(input clock, reset, input [5:0] n, output ready, output [31:0] value)
reg [31:0] previous, current;
reg [5:0] counter;
always @(posedge reset)
begin
previous <= 32'd0;
current <= 32'd1;
counter <= 32'd1;