Docsity

Verilog Programming: Behavioral Modeling and 4-bit Full Adder Implementation, Slides of Digital Systems Design

Toggle sidebar
bg1
IMPLEMENTATION 2
module mux4_1 (in1, in2, in3, in4, s0, s1 out);
๎š„// Module 4-to-1 multiplexer using data flow modeling
๎š„// Port declarations from the I/O diagram
output out;
input in1, in2, in3, in4;
input s1, s0;
// data flow logic for 4:1 mux
assign out = s1 ? (s0 ? In4 : in3) : (s0 ? In2 : in1);
endmodule
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Verilog Programming: Behavioral Modeling and 4-bit Full Adder Implementation and more Slides Digital Systems Design in PDF only on Docsity!

IMPLEMENTATION 2^ module mux4_1 (in1, in2, in3, in4, s0, s1 out);^ ย„^ // Module 4-to-1 multiplexer using data flow modeling^ ย„^ // Port declarations from the I/O diagram^ output out;^ input in1, in2, in3, in4;^ input s1, s0;^ // data flow logic for 4:1 mux^ assign out =

s1? (s0? In4 : in3) : (s0? In2 : in1); endmodule

4-bit Full Adder, Using Dataflow Operators^ // Define a 4-bit full adder by using dataflowstatements.^ module fulladd4(sum, c_out, a, b, c_in);^ // I/O port declarations^ output [3:0] sum;^ output c_out;^ input[3:0] a, b;^ input c_in;^ // Specify the function of a full adder^ assign {c_out, sum} = a + b + c_in;^ endmodule

Behavioral ModelingBehavioral Modeling

Behavioral Modeling! ย„^ Verilog provides designers the ability to describedesign functionality in an algorithmic manner. ย„^ The designer describes the behavior of the circuit. ย„^ Behavioral modeling represents the circuit at a veryhigh level of abstraction. ย„^ In behavioral modeling, everything comes in aprocedural block ย„^ Behavioral Verilog constructs are similar to C languageconstructs

Procedural Blocks

Procedural^ Blocks ย„^ There are two structured procedurestatements in Verilog: always andinitial

initial Block^

always^ Block

Behavioral Block /P=wire/reg

O/P=reg

I

initial Block ย„^ All statements inside an initial statement constitutean initial block. ย„^ An initial block starts at time 0, executes exactlyonce during a simulation, and then does notexecute again. ย„^ If there are multiple initial blocks, each block startsto execute concurrently at time 0. ย„^ Each block finishes execution independently ofother blocks. ย„^ Multiple behavioral statements must be grouped,typically using the keywords begin and end.

initial Statement module stimulus; reg x,y, a,b, m; //single statement; does not need to be grouped initial m = 1'b0; //multiple statements; need to be grouped initial begin #5 a = 1'b1; #25 b = 1'b0; end initial begin #10 x = 1'b0; #25 y = 1'b1; end initial #50 $finish; endmodule

initial Block

module stimulus; reg x,y, a, b, c; initial begin^ c=1โ€™b0;^ #5^ a=1โ€™b1;^ #25 b=1โ€™b0; end initial begin^ #10 x=1โ€™b0;^ #25 y=1โ€™b1; end initial^ #50 $finish; endmodule

initial Block starts at time 0,executes only once during asimulation Multiple statements must be groupedusing the keywords begin and end.Incase^ of^ a^

single^ behavioral statement, grouping is not necessary.

initial Block

module stimulus; reg x,y, a, b, c; initial Begin^ c = 1โ€™b0;^ #5^ a=1โ€™b1;^ #25 b=1โ€™b0; end initial begin^ #10 x=1โ€™b0;^ #25 y=1โ€™b1; end initial^ #50 $finish; endmodule

Here we have three initial blockswhere each block starts to execute inparallel at time 0.Each^ Block^ finishes

its^ execution independent of each other.

always Block ย„^ All behavioral statements inside an alwaysstatement constitute an always block. ย„^ The always statement starts at time 0 andexecutes the statements in the always blockcontinuously in a looping fashion. ย„^ This statement is used to model a block ofactivity that is repeated continuously in adigital circuit.

always Statement module clock_gen (output reg clock); //Initialize clock at time zero initial clock = 1'b0; //Toggle clock every half-cycle (time period = 20) always #10 clock = ~clock; initial #1000 $finish; endmodule

Procedural assignments^ ย„^ Procedural assignments update values ofreg, integer, real, or time variables^ ย„^ assignment ::= variable_lvalue = [delay_or_event_control ] expression^ ย„^ The left-hand side of a proceduralassignment can be one of thefollowing:^ ย„^ A reg, integer, real, or time register variable ora memory element^ ย„^ A bit select of these variables (e.g., addr[0])^ ย„^ A part select of these variables (e.g.,addr[31:16])^ ย„^ A concatenation of any of the above

Procedural assignments ย„^ Blocking assignment =^ ย„^ Blocking assignment statements are executed inthe order they are specified in a sequentialblock^ ย„^ Regular assignment inside procedural block^ ย„^ Assignment takes place immediately^ ย„^ LHS must be a register