reading a bookModule


The module is the basic unit of hierarchy in Verilog. Modules contain declarations and functional decriptions and represent hardware components.

Syntax ( Key to Notation )

{either}

module ModuleName [(Port,...)];
  ModuleItem...
endmodule

macromodule ModuleName [(Port,...)];
  ModuleItem...
endmodule

ModuleItem = {either}
  Declaration
  Defparam
  Continuous Assignment
  Instance
  Specify
  Initial
  Always

Where

Modules are declared outside any other modules or primitives.

Rules

Gotchas!

The same keyword, endmodule, is used at the end of both modules and macromodules.

Synthesis

Tips

Have only one module declaration per file. This eases source code maintenance for a large design.

Example

macromodule nand2 (f, a, b);
  output f;
  input a, b;

  nand (f, a, b);
endmodule


module PYTHAGORAS (X, Y, Z);
  input  [63:0] X, Y;
  output [63:0] Z;

  parameter Epsilon = 1.0E-6;
  real RX, RY, X2Y2, A, B;

  always @(X or Y)
  begin
    RX = $bitstoreal(X);
    RY = $bitstoreal(Y);
    X2Y2 = (RX * RX) + (RY * RY);
    B = X2Y2;
    A = 0.0;
    while ((A - B) > Epsilon || (A - B) < -Epsilon)
    begin
      A = B;
      B = (A + X2Y2 / A) / 2.0;
    end
  end
  assign Z = $realtobits(A);
endmodule

See Also

Primitive, Instantiation


reference cardVerilog Quick Reference
teaching pointerDoulos Training Courses
reading a bookBack to the Verilog Golden Reference Guide


river sceneDoulos Home Page

Copyright 1995-1997 Doulos
This page was last updated 16th July 1996

mail iconWe welcome your e-mail comments. Please contact us at: webmaster@doulos.co.uk