Board logo

标题: 子函数 fuction 的使用方法 [打印本页]

作者: graduate    时间: 2007-11-4 01:37     标题: 子函数 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));却发生错误,大家谈谈怎么设计这个子函数,才能使其有通用性呢?

作者: bjxiong    时间: 2007-11-5 11:30

搞不懂,关注一个!
作者: caopengly    时间: 2007-11-5 11:51

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

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

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






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0