Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.33 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;
  4.  
  5.  
  6. entity domaci2 is
  7.     port(
  8.         iSW : in std_logic_vector(7 downto 0);
  9.         iNV : in std_logic;
  10.        
  11.         oLED : out std_logic_vector(7 downto 0);
  12.         oSIGN : out std_logic;
  13.         oGREAT : out std_logic
  14.     );
  15. end entity;
  16.  
  17.  
  18. architecture Behavior of domaci2 is
  19.    
  20.     signal sA : std_logic_vector(3 downto 0);
  21.     signal sB : std_logic_vector(3 downto 0);
  22.     signal sSUMA : std_logic_vector(3 downto 0);
  23.    
  24. begin
  25.  
  26.     process(iNV, iSW, sA, sB, sSUMA) begin
  27.         if(iNV='1')then
  28.             oLED <= not(iSW);   -- stavljamo neginrane signale na izlaz
  29.         else
  30.        
  31.             oLED(4) <= '1';         --ok ova lampa uvek svetli
  32.        
  33.             if(iSW(6)='1')then  --znaci treba ga invertovati
  34.                 sA <= '1' & iSW(6) & not(iSW(5 downto 4)) + '1';
  35.             else
  36.                 sA <= '0' & iSW(6 downto 4);
  37.             end if;
  38.            
  39.             if(iSW(2)='1')then
  40.                 sB <= '1' & iSW(2) & not(iSW(1 downto 0)) + '1'; -- treba prva cifra da bude 1 da bi bio negativan broj    
  41.             else
  42.                 sB <= '0' & iSW(2 downto 0);
  43.             end if;
  44.            
  45.             sSUMA <= sA + sB;
  46.            
  47.             oLED(3 downto 0) <= sSUMA;   --saberimo ta dva broja
  48.            
  49.            
  50.             if(sSUMA(3)='1')then            --znaci da je negativan zbir
  51.                 oSIGN <= '1';
  52.             else
  53.                 oSIGN <= '0';
  54.             end if;
  55.            
  56.            
  57.             if(iSW(6)='1' and iSW(2)='1')then
  58.                 if(sA > sB)then                                 --jer veci broj je zapravo manje negativan jer npr 111=-1(k2) je veci od 101=-3(k2)
  59.                     oGREAT <= '1';
  60.                 else
  61.                     oGREAT <= '0';
  62.                 end if;
  63.             elsif(iSW(6)='1' and iSW(2)='0')then
  64.                 oGREAT <= '0';
  65.             elsif(iSW(6)='0' and iSW(2)='1')then
  66.                 oGREAT <= '1';
  67.             else                                                            --elsif(iSW(6)='0' and iSW(2)='0')then
  68.                 if(sA > sB)then
  69.                     oGREAT <= '1';
  70.                 else
  71.                     oGREAT <= '0';
  72.                 end if;
  73.             end if;
  74.            
  75.                                      
  76.                                      
  77.             if(iSW(0)='1')then
  78.                     oLED(7 downto 5) <= "000";
  79.             elsif(iSW(1)='1')then
  80.                     oLED(7 downto 5) <= "001";
  81.             elsif(iSW(2)='1')then
  82.                     oLED(7 downto 5) <= "010";
  83.             elsif(iSW(3)='1')then
  84.                     oLED(7 downto 5) <= "011";
  85.             elsif(iSW(4)='1')then
  86.                     oLED(7 downto 5) <= "100";
  87.             elsif(iSW(5)='1')then
  88.                     oLED(7 downto 5) <= "101";
  89.             elsif(iSW(6)='1')then
  90.                     oLED(7 downto 5) <= "110";
  91.             elsif(iSW(7)='1')then
  92.                     oLED(7 downto 5) <= "111";
  93.             else
  94.                     oLED(7 downto 5) <= "000";
  95.             end if;
  96.            
  97.            
  98.            
  99.         end if;
  100.    
  101.     end process;
  102.    
  103.    
  104.    
  105. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement