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位。