《第八讲子程序》-精选课件(公开PPT)

上传人:zhuma****mei2 文档编号:136073027 上传时间:2020-06-23 格式:PPT 页数:21 大小:291KB
返回 下载 相关 举报
《第八讲子程序》-精选课件(公开PPT)_第1页
第1页 / 共21页
《第八讲子程序》-精选课件(公开PPT)_第2页
第2页 / 共21页
《第八讲子程序》-精选课件(公开PPT)_第3页
第3页 / 共21页
《第八讲子程序》-精选课件(公开PPT)_第4页
第4页 / 共21页
《第八讲子程序》-精选课件(公开PPT)_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《《第八讲子程序》-精选课件(公开PPT)》由会员分享,可在线阅读,更多相关《《第八讲子程序》-精选课件(公开PPT)(21页珍藏版)》请在金锄头文库上搜索。

1、第八讲 VHDL硬件描述语言_6,教学课时:2学时 教学内容: 1、函数 2、过程 3、子程序重载,一、函数,函数分为函数头和函数体两部分。 函数头的格式为: FUNCTION 函数名(参数表) RETURN 数据类型 ; 函数体的格式为: FUNCTION 函数名(参数表) RETURN 数据类型 IS 声明部分 BEGIN 顺序语句; RETURN 返回变量名; END 函数名;,函数可以在程序包、结构体和进程中定义。,在程序包中定义的函数可以被其他不同的设计调用。此时,函数头必须放在程序包的说明部分,而函数体放在程序包的包体内。,如果只是在结构体中定义并调用函数,则仅需函数体即可。,例1

2、:设计一个电路,它有4个输入失量(3位二进制),要求输出为最大输入值。,设计思路一: (1)在程序包内定义一个求2个输入失量最大值的函数。函数体在包体内。 (2)新建一个实体,调用最大值函数,实现电路要求。,library ieee; use ieee.std_logic_1164.all; package mypkg is function max(a,b:in std_logic_vector) return std_logic_vector; end mypkg; package body mypkg is function max(a,b:in std_logic_vector) re

3、turn std_logic_vector is begin if (ab)then return a; else return b; end if; end max; end mypkg;,library ieee; use ieee.std_logic_1164.all; use work.mypkg.all; entity bijiaoqi is port(a,b,c,d:in std_logic_vector(2 downto 0); y:out std_logic_vector(2 downto 0); end entity; architecture one of bijiaoqi

4、 is begin process(a,b,c,d) variable q1,q2,q3:std_logic_vector(2 downto 0); begin q1:=max(a,b); q2:=max(q1,c); q3:=max(q2,d); yb then return a; else return b; end if; end max; begin process(a,b,c,d) variable q1,q2,q3:std_logic_vector(2 downto 0); begin q1:=max(a,b); q2:=max(q1,c); q3:=max(q2,d); yb t

5、hen return a; else return b; end if; end max; variable q1,q2,q3:std_logic_vector(2 downto 0); begin q1:=max(a,b); q2:=max(q1,c); q3:=max(q2,d); yb then y:=a; else y:=b; end if; end max; variable q1,q2,q3:std_logic_vector(2 downto 0); begin max(a,b,q1); max(q1,c,q2); max(q2,d,q3); yb then y=a; else y

6、b then return a; else return b; end if; end function max; function max(a,b:in integer) return integer is begin if ab then return a; else return b; end if; end function max; end packmax;,library ieee; use ieee.std_logic_1164.all; use work.packmax.all; entity expmax is port(a1,b1:in std_logic_vector(3

7、 downto 0); a2,b2:in bit_vector(4 downto 0); a3,b3:in integer range 0 to 15; c1:out std_logic_vector(3 downto 0); c2:out bit_vector(4 downto 0); c3:out integer range 0 to 15); end entity; architecture one of expmax is begin c1=max(a1,b1); c2=max(a2,b2); c3=16 then cout=1; c=sum-16; else cout=0; c=sum; end if; end add;-过程体,begin process(a,b,cin) begin add(a,b,cin,c,cout); -过程调用 end process; end one;,仿真波形图,

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号