首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | 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));却发生错误,大家谈谈怎么设计这个子函数,才能使其有通用性呢?
返回列表