Advertisement
Guest User

Untitled

a guest
Nov 14th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity zad1 is
  6. port(
  7. A,B,C :in std_logic_vector (7 downto 0);
  8. S :out std_logic_vector (7 downto 0)
  9. );
  10. end entity;
  11.  
  12. architecture data_flow of zad1 is
  13. signal sum_A : integer range 0 to 18;
  14. signal sum_B : integer range 0 to 18;
  15. signal sum_C : integer range 0 to 18;
  16. signal A_int : integer range 0 to 99;
  17. signal B_int : integer range 0 to 99;
  18. signal C_int : integer range 0 to 99;
  19. signal div : std_logic_vector (2 downto 0);
  20. begin
  21. process(A,B,C) is
  22. begin
  23. A_int <= to_integer(unsigned(A(7 downto 4)))*10 + to_integer(unsigned(A(3 downto 0)));
  24. B_int <= to_integer(unsigned(B(7 downto 4)))*10 + to_integer(unsigned(B(3 downto 0)));
  25. C_int <= to_integer(unsigned(C(7 downto 4)))*10 + to_integer(unsigned(C(3 downto 0)));
  26.  
  27. sum_A <= to_integer(unsigned(A(7 downto 4))) + to_integer(unsigned(A(3 downto 0)));
  28. sum_B <= to_integer(unsigned(B(7 downto 4))) + to_integer(unsigned(B(3 downto 0)));
  29. sum_C <= to_integer(unsigned(C(7 downto 4))) + to_integer(unsigned(C(3 downto 0)));
  30. --Sprawdzanie warunku podzielności przez 3
  31. S<="00000000";
  32. case sum_A is
  33. when 3 | 6 | 9 | 12 | 15 | 18 =>
  34. div(2) <= '1';
  35. when others =>
  36. div(2) <= '0';
  37. end case;
  38.  
  39. case sum_B is
  40. when 3 | 6 | 9 | 12 | 15 | 18 =>
  41. div(1) <= '1';
  42. when others =>
  43. div(1) <= '0';
  44. end case;
  45.  
  46. case sum_C is
  47. when 3 | 6 | 9 | 12 | 15 | 18 =>
  48. div(0) <= '1';
  49. when others =>
  50. div(0) <= '0';
  51. end case;
  52. --Sprawdzanie która z liczb jest największa
  53. case div is
  54. when "000" =>
  55. S <= "00000000";
  56. when "001" =>
  57. S <= C;
  58. when "010" =>
  59. S <= B;
  60. when "011" =>
  61. if B_int>=C_int then
  62. S <= B;
  63. else
  64. S <= C;
  65. end if;
  66. when "100" =>
  67. S <= A;
  68. when "101" =>
  69. if A_int>=C_int then
  70. S <= A;
  71. else
  72. S <= C;
  73. end if;
  74. when "110" =>
  75. if A_int>=B_int then
  76. S <= A;
  77. else
  78. S <= B;
  79. end if;
  80. when "111" =>
  81. if A_int>=B_int then
  82. if C_int>=A_int then
  83. S <= C;
  84. elsif A_int>=C_int then
  85. S <= A;
  86. end if;
  87.  
  88. elsif B_int>=A_int then
  89. if B_int>=C_int then
  90. S <= B;
  91. elsif C_int>=B_int then
  92. S <= C;
  93. end if;
  94. elsif C_int>=B_int then
  95. if C_int>=A_int then
  96. S <= C;
  97. elsif A_int>=C_int then
  98. S <= A;
  99. end if;
  100. else
  101. S <= C;
  102. end if;
  103. end case;
  104. end process;
  105.  
  106. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement