SystemVerilog adds the concept of global scope. Any declarations and definitions which is declared outside a module, interface, task, or function, is global in scope. Global variables have a static lifetime (exists for the whole elaboration and simulation time). Datatypes, tasks,functions, class definitions can be in global scope. Global members can be referenced explicitly via the $root . All these can be accessed from any scope as this is the highest scope and any other scope will be below the global.
Local declarations and definitions are accessible at the scope where they are defined and below. By default they are static in life time. They can be made to automatic. To access these local variables which are static, hierarchical pathname should be used.
int st0; //Static. Global Variable. Declared outside module
task disp(); //Static. Global Task.
int st0; //static. Local to module
initialbegin int st1; //static. Local to module
staticint st2; //static. Local to Module
automaticint auto1; //automatic.
taskautomatic t1(); //Local task definition.
int auto2; //automatic. Local to task
staticint st3; //static.Local to task. Hierarchical path access allowed
automaticint auto3; //automatic. Local to task
$root.st0 = st0; //$root.sto is global variable, st0 is local to module.
The Verilog assign statement is a unidirectional assignment. To model a bidirectional short-circuit connection it is necessary to use the alias statement.
This example strips out the least and most significant bytes from a four byte bus:
module byte_rip (inoutwire [31:0] W, inoutwire [7:0] LSB, MSB);
alias W[7:0] = LSB;
alias W[31:24] = MSB;
Data Types On Ports:
Verilog restricts the data types that can be connected to module ports. Only net types are allowed on the receiving side and Nets, regs or integers on the driving side. SystemVerilog removes all restrictions on port connections. Any data type can be used on either side of the port. Real numbers, Arrays, Structures can also be passed through ports.
Parameterized Data Types:
Verilog allowed only values to be parameterized. SystemVerilog allows data types to be "parameterized". A data-type parameter can only be set to a data-type.
module foo #(parametertype VAR_TYPE = integer);
foo #(.VAR_TYPE(byte)) bar ();
Declaration And Initialization:
integer i = 1;
In Verilog, an initialization value specified as part of the declaration is executed as if the assignment were made from an initial block, after simulation has started. This creates an event at time 0 and it is same as if the assiginment is done in initial block. In Systemverilog , setting the initial value of a static variable as part of the variable declaration is done before initial block and so does not generate an event.