









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










HDL Based Digital Design using Verilog By M. Mohsin Rahmatullah @ SS-CARE School of Engineering
module mux4_1(in1, in2, in3, in4, sel, out); input [1:0] sel; input [15:0] in1, in2, in3, in3; output [15:0] out; reg [15:0] out; always @(in1 or in2 or in3 or in4 or sel) case (sel) 2'b00: out = in1; 2'b01: out = in2; 2'b10: out = in3; 2'b11: out = in4; default: out = 16'bx;
HDL Based Digital Design using Verilog By M. Mohsin Rahmatullah @ SS-CARE School of Engineering
There are four types of looping statements in Verilog: while, for,repeat, and forever repeat while for forever forever @(posedgeforever @( posedge clock) x = y; clock) x = y;
Sequential Blocks The keywords begin and end are used to group statements intosequential blocks. The statements in a sequential block are processed in the orderthey are specified //Illustration 1: Sequential block without delay reg x, y; reg [1:0] z, w; initial begin x = 1'b0; y = 1'b1; z = {x, y}; w = {y, x}; end //Illustration 2: Sequential blocks with delay reg x, y; reg [1:0] z, w; initial begin x = 1'b0; //completes at simulation time 0 #5 y = 1'b1; //completes at simulation time 5 #10 z = {x, y}; //completes at simulation time 15 #20 w = {y, x}; //completes at simulation time 35 end
Verilog provides tasks and functions to break uplarge behavioral designs into smaller pieces. Tasks and functions allow the designer to abstractVerilog code that is used at many places in thedesign Tasks have input, output, and inout arguments;functions have input arguments Both tasks and functions must be defined in amodule and are local to the module Tasks are used for common Verilog code thatcontains delays, timing, event constructs, ormultiple output arguments Functions are used when common Verilog code ispurely combinational, executes in zero simulationtime, and provides exactly one output