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

Subversion Repositories mcip_open

[/] [mcip_open/] [trunk/] [MCIPopen_XilinxISEproject/] [ALU.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 mezzah
--------------------------------------------------------------------------------
2
-- Company:        Ferhat Abbas University - Algeria
3
-- Engineer:       Ibrahim MEZZAH
4
-- Progect Supervisor: Dr H. Chemali
5
-- Create Date:    01:15:35 07/17/05
6
-- Design Name:    8-bits arithmetic and logic unit (2)
7
-- Module Name:    ALU - simple
8
-- Project Name:   Microcontroller IP (MCIP)
9
-- Target Device:  xc3s500e-4fg320
10
-- Tool versions:  Xilinx ISE 9.1.03i
11
-- Description:  This ALU is based on 8 simple slices. This module:
12
--                                               operates on A, B and using Old status,
13
--                                               provides the result S and the New status.
14
-- Revision:             07/07/2008
15
-- Revision  2.2 - Add description
16
--------------------------------------------------------------------------------
17
library IEEE;
18
use IEEE.STD_LOGIC_1164.ALL;
19
use IEEE.STD_LOGIC_UNSIGNED.ALL;
20
 
21
entity ALU is
22
    Port ( CommandVector : in std_logic_vector(13 downto 0);
23
           CommandStatus : in std_logic_vector(4 downto 0);
24
                          OldStatus     : in std_logic_vector(4 downto 0);
25
                          a             : in std_logic_vector(7 downto 0);
26
           b             : in std_logic_vector(7 downto 0);
27
           s             : out std_logic_vector(7 downto 0);
28
           NewStatus     : out std_logic_vector(4 downto 0);
29
           SetResponse   : out std_logic_vector(1 downto 0));
30
end ALU;
31
 
32
architecture simple of ALU is
33
        component alu_slice
34
    Port ( g  : in  std_logic_vector(3 downto 0);
35
           p  : in  std_logic_vector(3 downto 0);
36
           a  : in  std_logic;
37
           b  : in  std_logic;
38
           ci : in  std_logic;
39
           s  : out std_logic;
40
           co : out std_logic);
41
        end component;
42
 
43
        signal ci : std_logic_vector(7 downto 0);
44
        signal co : std_logic_vector(7 downto 0);
45
        signal ai : std_logic_vector(7 downto 0);
46
        signal bi : std_logic_vector(7 downto 0);
47
        signal si : std_logic_vector(7 downto 0);
48
        signal CurrentStatus : std_logic_vector(4 downto 0);
49
        signal cr0 : std_logic;
50
        signal cr7 : std_logic;
51
        signal C   : std_logic;
52
        signal DC  : std_logic;
53
        signal Z   : std_logic;
54
        signal OV  : std_logic;
55
        signal N   : std_logic;
56
        signal test_bit : std_logic;
57
 
58
        signal SWAPa  : std_logic_vector(7 downto 0);
59
        signal S_D    : std_logic_vector(7 downto 0);
60
        signal BITOPa : std_logic_vector(7 downto 0);
61
        signal DAW_op : std_logic_vector(7 downto 0);
62
 
63
        alias v : std_logic_vector(13 downto 0) is CommandVector;
64
 
65
begin
66
 
67
slices: for i in 0 to 7 generate
68
        slice: alu_slice
69
                port map( g  => v(3 downto 0),
70
                                         p  => v(7 downto 4),
71
                                         a  => ai(i),
72
                                         b  => bi(i),
73
                                         ci => ci(i),
74
                                         s  => si(i),
75
                                         co => co(i)
76
                                  );
77
        end generate;
78
 
79
        cr0 <= a(1)                                                     when v(11) = '1' else
80
                         a(7);
81
        cr7 <= a(0)                                                      when v(10) = '1' else
82
                         OldStatus(0);
83
 
84
        ci(0) <= '0'                                                      when v(13 downto 12) = "00" else
85
                                '1'                                                     when v(13 downto 12) = "01" else
86
                                cr0                                                     when v(13 downto 12) = "10" else
87
                                OldStatus(0);
88
        ci(7) <= cr7                                                    when v(11) = '1' else
89
                                co(6);
90
 
91
        C <= co(0)                                                               when v(11) = '1' else
92
                  co(7);
93
        DC <= ci(4);
94
        Z <= '1'                                                                        when si = X"00" else
95
                  '0';
96
        N <= si(7);
97
        OV <= '1'
98
        when((v(0)='0' and v(1)='1' and N='1' and a(7)='0' and b(7)='0') or
99
                  (v(0)='0' and v(1)='1' and N='0' and a(7)='1' and b(7)='1') or
100
 
101
                  (v(0)='0' and v(1)='0' and N='1' and a(7)='0') or
102
 
103
                  (v(0)='1' and v(1)='0' and v(5)='0' and N='0' and a(7)='1' and b(7)='0') or
104
                  (v(0)='1' and v(1)='0' and v(5)='0' and N='1' and a(7)='0' and b(7)='1') or
105
 
106
                  (v(0)='1' and v(7)='1' and N='0' and a(7)='1') or
107
 
108
                  (v(0)='1' and v(1)='0' and v(5)='1' and N='1' and a(7)='1' and b(7)='0') or
109
                  (v(0)='1' and v(1)='0' and v(5)='1' and N='0' and a(7)='0' and b(7)='1') or
110
 
111
                  (v(0)='1' and v(1)='1' and v(7)='0' and N='1' and a(7)='1') ) else
112
                        '0';
113
 
114
        CurrentStatus <= N&OV&Z&DC&C;
115
 
116
        SWAPa <= a(3 downto 0) & a(7 downto 4);
117
 
118
        DAW_op(3 downto 0) <= X"6"
119
        when ((b(3 downto 0) > "1001") or OldStatus(1)='1') else
120
                                                                 X"0";
121
        DAW_op(7 downto 4) <= X"6"              when ((b(7 downto 4) > "1001") or OldStatus(0)='1'
122
                                                                                                        or (b(7 downto 4)="1001" and DC='1')) else
123
                                                                 X"0";
124
 
125
        S_D <= DAW_op                                                   when V(10) = '0' else
126
                         SWAPa;
127
 
128
        ai <= BITOPa                                                    when v(8) = '0' else
129
                        S_D                                                             when v(9) = '0' else
130
                        a;
131
        bi <= b;
132
 
133
        SetResponse(0) <= test_bit                       when v(8) = '0' else
134
                                                        N;
135
        SetResponse(1) <= Z;
136
 
137
Carry : process(v(13 downto 11), a, co, cr0, cr7, OldStatus(0))
138
        begin
139
                for i in 0 to 7 loop
140
                  if i = 0 then
141
                        if v(13 downto 12) = "00" then
142
                          ci(i) <= '0';
143
                        elsif v(13 downto 12) = "01" then
144
                          ci(i) <= '1';
145
                        elsif v(13 downto 12) = "10" then
146
                          ci(i) <= cr0;
147
                        else
148
                          ci(i) <= OldStatus(0);
149
                        end if;
150
                  elsif i = 7 then
151
                        if v(11) = '1' then
152
                          ci(i) <= cr7;
153
                        else
154
                          ci(i) <= co(6);
155
                        end if;
156
                  else
157
                        if v(11) = '1' then
158
                          ci(i) <= a(i+1);
159
                        else
160
                          ci(i) <= co(i-1);
161
                        end if;
162
                  end if;
163
                end loop;
164
        end process;
165
 
166
Bit_op : process(a, b(2 downto 0), v(10 downto 9))
167
        begin
168
                for i in 0 to 7 loop
169
                if i = conv_integer(b(2 downto 0)) then
170
                  if v(9) = '1' then
171
                         BITOPa(i) <= not a(i);
172
                  elsif v(10) = '0' then
173
                         BITOPa(i) <= '0';
174
                  else
175
                         BITOPa(i) <= '1';
176
                  end if;
177
                  test_bit <= a(i);
178
                else
179
                  BITOPa(i) <= a(i);
180
                end if;
181
                end loop;
182
        end process;
183
 
184
Status : process(OldStatus, CommandStatus, CurrentStatus)
185
        begin
186
                for i in 0 to 4 loop
187
                if CommandStatus(i) = '1' then
188
                  NewStatus(i) <= CurrentStatus(i);
189
                else
190
                  NewStatus(i) <= OldStatus(i);
191
                end if;
192
                end loop;
193
        end process;
194
 
195
        s <= si;
196
 
197
end simple;

powered by: WebSVN 2.1.0

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