

































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Verilog design examples for writing synthesizable code and implementing a Greatest Common Divisor (GCD) function. It covers guidelines for synthesizable Verilog, parameterized models, and explicit state representation. The document also includes examples of datapath design and control logic for a GCD implementation.
Typology: Lecture notes
1 / 41
This page cannot be seen from the preview
Don't miss anything!


































! Use always @(posedge clk) and non- blocking assignments (<=) always @( posedge clk ) C_out <= C_in; ! Use only positive-edge triggered flip-flops for state ! Do not assign the same variable from more than one always block – ill defined semantics ! Do not mix blocking and non-blocking assignments ! Only leaf modules should have functionality; use higher-level modules only for wiring together sub-modules
wire A_in, B_in, C_in; reg A_out, B_out, C_out; always @( posedge clk ) begin A_out <= A_in; B_out <= A_out + 1; C_out <= B_out + 1; end
A
B C
wire A_in, B_in, C_in; reg A_out, B_out, C_out; always @( posedge clk ) begin A_out <= A_in; B_out <= B_in; C_out <= C_in; assign B_in = A_out + 1; assign C_in = B_out + 1; end
A
B C
wire A_in, B_in, C_in; reg A_out, B_out, C_out; always @( posedge clk ) A_out <= A_in; assign B_in = A_out + 1; always @( posedge clk ) B_out <= B_in; assign C_in = B_out + 1; always @( posedge clk ) C_out <= C_in;
A
B C
L03-
!"#$%&'()+,-$+.+/0)1/&+$%2)/,"34+5() "$6"#()789:) ));/2+3) )))));))))<).8":) )))))5))))<)0)=)>?) )/30) @AB@AC@) DCEFG) "((+23)0)<);=B?) "((+23)/)<)5=B?) "$6"#()) ))78-%(/02/)5$H:) ));/2+3) ))))))")I<)
))/30) "$6"#()) ))78-%(/02/)5$H:) ));/2+3) ))))))K)I<)
))/30) "$6"#()) ))78-%(/02/)5$H:) ));/2+3) ))))))))I<).%%?)
))/30) "$6"#()) ))78-%(/02/)5$H:) ));/2+3) )))))).%%)<)K?)
))/30)
If you treat verilog as a language for coding up hardware you have already designed on paper/whiteboard, you will not need to rely on this. (combinational) (sequential left hand side) (sequential right hand side)
L03-
int GCD( int inA, int inB) { int done = 0; int A = inA; int B = inB; while ( !done ) { if ( A < B ) { swap = A; A = B; B = swap; } else if ( B != 0 ) A = A - B; else done = 1; } return A; }
idle input_available operand_A operand_B result_data result_taken result_rdy clk reset
Step 2: Design a datapath which has the functional units B A = inA; B = inB; while ( !done ) begin if ( A < B ) swap = A; A = B; B = swap; else if (B != 0) A = A - B; else done = 1; End Y = A; zero? lt A sub
module GCDdatapath#( parameter W = 16 ) ( input clk, // Data signals input [W-1:0] operand_A, input [W-1:0] operand_B, output [W-1:0] result_data, // Control signals (ctrl->dpath) input A_en, input B_en, input [1:0] A_sel, input B_sel, // Control signals (dpath->ctrl) output B_zero, output A_lt_B ); B A sel A en B sel B en B = 0 A < B zero? lt A sub
wire [W-1:0] B; wire [W-1:0] sub_out; wire [W-1:0] A_out; vcMux3#(W) A_mux ( .in0 (operand_A), .in1 (B), .in2 (sub_out), .sel (A_sel), .out (A_out) ); wire [W-1:0] A; vcEDFF_pf#(W) A_pf ( .clk (clk), .en_p (A_en), .d_p (A_out), .q_np (A) ); B A sel A en B sel B en B = 0 A < B zero? lt A sub