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

Subversion Repositories tinycpu

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

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

powered by: WebSVN 2.1.0

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