Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Subprograms and Packages - Computer Science - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Computer Science which includes Bit Adder, Code, Vector, Bcdcarryout, Architecture Behavioral, Component, Signal, Waveform, Logic etc. Key important points are: Subprograms and Packages, Primary Purpose, Encapsulate Elements, Common Storage, Declaring Data, Package Declaration Section, Package Body, Subprogram Declaration, Subtype Declaration, Component Declaration

Typology: Slides

2012/2013

Uploaded on 03/23/2013

dhruv
dhruv 🇮🇳

4.3

(12)

203 documents

1 / 29

Toggle sidebar

Related documents


Partial preview of the text

Download Subprograms and Packages - Computer Science - Lecture Slides and more Slides Computer Science in PDF only on Docsity! Packages • The primary purpose of a package is to encapsulate elements that can be shred (globally) among two or more design units. • A package is a common storage area used to hold data to be shared among a number of entities • Declaring data inside of a package allows the data to be referenced by other entities; thus data can be shared. Docsity.com Package (cont..) • A package consists of two parts: – A package declaration section – A package body Docsity.com Package body • The package body can also contain the following declaration: – Subprogram declaration/body – Type, subtype declaration – Constant declaration – File declaration – Alias declaration – Use clause Docsity.com Package body (example) Package body cluspack is constant undriven : t_wclus:= (zx,zx); function resolve_cluster (s: t_clus_vec) return t_cluster is variable result : t_cluster; variable drive_const: integer; begin if s’length = 0 then return undriven end if; Docsity.com (cont..) For I in s’range loop if s(I) /= undriven then drive_count := drive_count + 1; if drive_count = 1 then result := a (I); else result : = undriven end if; End loop Return result; -- return value End resolve_cluster; -- end function End cluspack; -- end package Docsity.com Procedure and Function • A procedure can return more than one argument. • A procedure can have input parameters, output parameters and inout parameters • A function always returns just one. • All parameters are input parameters • E.g. data type conversions, logical operations, arithmetic computations, new operator and attributes • Signal declaration and component instantiation is not allowed. Docsity.com Function syntax • To construct and use of a function, two parts are necessary: – The function body and – A call to the function Docsity.com Function body FUNCTION function_name [<parameter list>] RETURN data_type is [declaration] Begin [sequential statements] END function_name; Docsity.com Function call • A function is called as par of an expression. The expression can obviously appear by itself or associated to a statement (either concurrent or sequential). • Example of function calls: X <= conv_integer (a); -- converts a to an integer Y <= maximum (a,b); --returns the largest of a and b; If x > maximum (a,b); --compares x to the largest of a,b Docsity.com Function Location Function/Procedure location Package Main code (+Package body) Architecture Entity Library Docsity.com Function Use library ieee; Use ieee.std_logic_1164.all; package num_type is type log8 is array (0 to 7) of std_logic; end num_type; Docsity.com Conversion Function • Conversion Function are used to convert an object of one type to another. • They are used in component instantiation statement to allow mapping of signals and ports of different types. Docsity.com Conversion function (example) Function conversion4val (s: fourval) return fourvalue is Begin case s is when x => return ‘x’; when L => return ‘0’; when H => return ‘1’ when z => return ‘z’; end case; End convert4val; Docsity.com Resolution Function • A resolution function is used to return the value of a signal when the signal is driven by multiple drivers. • A resolution function consists of a function that is called whenever one of the drivers for the signal has an event occur on it. • The resolution function is executed and returns a single value from all of the driver values; this value is the new value of the signal. Docsity.com Procedure body Procedure procedure_name [<parameter list>] is [declarations] Begin (sequential statements) End procedure_name; Docsity.com Procedure (example) • Procedure my_procedure( a : in std_logic; signal b,c : in std_logic; signal x : out std_logic_vector(7 downto 0); signal y : inout integer range 0 to 99) is Begin ------ End my_procedure; Docsity.com <parameter list> • <parameter list> = [CONSTANT] constant_name: mode type • <parameter list> = SIGNAL signal_name: mode type; or • <parameter list> = VARIABLE variable_name : mode type • A procedure can have any number of IN,OUT or INOUT parameters, Which can be SIGNALS, VARIABLES, or CONSTANTS. Docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved