SystemVerilog Program Blocks - What, Why and How

Previous: What are Programs? Next: Programs and assignments

OK, So How Do I Create a Program Block?

A program block, as we mentioned earlier, is enclosed within the keywords program and endprogram (similar to a module being defined within module and endmodule keywords.

Following is an example of a program module.

program my_prog ( input  clk
                , input  reset
                , input  [7:0] in_pkt
		, output [7:0] out_pkt
   initial begin 
      out_pkt = 8'h0;

A program module can be defined independently similar to a module and then instantiated within a module. Or, it can be defined within a module itself.

module my_mod(...);
   int i;
   program my_prog(...);
This later type of definition (within a module) is known as implicit definition. In such a case, both the program name and the instance names are identical (e.g., my_prog in the above example). Also, a module variable (such as the integer i above) will also be accessible from the program my_prog.

Hmmm, A Program Block Looks Very Similar to a Module...

A module and a program block carry many similarities.

  • Similar to a module, a program block may have zero or more inputs, outputs and inout ports.
  • A program block can contain zero or more initial blocks, cont assignments, generate and specparam statements, concurrent assertions and timunit declarations.
  • Type and data declarations, functions and tasks can be defined within a program block similar to what you can do in a module.
  • A hierarchy can contain any number of program blocks. These program blocks may interact throughtheir ports or may be isolated from one other. This is how modules work too in a design environment.

However, the similarities end there. Here are some of the differences.

  • A program block can not contain any always statement, UDP, module, interface or other program. Thus a program block is always a leaf level node in a hierarchy.
  • A program definition can occur within a module as we saw earlier. Obviously, a module can not be defined this way.
  • A program can call a task or function in modules or other programs. But a module can not call a task or function in a program.
However, the biggest difference between a program and a module is the way they handle variable assignments in procedural blocks. We will see in the next section this is where the utility of a program comes into effect.

Previous: What are Programs? Next: Programs and assignments


Verification Management
Join Verification Management Group

Shop Amazon - Contract Cell Phones & Service Plans

Book of the Month