Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.numeric_std.all;
- entity zad1 is
- port(
- A,B,C :in std_logic_vector (7 downto 0);
- S :out std_logic_vector (7 downto 0)
- );
- end entity;
- architecture data_flow of zad1 is
- signal sum_A : integer range 0 to 18;
- signal sum_B : integer range 0 to 18;
- signal sum_C : integer range 0 to 18;
- signal A_int : integer range 0 to 99;
- signal B_int : integer range 0 to 99;
- signal C_int : integer range 0 to 99;
- signal div : std_logic_vector (2 downto 0);
- begin
- process(A,B,C) is
- begin
- A_int <= to_integer(unsigned(A(7 downto 4)))*10 + to_integer(unsigned(A(3 downto 0)));
- B_int <= to_integer(unsigned(B(7 downto 4)))*10 + to_integer(unsigned(B(3 downto 0)));
- C_int <= to_integer(unsigned(C(7 downto 4)))*10 + to_integer(unsigned(C(3 downto 0)));
- sum_A <= to_integer(unsigned(A(7 downto 4))) + to_integer(unsigned(A(3 downto 0)));
- sum_B <= to_integer(unsigned(B(7 downto 4))) + to_integer(unsigned(B(3 downto 0)));
- sum_C <= to_integer(unsigned(C(7 downto 4))) + to_integer(unsigned(C(3 downto 0)));
- --Sprawdzanie warunku podzielności przez 3
- S<="00000000";
- case sum_A is
- when 3 | 6 | 9 | 12 | 15 | 18 =>
- div(2) <= '1';
- when others =>
- div(2) <= '0';
- end case;
- case sum_B is
- when 3 | 6 | 9 | 12 | 15 | 18 =>
- div(1) <= '1';
- when others =>
- div(1) <= '0';
- end case;
- case sum_C is
- when 3 | 6 | 9 | 12 | 15 | 18 =>
- div(0) <= '1';
- when others =>
- div(0) <= '0';
- end case;
- --Sprawdzanie która z liczb jest największa
- case div is
- when "000" =>
- S <= "00000000";
- when "001" =>
- S <= C;
- when "010" =>
- S <= B;
- when "011" =>
- if B_int>=C_int then
- S <= B;
- else
- S <= C;
- end if;
- when "100" =>
- S <= A;
- when "101" =>
- if A_int>=C_int then
- S <= A;
- else
- S <= C;
- end if;
- when "110" =>
- if A_int>=B_int then
- S <= A;
- else
- S <= B;
- end if;
- when "111" =>
- if A_int>=B_int then
- if C_int>=A_int then
- S <= C;
- elsif A_int>=C_int then
- S <= A;
- end if;
- elsif B_int>=A_int then
- if B_int>=C_int then
- S <= B;
- elsif C_int>=B_int then
- S <= C;
- end if;
- elsif C_int>=B_int then
- if C_int>=A_int then
- S <= C;
- elsif A_int>=C_int then
- S <= A;
- end if;
- else
- S <= C;
- end if;
- end case;
- end process;
- end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement