0
我使用展台乘法器算法分别乘以包含在寄存器A和B中的以下数字:308和165.结果存储在zlo和zhi中,其中zlo是低32位,zhi是高32位。以下是VHDL代码:展位乘法器在64位寄存器的高32位中放置1
variable M : std_logic_vector(64 downto 0);
variable S : std_logic_vector(64 downto 0);
variable P : std_logic_vector(64 downto 0);
-- Input A is in most significant bits of M
M(64 downto 33) := A(31 downto 0);
M(32 downto 0) := B"00000000_00000000_00000000_00000000_0";
-- -Input A is in most significant bits of S
S(64 downto 33) := std_logic_vector(NOT signed(A) + 1);
S(32 downto 0) := B"00000000_00000000_00000000_00000000_0";
-- P contains the product
P(64 downto 33) := B"00000000_00000000_00000000_00000000";
P(32 downto 1) := B(31 downto 0);
P(0) := '0';
-- check the last two bits and perform appropriate operation and shift
for i in 0 to 31 loop
if P(1 downto 0) = "01" then
P(64 downto 0) := std_logic_vector(signed(P) + signed(M));
elsif P(1 downto 0) = "10" then
P(64 downto 0) := std_logic_vector(signed(P) + signed(S));
end if;
P := std_logic_vector(signed(P) srl 1);
end loop;
zhi <= P(64 downto 33);
zlo <= P(32 downto 1);
ModelSim中波形的结果如下所示。正如你所看到的,308被装载到公共汽车上,然后是165.结果,50820然后被存储在总线(zlo)上,然后1被存储在总线(zhi)上。为什么有1? 50820不会进入高32位。