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

Subversion Repositories tinycpu

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

Go to most recent revision | 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
  signal TRData: std_logic;
27
begin
28
  TR <= TRData;
29
  process(DataIn1, DataIn2, Op)
30
  begin
31
    case Op is
32
--bitwise operations
33
      when "00000" => --and
34
        DataOut <= DataIn1 and DataIn2;
35
      when "00001" => --or
36
        DataOut <= DataIn1 or DataIn2;
37
      when "00010" => --xor
38
        DataOut <= DataIn1 xor DataIn2;
39
      when "00011" => --not
40
        DataOut <= not DataIn2; --ignore DataIn1 here so that mapping these operations is as simple as possible
41
      when "00100" => --left shift (logical)
42
        DataOut <= std_logic_vector(shift_left(unsigned(DataIn1),to_integer(unsigned(DataIn2(2 downto 0)))));
43
      when "00101" => --right shift(logical)
44
        DataOut <= std_logic_vector(shift_right(unsigned(DataIn1),to_integer(unsigned(DataIn2(2 downto 0)))));
45
      when "00110" => --left rotate
46
        DataOut <= std_logic_vector(rotate_left(unsigned(DataIn1),to_integer(unsigned(DataIn2(2 downto 0)))));
47
      when "00111" => --right rotate
48
        DataOut <= std_logic_vector(rotate_right(unsigned(DataIn1),to_integer(unsigned(DataIn2(2 downto 0)))));
49
--comparisons
50
      when "01000" => --greater than
51
        DataOut <= "00000000";
52
        if(to_integer(unsigned(DataIn1)) > to_integer(unsigned(DataIn2))) then
53
          TRData <= '1';
54
        else
55
          TRData <= '0';
56
        end if;
57
      when "01001" => --greater than or equal
58
        DataOut <= "00000000";
59
        if(to_integer(unsigned(DataIn1)) >= to_integer(unsigned(DataIn2))) then
60
          TRData <= '1';
61
        else
62
          TRData <= '0';
63
        end if;
64
      when "01010" => --less than
65
        DataOut <= "00000000";
66
        if(to_integer(unsigned(DataIn1)) < to_integer(unsigned(DataIn2))) then
67
          TRData <= '1';
68
        else
69
          TRData <= '0';
70
        end if;
71
      when "01011" => --less than or equal
72
        DataOut <= "00000000";
73
        if(to_integer(unsigned(DataIn1)) <= to_integer(unsigned(DataIn2))) then
74
          TRData <= '1';
75
        else
76
          TRData <= '0';
77
        end if;
78
      when "01100" => --equals to
79
        DataOut <= "00000000";
80
        if(to_integer(unsigned(DataIn1)) = to_integer(unsigned(DataIn2))) then
81
          TRData <= '1';
82
        else
83
          TRData <= '0';
84
        end if;
85
      when "01101" => --not equal
86
        DataOut <= "00000000";
87
        if(to_integer(unsigned(DataIn1)) /= to_integer(unsigned(DataIn2))) then
88
          TRData <= '1';
89
        else
90
          TRData <= '0';
91
        end if;
92
      when "01110" => --equal to 0
93
        DataOut <= "00000000";
94
        if(to_integer(unsigned(DataIn1)) = 0) then
95
          TRData <= '1';
96
        else
97
          TRData <= '0';
98
        end if;
99
      when "01111" => --not equal to 0
100
        DataOut <= "00000000";
101
        if(to_integer(unsigned(DataIn1)) /= 0) then
102
          TRData <= '1';
103
        else
104
          TRData <= '0';
105
        end if;
106
--other operations
107
      when "10000" => --set TR
108
        DataOut <= "00000000";
109
        TRData <= '1';
110
      when "10001" => --reset TR
111
        DataOut <= "00000000";
112
        TRData <= '0';
113
      when "10010" => --increment
114
        DataOut <= std_logic_vector(unsigned(DataIn1) + 1);
115
      when "10011" => --decrement
116
        DataOut <= std_logic_vector(unsigned(DataIn1) - 1);
117
      when "10100" => --add
118
        DataOut <= std_logic_vector(unsigned(DataIn1) + unsigned(DataIn2));
119
      when "10101" => --subtract
120
        DataOut <= std_logic_vector(unsigned(DataIn1) - unsigned(DataIn2));
121
 
122
      when others =>
123
        DataOut <= "00000000";
124
        TRData <= '1';
125
    end case;
126
  end process;
127
end Behavioral;

powered by: WebSVN 2.1.0

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