Algorisme de Booth: diferència entre les revisions

Contingut suprimit Contingut afegit
Línia 49:
entity BoothMult4 is port(
 
A: in std_logic_vector(3 downto 0);
 
B: in std_logic_vector(3 downto 0);
 
O: out std_logic_vector(7 downto 0)
 
);
end BoothMult4;
architecture boothMult4Arch of BoothMult4 is
begin
Algorisme: process(A, B) -- Cada cop que canvii o be A o be B
 
variable num: std_logic_vector(8 downto 0);
variable Y, Z: unsigned(3 downto 0);
variable i:integer;
begin
num := "000000000";
Y := unsigned(B);
num(4 downto 1) := A;
for i in 0 to 3 loop
if(num(1) = '1' and num(0) = '0') then
Z := unsigned(num(8 downto 5));
num(8 downto 5) := std_logic_vector(Z - Y);
elsif(num(1) = '0' and num(0) = '1') then
Z := unsigned(num(8 downto 5));
num(8 downto 5) := std_logic_vector(Z + Y);
end if;
Onum(7 downto 0) <:= num(8 downto 1);
end loop;
 
numO(7 downto 0) :<= num(8 downto 1);
 
end process; begin
num := "000000000";
Y := unsigned(B);
num(4 downto 1) := A;
for i in 0 to 3 loop
if(num(1) = '1' and num(0) = '0') then
Z := unsigned(num(8 downto 5));
num(8 downto 5) := std_logic_vector(Z - Y);
elsif(num(1) = '0' and num(0) = '1') then
Z := unsigned(num(8 downto 5));
num(8 downto 5) := std_logic_vector(Z + Y);
end if;
num(7 downto 0) := num(8 downto 1);
end loop;
O(7 downto 0) <= num(8 downto 1);
end process;
end boothMult4Arch;