vhdl编写的移位相加型乘法器 modelsim仿真与预期不符。自己找不出问题,希望得到大家指点
原代码
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
ENTITY mul_1 IS
GENERIC(s:INTEGER :=4);
PORT (a,b:IN STD_LOGIC_VECTOR(s DOWNTO 1);
y:OUT STD_LOGIC_VECTOR(2*s DOWNTO 1)
);
END ENTITY;
ARCHITECTURE yiwei OF mul_1 IS
SIGNAL a0:STD_LOGIC_VECTOR(2*s DOWNTO 1);
BEGIN
a0<=CONV_STD_LOGIC_VECTOR(0,s)&a;---cov_std_logic_vector将0转换为s位的STD_LOGIC_VECTOR,该语句为将a高四位补零,补成8位数组
PROCESS(a,b) IS
VARIABLE r1:STD_LOGIC_VECTOR(2*s DOWNTO 1);
BEGIN
r1:=(OTHERS=>'0');
FOR i IN 1 TO s LOOP
IF (b(i)='1') THEN
r1:=r1+TO_STDLOGICVECTOR(TO_BITVECTOR (a0) SLL (i-1));--to_stdlogicvector、to_BITVECTOR在unsigned库中,
END IF;
END LOOP;
y<=r1;
END PROCESS;
END ARCHITECTURE;
仿真结果
希望大佬解惑
|