LEC-14 - 14 Subprograms and Packages 4/25/2010 © Copyright...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 14 Subprograms and Packages 4/25/2010 © Copyright 2003, 2006 Kenneth L. Short 1 4/25/2010 © Copyright 2003, 2006 Kenneth L. Short 1 Subprograms and Packages Prof. Ken Short 4/25/2010 © Copyright 2003, 2006 Kenneth L. Short 2 Subprograms ¡ VHDL subprograms are similar to subprograms in conventional programming languages ¡ A subprogram is an encapsulated sequence of sequential statements that define an algorithm. The algorithm uses the values of input parameters, passed to the subprogram when it is called, to compute a value or cause some desired effect. ¡ The actual code for a subprogram appears only once in a description’s text. However, the subprogram can be executed, by calling it, from any number of places in the description. ¡ Unlike subprograms in conventional programming languages, VHDL subprograms can also be executed as concurrent statements 14 Subprograms and Packages 4/25/2010 © Copyright 2003, 2006 Kenneth L. Short 2 4/25/2010 © Copyright 2003, 2006 Kenneth L. Short 3 Packages ¡ Commonly used subprograms for type conversion, resolution of multiply driven signals, and overloading operators are usually placed in packages so that they can be easily reused in other designs. ¡ Packages may also contain definitions of constants and additional data types. ¡ Packages are typically placed in libraries. For example, we have previously used data types and subprograms provided in packages in the IEEE library. 4/25/2010 © Copyright 2003, 2006 Kenneth L. Short 4 Functions ¡ VHDL provides two forms of subprograms, functions and procedures. ¡ A function computes and returns a single value. This value is computed using the values of parameters passed to the function when it is called. ¡ A function is called from an expression. The value returned by a function is used in the expression. ¡ A function can be used in an expression that is part of either a sequential or concurrent statement. However, all statements within a function are sequential. 14 Subprograms and Packages 4/25/2010 © Copyright 2003, 2006 Kenneth L. Short 3 4/25/2010 © Copyright 2003, 2006 Kenneth L. Short 5 Procedures ¡ A procedure can return one or more values, or may return no values and be used only for its effect. ¡ A procedure is called from a procedure statement. ¡ A procedure statement can appear in an architecture body as a concurrent statement. Or, it can appear in a process or another subprogram as a sequential statement. ¡ All statements in a procedure are sequential. 4/25/2010 © Copyright 2003, 2006 Kenneth L. Short 6 Function and Procedure Called in Concurrent Statements d clk u1 u2 u3 u5 u4 q q_bar s1 s3 s2 s5 s4 14 Subprograms and Packages 4/25/2010 © Copyright 2003, 2006 Kenneth L. Short 4 4/25/2010 © Copyright 2003, 2006 Kenneth L. Short 7 D Latch from NAND Gates ¡ The D latch description has each NAND component implemented in a different way: ¢ u1: concurrent signal assignment statement (nand_2csa) ¢ u2: component instantiation statement (nand_2c)...
View Full Document

This note was uploaded on 08/30/2010 for the course ESE 382 taught by Professor Short during the Spring '10 term at SUNY Stony Brook.

Page1 / 18

LEC-14 - 14 Subprograms and Packages 4/25/2010 © Copyright...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online