text stringlengths 1 2.1M |
|---|
// Quartus II Verilog Template
// Barrel shifter
module barrel_shifter
#(parameter M=8, parameter N=2**M)
(
input [N-1:0] data,
input [M-1:0] distance,
input clk, enable, shift_left,
output reg [N-1:0] sr_out
);
// Declare temporary registers
reg [2*N-1:0] tmp;
// Shift/rotate in the specified direction and
... |
module top_module( input in, output out );
assign out = in;
endmodule
|
module top_module(
input a,b,c,
output w,x,y,z );
assign w = a;
assign x = b;
assign y = b;
assign z = c;
endmodule
|
module top_module( input in, output out );
assign out = ~in;
endmodule
|
module top_module(
input a,
input b,
output out );
assign out = a&b;
endmodule
|
module top_module(
input a,
input b,
output out );
assign out = ~(a|b);
endmodule
|
module top_module(
input a,
input b,
output out );
assign out = ~a^b;
endmodule
|
`default_nettype none
module top_module(
input a,
input b,
input c,
input d,
output out,
output out_n );
wire in1,in2;
assign in1 = a & b;
assign in2 = c & d;
assign out = in1 | in2;
assign out_n = ~(in1 | in2);
endmodule
|
module top_module (
input p1a, p1b, p1c, p1d, p1e, p1f,
output p1y,
input p2a, p2b, p2c, p2d,
output p2y );
assign p1y = (p1a & p1b & p1c) | (p1d & p1e & p1f);
assign p2y = (p2a & p2b) | (p2d & p2c);
endmodule
|
module top_module (
input wire [2:0] vec,
output wire [2:0] outv,
output wire o2,
output wire o1,
output wire o0 ); // Module body starts after module declaration
assign outv = vec;
assign o2 = vec[2];
assign o1 = vec[1];
assign o0 = vec[0];
endmodule
|
`default_nettype none // Disable implicit nets. Reduces some types of bugs.
module top_module(
input wire [15:0] in,
output wire [7:0] out_hi,
output wire [7:0] out_lo );
assign {out_hi,out_lo} = in;
endmodule
|
module top_module(
input [31:0] in,
output [31:0] out );//
assign {out[7:0],out[15:8],out[23:16],out[31:24]} = in;
endmodule
|
module top_module(
input [2:0] a,
input [2:0] b,
output [2:0] out_or_bitwise,
output out_or_logical,
output [5:0] out_not
);
assign out_or_bitwise = a | b;
assign out_or_logical = a || b;
assign out_not[2:0] = ~a; // Part-select on left side is o.
assign out_not[5:3] = ~b; //Assigning to [5:3] does not co... |
module top_module(
input [3:0] in,
output out_and,
output out_or,
output out_xor
);
assign out_and = in[0] & in[1] & in[2] & in[3] ;
assign out_or = in[0] | in[1] | in[2] | in[3];
assign out_xor = in[0] ^ in[1] ^ in[2] ^ in[3];
endmodule
|
module top_module (
input [4:0] a, b, c, d, e, f,
output [7:0] w, x, y, z );//
assign w = {a[4:0],b[4:2]};
assign x = {b[1:0],c[4:0],d[4]};
assign y = {d[3:0],e[4:1]};
assign z = {e[0],f[4:0],2'b11};
endmodule
|
module top_module(
input [7:0] in,
output [7:0] out
);
assign out[7:0] = {in[0],in[1],in[2],in[3],in[4],in[5],in[6],in[7]};
/*
// I know you're dying to know how to use a loop to do this:
// Create a combinational always block. This creates combinational logic that computes the same result
// as ... |
module top_module (
input [7:0] in,
output [31:0] out );//
assign out = {{24{in[7]}},{in}};
endmodule
|
module top_module (
input a, b, c, d, e,
output [24:0] out );//
wire [4:0] k = {a,b,c,d,e};
assign out[24:20] = ~ {5{a}} ^ k;
assign out[19:15] = ~ {5{b}} ^ k;
assign out[14:10] = ~ {5{c}} ^ k;
assign out[9:5] = ~ {5{d}} ^ k;
assign out[4:0] = ~ {5{e}} ^ k;
endmodule
|
module top_module (
input a,
input b,
output out
);
// Create an instance of "mod_a" named "inst1", and connect ports by name:
mod_a inst1 (
.in1(a), // Port"in1"connects to wire "a"
.in2(b), // Port "in2" connects to wire "b"
.out(out) // Port "out" connects to wire "out"
// (Note: mod_a's port "out... |
module top_module (
input a,
input b,
input c,
input d,
output out1,
output out2
);
mod_a aa(out1,out2,a,b,c,d);
endmodule
|
module top_module (
input a,
input b,
input c,
input d,
output out1,
output out2
);
mod_a aaaa(.out1(out1),.out2(out2),.in1(a),.in2(b),.in3(c),.in4(d));
endmodule
|
module top_module ( input clk, input d, output q );
wire q1,q2;
my_dff d1(clk,d,q1);
my_dff d2(clk,q1,q2);
my_dff d3(clk,q2,q);
endmodule |
module top_module (
input clk,
input [7:0] d,
input [1:0] sel,
output reg [7:0] q
);
wire [7:0] o1, o2, o3; // output of each my_dff8
// Instantiate three my_dff8s
my_dff8 d1 ( clk, d, o1 );
my_dff8 d2 ( clk, o1, o2 );
my_dff8 d3 ( clk, o2, o3 );
// This is one way to make a 4-to-1 multiplexer
always @(... |
module top_module(
input [31:0] a,
input [31:0] b,
output [31:0] sum
);
wire con1, con2;
add16 adder_1(a[15:0], b[15:0], 0, sum[15:0], con1);
add16 adder_2(a[31:16], b[31:16], con1, sum[31:16], con2);
endmodule
|
module top_module (
input [31:0] a,
input [31:0] b,
output [31:0] sum
);//
wire con1, con2;
add16 adder_1(a[15:0], b[15:0], 0, sum[15:0], con1);
add16 adder_2(a[31:16], b[31:16], con1, sum[31:16], con2);
endmodule
module add1 ( input a, input b, input cin, output sum, output cout );
assign s... |
module top_module(
input [31:0] a,
input [31:0] b,
output [31:0] sum
);
wire cout1,cout2a,cout2b;
wire [15:0] sum2a,sum2b;
add16 add1(a[15:0],b[15:0],0,sum[15:0],cout1);
add16 add2a(a[31:16],b[31:16],0,sum2a,cout2a);
add16 add2b(a[31:16],b[31:16],1,sum2b,cout2b);
always @(*) beg... |
module top_module(
input [31:0] a,
input [31:0] b,
input sub,
output [31:0] sum
);
wire cout,cout2;
wire [31:0] b_in;
assign b_in = b^{32{sub}};
add16 a1(a[15:0],b_in[15:0],sub,sum[15:0],cout);
add16 a2(a[31:16],b_in[31:16],cout,sum[31:16],cout2);
endmodule
|
// synthesis verilog_input_version verilog_2001
module top_module(
input a,
input b,
output wire out_assign,
output reg out_alwaysblock
);
assign out_assign = a&b;
always @(*) out_alwaysblock = a&b;
endmodule
|
// synthesis verilog_input_version verilog_2001
module top_module(
input clk,
input a,
input b,
output wire out_assign,
output reg out_always_comb,
output reg out_always_ff );
assign out_assign = a^b;
always @(*) out_always_comb = a^b;
always @(posedge clk) out_always_ff <= a^b;
e... |
// synthesis verilog_input_version verilog_2001
module top_module(
input a,
input b,
input sel_b1,
input sel_b2,
output wire out_assign,
output reg out_always );
assign out_assign = (sel_b1&sel_b2)?b:a;
always@(*) begin
if (sel_b1&sel_b2) begin
out_always = ... |
// synthesis verilog_input_version verilog_2001
module top_module (
input cpu_overheated,
output reg shut_off_computer,
input arrived,
input gas_tank_empty,
output reg keep_driving ); //
always @(*) begin
if (cpu_overheated)
shut_off_computer = 1;
end
... |
// synthesis verilog_input_version verilog_2001
module top_module (
input [2:0] sel,
input [3:0] data0,
input [3:0] data1,
input [3:0] data2,
input [3:0] data3,
input [3:0] data4,
input [3:0] data5,
output reg [3:0] out );//
always@(*) begin // This is a combinational circuit
... |
// synthesis verilog_input_version verilog_2001
module top_module (
input [3:0] in,
output reg [1:0] pos );
always @(*) begin
pos = (in[0]&1)?2'd0:(in[1]&1)?2'd1:(in[2]&1)?2'd2:(in[3]&1)?2'd3:2'd0;
end
endmodule
|
module top_module (
input [7:0] in,
output reg [2:0] pos );
// casez treats bits that have the value z as don't-care in the comparison.
//Notice how there are certain inputs (e.g., 4'b1111) that will match more than one case item.
//The first match is chosen (so 4'b1111 matches the first... |
// synthesis verilog_input_version verilog_2001
module top_module (
input [15:0] scancode,
output reg left,
output reg down,
output reg right,
output reg up );
always @(*) begin
up = 1'b0; down = 1'b0; left = 1'b0; right = 1'b0;
case (scancode)
16'he06b: left = 1'b... |
module top_module (
input [7:0] a, b, c, d,
output [7:0] min);//
wire [7:0] min1 = (a<b)?a:b;
wire [7:0] min2 = (c<d)?c:d;
assign min = (min1<min2)? min1 : min2;
endmodule |
module top_module (
input [7:0] in,
output parity);
assign parity = ^ in;
endmodule
|
module top_module(
input [99:0] in,
output out_and,
output out_or,
output out_xor
);
assign {out_and,out_or,out_xor} = {&in,|in,^in};
endmodule
|
module top_module(
input [99:0] in,
output [99:0] out
);
integer i;
always @(in) begin
for(i=0;i<100;i++) begin
out[i] = in[99-i];
end
end
endmodule
|
module top_module (
input [254:0] in,
output reg [7:0] out
);
always @(*) begin // Combinational always block
out = 0;
for (int i=0;i<255;i++)
out = out + in[i];
end
endmodule
|
module top_module(
input [99:0] a, b,
input cin,
output [99:0] cout,
output [99:0] sum );
integer i;
always @(*) begin
sum[0] = a[0] ^ b[0] ^ cin;
cout[0] = a[0] & b[0] | cin & (a[0]|b[0]);
for (i = 1; i<100; i++) begin
sum[i] = a[i] ^ b[i] ^ cout[i-1];
... |
module top_module(
input [399:0] a, b,
input cin,
output cout,
output [399:0] sum );
wire[99:0] cout_wires;
genvar i;
generate
bcd_fadd(a[3:0], b[3:0], cin, cout_wires[0],sum[3:0]);
for (i=4; i<400; i=i+4) begin: bcd_adder_instances
bcd_fadd bcd_adder(a... |
module top_module (
input in,
output out);
assign out = in;
endmodule
|
module top_module (input x, input y, output z);
assign z = (x^y) & x;
endmodule
|
module top_module (input x, input y, output z);
assign z = ~(x^y);
endmodule
|
module top_module(
input x,
input y,
output z);
wire o1, o2, o3, o4;
A ia1 (x, y, o1);
B ib1 (x, y, o2);
A ia2 (x, y, o3);
B ib2 (x, y, o4);
assign z = (o1 | o2) ^ (o3 & o4);
// Or you could simplify the circuit including the sub-modules:
// assign z = x|~y;
endmodule
module A (
input x,
input y,
... |
module top_module(
input ring,
input vibrate_mode,
output ringer,
output motor
);
// When should ringer be on? When (phone is ringing) and (phone is not in vibrate mode)
assign ringer = ring & ~vibrate_mode;
// When should motor be on? When (phone is ringing) and (phone is in vibrate mode)
assign motor = r... |
module top_module (
input too_cold,
input too_hot,
input mode,
input fan_on,
output heater,
output aircon,
output fan
);
assign fan = fan_on | heater | aircon;
assign heater = mode & too_cold;
assign aircon = ~mode & too_hot;
endmodule
|
module top_module(
input [2:0] in,
output [1:0] out );
integer i,count;
always @ * begin
count = 0;
for (i=0; i<3;i=i+1) begin
if (in[i]==1'b1) count=count+1;
end
out = count;
end
endmodule |
module top_module(
input [3:0] in,
output [2:0] out_both,
output [3:1] out_any,
output [3:0] out_different );
assign out_both = {in[3]&in[2],in[2]&in[1],in[1]&in[0]};
assign out_any = {in[3]|in[2],in[2]|in[1],in[1]|in[0]};
assign out_different = {in[0]^in[3],in[3]^in[2],in[2]^in[1],in[... |
module top_module(
input [99:0] in,
output [98:0] out_both,
output [99:1] out_any,
output [99:0] out_different );
assign out_any = in[99:1] | in[98:0];
assign out_both = in[98:0] & in[99:1];
assign out_different = in ^ {in[0], in[99:1]};
endmodule
|
module top_module (
output out);
assign out = 1'b0;
endmodule
|
module top_module (
input in1,
input in2,
output out);
assign out = ~ (in1|in2);
endmodule
|
module top_module (
input in1,
input in2,
input in3,
output out);
assign out = in3 ^ ~(in1^in2);
endmodule
|
module top_module(
input a, b,
output out_and,
output out_or,
output out_xor,
output out_nand,
output out_nor,
output out_xnor,
output out_anotb
);
assign out_and = a&b;
assign out_or = a|b;
assign out_xor = a^b;
assign out_nand = ~out_and;
assign out_nor = ~out_or;
... |
module top_module (
input p1a, p1b, p1c, p1d,
output p1y,
input p2a, p2b, p2c, p2d,
output p2y );
assign p1y = ~(p1a && p1b && p1c && p1d);
assign p2y = ~(p2a && p2b && p2c && p2d);
endmodule
|
module top_module (
input x3,
input x2,
input x1,
output f
);
// This truth table has four minterms.
assign f = ( ~x3 & x2 & ~x1 ) |
( ~x3 & x2 & x1 ) |
( x3 & ~x2 & x1 ) |
( x3 & x2 & x1 ) ;
// It can be simplified, by boolean algebra or Karnaugh maps.
// assign f = (~x3 & x2) | (x3 & x1);
... |
module top_module(
input [1:0] A,
input [1:0] B,
output z);
// assign z = (A[0] == B[0]) && (A[1] == B[1]);
assign z = (A[1:0]==B[1:0]); // Comparisons produce a 1 or 0 result.
// Another option is to use a 16-entry truth table ( {A,B} is 4 bits, with 16 combinations ).
// There are 4 rows with a 1 result. ... |
module top_module(
input a, b, sel,
output out );
assign out = (sel==1)?b:a;
endmodule |
module top_module(
input [99:0] a, b,
input sel,
output [99:0] out );
assign out = (sel)? b:a;
endmodule
|
module top_module(
input [15:0] a, b, c, d, e, f, g, h, i,
input [3:0] sel,
output [15:0] out );
always @(*) begin
case (sel)
4'd0: out = a;
4'd1: out = b;
4'd2: out = c;
4'd3: out = d;
4'd4: out = e;
4'd5: out = f;
... |
module top_module(
input [255:0] in,
input [7:0] sel,
output out );
assign out = in[sel];
endmodule
|
module top_module (
input [1023:0] in,
input [7:0] sel,
output [3:0] out
);
// We can't part-select multiple bits without an error, but we can select one bit at a time,
// four times, then concatenate them together.
assign out = {in[sel*4+3], in[sel*4+2], in[sel*4+1], in[sel*4+0]};
// Alternatively, "indexed v... |
module top_module(
input a, b,
output cout, sum );
assign cout = a&b;
assign sum = a^b;
endmodule
|
module top_module(
input a, b, cin,
output cout, sum );
assign cout = a&b | b&cin | a&cin;
assign sum = a^b^cin;
endmodule
|
module top_module(
input [2:0] a, b,
input cin,
output [2:0] cout,
output [2:0] sum );
FA FA1(a[0],b[0],cin,cout[0],sum[0]);
FA FA2(a[1],b[1],cout[0],cout[1],sum[1]);
FA FA3(a[2],b[2],cout[1],cout[2],sum[2]);
endmodule
module FA(
input a, b, cin,
output cout, sum );
as... |
module top_module (
input [3:0] x,
input [3:0] y,
output [4:0] sum
);
// This circuit is a 4-bit ripple-carry adder with carry-out.
assign sum = x+y; // Verilog addition automatically produces the carry-out bit.
// Verilog quirk: Even though the value of (x+y) includes the carry-out, (x+y) is still considered t... |
module top_module (
input [7:0] a,
input [7:0] b,
output [7:0] s,
output overflow
); //
wire [8:0] sum;
assign sum = a+b;
assign s = sum[7:0];
assign overflow = a[7]&&b[7]&&(~s[7]) || (~a[7])&&(~b[7])&&(s[7]);
endmodule
|
module top_module(
input [99:0] a, b,
input cin,
output cout,
output [99:0] sum );
assign {cout,sum} = a+b+cin;
endmodule
|
module top_module(
input [15:0] a, b,
input cin,
output cout,
output [15:0] sum );
wire c1,c2,c3;
bcd_fadd b1(a[3:0],b[3:0],cin,c1,sum[3:0]);
bcd_fadd b2(a[7:4],b[7:4],c1,c2,sum[7:4]);
bcd_fadd b3(a[11:8],b[11:8],c2,c3,sum[11:8]);
bcd_fadd b4(a[15:12],b[15:12],c3,cout,sum[15:12... |
module top_module(
input a,
input b,
input c,
output out );
assign out = (a | b | c);
endmodule
|
module top_module(
input a,
input b,
input c,
input d,
output out );
assign out = ~d&~a | ~c&~b | c&d&(a|b);
endmodule
|
module top_module(
input a,
input b,
input c,
input d,
output out );
assign out = a | ~b&c;
endmodule
|
module top_module(
input a,
input b,
input c,
input d,
output out );
assign out = a^b^c^d;
endmodule
|
module top_module (
input a,
input b,
input c,
input d,
output out_sop,
output out_pos
);
assign out_sop = (c&d)|(~a&~b&c);
assign out_pos = c&(~b|~c|d)&(~a|~c|d);
endmodule
|
module top_module (
input [4:1] x,
output f );
assign f = ~x[1]&x[3] | x[1]&x[2]&x[4];
endmodule
|
module top_module (
input [4:1] x,
output f
);
assign f = (~x[1]&x[3])|(~x[2]&~x[4])|(x[2]&x[3]&x[4]);
endmodule
|
module top_module (
input c,
input d,
output [3:0] mux_in
);
assign mux_in = (c&d)?4'b1001:(c)?4'b0101:(d)?4'b0001:4'b0100;
endmodule
|
module top_module(
input clk,
input d,
output reg q);
// Use non-blocking assignment for edge-triggered always blocks
always @(posedge clk)
q <= d;
// Undefined simulation behaviour can occur if there is more than one edge-triggered
// always block and blocking assignment is used. Which always block is simu... |
module top_module (
input clk,
input in,
output out);
always @(posedge clk) begin
out <= out^in;
end
endmodule
|
module top_module (
input clk,
input L,
input r_in,
input q_in,
output reg Q);
always @ (posedge clk) begin
case (L)
1'b0 : Q <= q_in;
1'b1 : Q <= r_in;
endcase
end
endmodule |
module top_module (
input clk,
input w, R, E, L,
output Q
);
wire [1:0] con = {E,L};
always @(posedge clk) begin
case(con)
2'b00: Q <= Q;
2'b01: Q <= R;
2'b11: Q <= R;
2'b10: Q <= w;
endcase
end
endmodule
|
module top_module (
input clk,
input x,
output z
);
reg q,q1,q2;
always @(posedge clk)
begin
q<= q^x;
q1<= ~q1 && x;
q2<= ~q2 || x;
end
assign z=~(q | q1 | q2);
endmodule |
module top_module (
input clk,
input j,
input k,
output Q);
always @ (posedge clk) begin
case ({j,k})
2'b00: Q <= Q;
2'b01: Q <= 1'b0;
2'b10: Q <= 1'b1;
2'b11: Q <= ~Q;
endcase
end
endmodule
|
module top_module(
input clk,
input [7:0] in,
output reg [7:0] pedge);
reg [7:0] d_last;
always @(posedge clk) begin
d_last <= in; // Remember the state of the previous cycle
pedge <= in & ~d_last; // A positive edge occurred if input was 0 and is now 1.
end
endmodule
|
module top_module (
input clk,
input [7:0] in,
output [7:0] anyedge
);
reg [7:0]dlast;
always @ (posedge clk) begin
dlast <= in;
anyedge <= dlast ^ in;
end
endmodule
|
module top_module (
input clk,
input reset,
input [31:0] in,
output [31:0] out
);
reg [31:0] d_last;
wire [31:0] state;
assign state = d_last & ~in;
always@( posedge clk) begin
d_last <= in;
if (reset) begin
out <= '0;
end
else begin
for... |
module top_module(
input clk,
input d,
output q);
reg p, n;
// A positive-edge triggered flip-flop
always @(posedge clk)
p <= d ^ n;
// A negative-edge triggered flip-flop
always @(negedge clk)
n <= d ^ p;
// Why does this work?
// After posedge clk, p changes... |
module top_module(
input clk,
input [7:0] d,
output reg [7:0] q);
// Because q is a vector, this creates multiple DFFs.
always @(posedge clk)
q <= d;
endmodule
|
module top_module (
input clk,
input reset, // Synchronous reset
input [7:0] d,
output [7:0] q
);
always @(posedge clk) begin
q <= (reset)?8'd0:d;
end
endmodule
|
module top_module (
input clk,
input reset,
input [7:0] d,
output [7:0] q
);
always @(negedge clk) begin
q <= (reset)? 8'h34:d;
end
endmodule
|
module top_module(
input clk,
input [7:0] d,
input areset,
output reg [7:0] q);
// The only difference in code compared to synchronous reset is in the sensitivity list.
always @(posedge clk, posedge areset)
if (areset)
q <= 0;
else
q <= d;
// In Verilog, the sensitivity list looks strange. The FF's... |
module top_module (
input clk,
input resetn,
input [1:0] byteena,
input [15:0] d,
output [15:0] q
);
always @(posedge clk) begin
case(byteena)
2'b01: q <= (~resetn)? 16'd0:{q[15:8],d[7:0]};
2'b10: q <= (~resetn)? 16'd0:{d[15:8],q[7:0]};
2'b11: q <= (~r... |
module top_module (
input d,
input ena,
output q);
always @ (*) begin
if (ena) q<=d;
end
endmodule
|
module top_module (
input clk,
input d,
input ar, // asynchronous reset
output q);
always @(posedge clk or posedge ar) begin
q <= (ar)? 0 : d;
end
endmodule
|
module top_module (
input clk,
input d,
input r, // synchronous reset
output q);
always @(posedge clk) begin
q <= (r)? 0:d;
end
endmodule
|
module top_module(
input clk,
input reset,
output reg [3:0] q);
always @(posedge clk)
if (reset)
q <= 0;
else
q <= q+1; // Because q is 4 bits, it rolls over from 15 -> 0.
// If you want a counter that counts a range different from 0 to (2^n)-1,
// then you need to add another rule to reset q to 0... |
module top_module(
input clk,
input reset,
output reg [3:0] q);
always @(posedge clk)
if (reset || q == 9) // Count to 10 requires rolling over 9->0 instead of the more natural 15->0
q <= 0;
else
q <= q+1;
endmodule
|
module top_module (
input clk,
input reset,
output [3:0] q);
always @(posedge clk) begin
if (reset || q == 4'd10)
q <= 4'd1;
else
q <= q + 1;
end
endmodule
|
module top_module (
input clk,
input slowena,
input reset,
output [3:0] q);
always @(posedge clk) begin
if (slowena) begin
if (q == 4'd9)
q<=0;
else
q<=q+1;
end
if(reset) begin
q<=0;
end
end
endmodule
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.