首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

子函数 fuction 的使用方法

子函数 fuction 的使用方法

function signed_sub (a,b:std_logic_vector) return std_logic_vector is

        variable a_ext,b_ext  :std_logic_vector((a'high+1) downto 0);
        variable diff         :std_logic_vector((a'high+1) downto 0);
    begin
        a_ext <= a(a'high)& a;  b_ext <= b(a'high) & b; -- 符号扩展
        diff <= a_ext - b_ext;
        return diff((a'high+1) downto 1);
    end function;
上面对于 一个信号
signal a,b  :std_logic_vector((a'high+1) downto 0);
调用 sum<=signed_add (a,b);是正确的
但是在对于 截位后的 a,b 信号,使用
sum<=signed_add (a(WORD_WIDTH-2 downto WORD_WIDTH/2-1),b(WORD_WIDTH-2 downto WORD_WIDTH/2-1));却发生错误,大家谈谈怎么设计这个子函数,才能使其有通用性呢?
搞不懂,关注一个!
想看更多的东西?来我的博客,精彩多多! http://blog.eccn.com/u/bjxiong/index.htm

“sum<=signed_add (a(WORD_WIDTH-2 downto WORD_WIDTH/2-1),b(WORD_WIDTH-2 downto WORD_WIDTH/2-1));却发生错误,大家谈谈怎么设计这个子函数,才能使其有通用性呢?”

你的这个函数是有通用性的,只是你的使用方法不对。

你看看提示的什么错误就可以知道了,结果的位数要匹配。

这个版主不太冷 =========================== 我的中电网博客:http://blog.chinaecnet.com/u/20/index.htm
返回列表