OpenCores
URL https://opencores.org/ocsvn/tinycpu/tinycpu/trunk

Subversion Repositories tinycpu

[/] [tinycpu/] [trunk/] [src/] [alu.vhd] - Blame information for rev 31

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 earlz
 
2
 
3
 
4
 
5
 
6 14 earlz
library IEEE;
7
use IEEE.STD_LOGIC_1164.ALL;
8
use IEEE.NUMERIC_STD.ALL;
9
use work.tinycpu.all;
10
 
11 15 earlz
 
12
 
13
 
14 14 earlz
entity alu is
15
 
16
  port(
17
    Op: in std_logic_vector(4 downto 0);
18
    DataIn1: in std_logic_vector(7 downto 0);
19
    DataIn2: in std_logic_vector(7 downto 0);
20
    DataOut: out std_logic_vector(7 downto 0);
21
    TR: out std_logic
22
   );
23
end alu;
24
 
25
architecture Behavioral of alu is
26
begin
27
  process(DataIn1, DataIn2, Op)
28
  begin
29 31 earlz
    TR <= '0';
30 14 earlz
    case Op is
31
--bitwise operations
32
      when "00000" => --and
33
        DataOut <= DataIn1 and DataIn2;
34
      when "00001" => --or
35
        DataOut <= DataIn1 or DataIn2;
36
      when "00010" => --xor
37
        DataOut <= DataIn1 xor DataIn2;
38
      when "00011" => --not
39
        DataOut <= not DataIn2; --ignore DataIn1 here so that mapping these operations is as simple as possible
40
      when "00100" => --left shift (logical)
41
        DataOut <= std_logic_vector(shift_left(unsigned(DataIn1),to_integer(unsigned(DataIn2(2 downto 0)))));
42
      when "00101" => --right shift(logical)
43
        DataOut <= std_logic_vector(shift_right(unsigned(DataIn1),to_integer(unsigned(DataIn2(2 downto 0)))));
44
      when "00110" => --left rotate
45
        DataOut <= std_logic_vector(rotate_left(unsigned(DataIn1),to_integer(unsigned(DataIn2(2 downto 0)))));
46
      when "00111" => --right rotate
47
        DataOut <= std_logic_vector(rotate_right(unsigned(DataIn1),to_integer(unsigned(DataIn2(2 downto 0)))));
48
--comparisons
49
      when "01000" => --greater than
50
        DataOut <= "00000000";
51
        if(to_integer(unsigned(DataIn1)) > to_integer(unsigned(DataIn2))) then
52 31 earlz
          TR <= '1';
53 14 earlz
        else
54 31 earlz
          TR <= '0';
55 14 earlz
        end if;
56
      when "01001" => --greater than or equal
57
        DataOut <= "00000000";
58
        if(to_integer(unsigned(DataIn1)) >= to_integer(unsigned(DataIn2))) then
59 31 earlz
          TR <= '1';
60 14 earlz
        else
61 31 earlz
          TR <= '0';
62 14 earlz
        end if;
63
      when "01010" => --less than
64
        DataOut <= "00000000";
65
        if(to_integer(unsigned(DataIn1)) < to_integer(unsigned(DataIn2))) then
66 31 earlz
          TR <= '1';
67 14 earlz
        else
68 31 earlz
          TR <= '0';
69 14 earlz
        end if;
70
      when "01011" => --less than or equal
71
        DataOut <= "00000000";
72
        if(to_integer(unsigned(DataIn1)) <= to_integer(unsigned(DataIn2))) then
73 31 earlz
          TR <= '1';
74 14 earlz
        else
75 31 earlz
          TR <= '0';
76 14 earlz
        end if;
77
      when "01100" => --equals to
78
        DataOut <= "00000000";
79
        if(to_integer(unsigned(DataIn1)) = to_integer(unsigned(DataIn2))) then
80 31 earlz
          TR <= '1';
81 14 earlz
        else
82 31 earlz
          TR <= '0';
83 14 earlz
        end if;
84
      when "01101" => --not equal
85
        DataOut <= "00000000";
86
        if(to_integer(unsigned(DataIn1)) /= to_integer(unsigned(DataIn2))) then
87 31 earlz
          TR <= '1';
88 14 earlz
        else
89 31 earlz
          TR <= '0';
90 14 earlz
        end if;
91
      when "01110" => --equal to 0
92
        DataOut <= "00000000";
93
        if(to_integer(unsigned(DataIn1)) = 0) then
94 31 earlz
          TR <= '1';
95 14 earlz
        else
96 31 earlz
          TR <= '0';
97 14 earlz
        end if;
98
      when "01111" => --not equal to 0
99
        DataOut <= "00000000";
100
        if(to_integer(unsigned(DataIn1)) /= 0) then
101 31 earlz
          TR <= '1';
102 14 earlz
        else
103 31 earlz
          TR <= '0';
104 14 earlz
        end if;
105
--other operations
106
      when "10000" => --set TR
107
        DataOut <= "00000000";
108 31 earlz
        TR <= '1';
109 14 earlz
      when "10001" => --reset TR
110
        DataOut <= "00000000";
111 31 earlz
        TR <= '0';
112 14 earlz
      when "10010" => --increment
113
        DataOut <= std_logic_vector(unsigned(DataIn1) + 1);
114
      when "10011" => --decrement
115
        DataOut <= std_logic_vector(unsigned(DataIn1) - 1);
116
      when "10100" => --add
117
        DataOut <= std_logic_vector(unsigned(DataIn1) + unsigned(DataIn2));
118
      when "10101" => --subtract
119
        DataOut <= std_logic_vector(unsigned(DataIn1) - unsigned(DataIn2));
120
 
121
      when others =>
122
        DataOut <= "00000000";
123 31 earlz
        TR <= '1';
124 14 earlz
    end case;
125
  end process;
126
end Behavioral;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.