240 likes | 348 Views
Entity declaration describes the input/output ports of a module. port mode (direction). entity name. Port Name. entity reg4 is port ( d0, d1, d2, d3, en, clk : in std_logic; q0, q1, q2, q3 : out std_logic ); end entity reg4;. punctuation. port type. reserved words.
E N D
Entity declaration • describes the input/output ports of a module port mode (direction) entity name Port Name entity reg4 isport ( d0, d1, d2, d3, en, clk : in std_logic; q0, q1, q2, q3 : out std_logic );end entity reg4; punctuation port type reserved words DSD,USIT,GGSIPU
Modeling Behavior • Architecture body • describes an implementation of an entity • may be several per entity • Behavioral architecture • describes the algorithm performed by the module • contains • process statements, • Function • Statement1 • Port interface DSD,USIT,GGSIPU
Modeling Structure • Structural architecture • implements the module as a composition of subsystems • contains • signal declarations, for internal interconnections • the entity ports are also treated as signals • component declarations • instances of previously declared entity/architecture pairs • port maps in component instances • connect signals to component ports DSD,USIT,GGSIPU
Component Declaration ComponentComponent-name [is] [port (list-of-interface-port);] End component [component-name]; Component-name: may or may not refer to the name of an entity already existing in a library. DSD,USIT,GGSIPU
Component cont.. • List-of-interface-port specifies the name,mode, and type for each port of the component in a manner similar to that specified in an entity declaration. • The names of the ports may also be different from the names of the ports in the entity to which it may be bound. DSD,USIT,GGSIPU
Component declaration • Component declaration appear in the declaration part of an architecture body. • They may also appear in a package declaration DSD,USIT,GGSIPU
Signal declaration • Are required to connect different types of ports.(mode of ports) • Class of the object identifier • Signal object should be same data type as it is in component and entity. • Signal object can be also be declared as an array DSD,USIT,GGSIPU
Component Instantiation • A Component instantiation statement defines a subcomponent of the entity in which it appears. • It associates the signals in the entity with the ports of that subcomponent. DSD,USIT,GGSIPU
Format of a component Instantiation statement Component-label : component-name [port map (association-list)]; * Component-label: It can be any legal identifier and can be considered as the name of the instance. DSD,USIT,GGSIPU
Component instantiation • The component-name must be the name of a component declared earlier using a component declaration. • The association-list associates signals in the entity, called actuals, with the ports of a component, called formals. DSD,USIT,GGSIPU
Association technique • There are two ways to perform the association of formals with actuals: 1. Positional association 2. Named association DSD,USIT,GGSIPU
Positional association • An association-list is of the form: Actual1,actual2,actual3…………………………actualn The first port in the component declaration corresponds to the first actual in the component declaration corresponds to the first actual in the component instantiation, the second with second, and so on. DSD,USIT,GGSIPU
Named association • An association-list is of the form: Formal1=>actual1,formal2=>actual2……..formaln=>actualn In named association, the ordering of the association is not important since the mapping between the actuals and formals is explicitly specified. The scope of the formals is restricted to be within the port map part of the instantiation for that component. DSD,USIT,GGSIPU
Rules of the port map • The types of the formal and actual being associated must be the same. • The modes of the ports must conform to the rule that if the formal s readable, so must the actual be; and if the formal is considered to be both readable and writeable, such a signal may be associated with a formal of any mode. DSD,USIT,GGSIPU
If an actual is a port of mode in, it may not be associated with a formal of mode out or inout; • if the actuals is a port of mode out, it may not be associated with a formal of mode in or inout; • if the actual is a port of mode inout, it may be associated with a formal of mode in,out, or inout. DSD,USIT,GGSIPU
Circuit of Half adder DSD,USIT,GGSIPU
Circuit of Full adder DSD,USIT,GGSIPU
Design a 4-bit adder using FA DSD,USIT,GGSIPU
Example (Full adder using macro of Half adder) library ieee; use ieee.std_logic_1164.all; entity ha is port ( x, y : in std_logic; s, c : out std_logic ); end ha; architecture ha_behave of ha is begin s <= x xor y; c <= x and y; end ha_behave; DSD,USIT,GGSIPU
library ieee; use ieee.std_logic_1164.all; entity fa is port ( xin, yin, zin : in std_logic; cout, sum : out std_logic ); end fa; architecture fa_struct of fa is component ha is port ( x, y : in std_logic; s, c : out std_logic ); end component ha; signal temp0,temp1,temp2 : std_logic; begin ha1 : ha port map (x=>xin,y=>yin,s=>temp0,c=>temp1); ha2 : ha port map (x=>temp0,y=>zin,s=>sum,c=>temp2); cout <= temp1 or temp2; end fa_struct; DSD,USIT,GGSIPU
library ieee;use ieee.std_logic_1164.all;entity fa_4bit isport ( a,b : in std_logic_vector (3 downto 0); sum : out std_logic_vector (3 downto 0); carry : out std_logic );end fa_4bit;architecture fa_4bit_behave of fa_4bit is component fa is port ( xin, yin, zin : in std_logic; cout, sum : out std_logic ); end component fa; signal c : std_logic_vector (3 downto 0);begin c(0) <= '1'; DSD,USIT,GGSIPU
u1 : fa port map (xin=>a(0),yin=>b(0),zin=>c(0),sum=>sum(0),cout=>c(1));u2 : fa port map (xin=>a(1),yin=>b(1),zin=>c(1),sum=>sum(1),cout=>c(2));u3 : fa port map (xin=>a(2),yin=>b(2),zin=>c(2),sum=>sum(2),cout=>c(3));u4 : fa port map (xin=>a(3),yin=>b(3),zin=>c(3),sum=>sum(3),cout=>carry);end fa_4bit_behave; DSD,USIT,GGSIPU
Adder-Subtractor using Mode control DSD,USIT,GGSIPU