发新话题
打印

子函数 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));却发生错误,大家谈谈怎么设计这个子函数,才能使其有通用性呢?
做永远的初学者,欢迎大家指点

TOP

谢谢了!!!

TOP

我有个函数包中定义了
        -- signed_add,结果做截位处理,位数没有扩张
        function signed_add (a,b:std_logic_vector) return std_logic_vector is
            variable a_ext,b_ext  :std_logic_vector((a'high+1) downto 0);
            variable sum          :std_logic_vector((a'high+1) downto 0);
        begin
                a_ext <= a(a'high)& a;  b_ext <= b(a'high) & b; -- 符号扩展
            sum <= a_ext + b_ext;
                return sum((a'high+1) downto 1);
        end function;
编译通过了,
然后令一个文件中的代码调用这个函数使用:Y(2*widthDAT-1 downto widthDAT) <= signed_add(xich,xqsh);
其中定义了 signal xich,xqsh,xqch,xish:std_logic_vector(widthDAT-1 downto 0);
而 Y 是端口信号:Y ut std_logic_vector(2*widthDAT-1 downto 0);
编译时出现下面的错误:
Error (10527): VHDL Variable Assignment Statement error at mypackage.vhd(24): Variable Assignment Statement must use := to assign value to variable "a_ext" 谁知道这个错误为什么吗 ??谢谢
做永远的初学者,欢迎大家指点

TOP

提示: 作者被禁止或删除 内容自动屏蔽

TOP

提高通用性的方法想法挺好,但你用signed_add (a(WORD_WIDTH-2 downto WORD_WIDTH/2-1),b(WORD_WIDTH-2 downto WORD_WIDTH/2-1))的时候,传进去的A'high是什么呢,会不会变呢?

TOP

好深奥啊!~呵呵

TOP

发新话题