Last active
November 14, 2016 15:20
-
-
Save maservant/b8a84db68f65574b9e79fed4da4465f4 to your computer and use it in GitHub Desktop.
Exercice en classe pour calcul du plus grand commun diviseur
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library IEEE; | |
use IEEE.std_logic_1164.all; | |
use IEEE.numeric_std.all; | |
entity gcd is | |
port( | |
Ai, Bi : in unsigned(15 downto 0); | |
init, clk : in std_logic; | |
F : out unsigned(15 downto 0); | |
fini : out std_logic | |
); | |
end gcd; | |
architecture arch1 of gcd is | |
signal A, B, AmoinsB, BmoinsA : unsigned(15 downto 0); | |
begin | |
AmoinsB <= A - B; | |
BmoinsA <= B - A; | |
F <= A; | |
process(clk) | |
begin | |
if rising_edge(clk) then | |
if init = '1' then | |
A <= Ai; | |
B <= Bi; | |
fini <= '0'; | |
elsif A = B then | |
fini <= '1'; | |
elsif AmoinsB(15) = '1' then -- A < B, mais gratuit. | |
B <= BmoinsA; | |
fini <= '0'; | |
else | |
A <= AmoinsB; | |
fini <= '0'; | |
end if; | |
end if; | |
end process; | |
end arch1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment