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

Subversion Repositories risc5x

[/] [risc5x/] [trunk/] [alu.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mikej
--
2
-- Risc5x
3
-- www.OpenCores.Org - November 2001
4
--
5
--
6
-- This library is free software; you can distribute it and/or modify it
7
-- under the terms of the GNU Lesser General Public License as published
8
-- by the Free Software Foundation; either version 2.1 of the License, or
9
-- (at your option) any later version.
10
--
11
-- This library is distributed in the hope that it will be useful, but
12
-- WITHOUT ANY WARRANTY; without even the implied warranty of
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
-- See the GNU Lesser General Public License for more details.
15
--
16
-- A RISC CPU core.
17
--
18
-- (c) Mike Johnson 2001. All Rights Reserved.
19
-- mikej@opencores.org for support or any other issues.
20
--
21
-- Revision list
22
--
23
-- version 1.0 initial opencores release
24
--
25
 
26
use work.pkg_prims.all;
27
use work.pkg_risc5x.all;
28
library ieee;
29
  use ieee.std_logic_1164.all;
30
  use ieee.std_logic_arith.all;
31
  use ieee.std_logic_unsigned.all;
32
 
33
entity ALU is
34
  port (
35
    ADDSUB          : in  std_logic_vector(1 downto 0);
36
    BIT             : in  std_logic_vector(1 downto 0);
37
    SEL             : in  std_logic_vector(1 downto 0);
38
 
39
    A               : in  std_logic_vector(7 downto 0);
40
    B               : in  std_logic_vector(7 downto 0);
41
    Y               : out std_logic_vector(7 downto 0);
42
    CIN             : in  std_logic;
43
    COUT            : out std_logic;
44
    DCOUT           : out std_logic;
45
    ZOUT            : out std_logic
46
    );
47
end;
48
 
49
architecture RTL of ALU is
50
 
51
-- signal definitions
52
  signal add_sub_dout   : std_logic_vector(7 downto 0) := (others => '0');
53
  signal add_sub_result : std_logic_vector(8 downto 0) := (others => '0');
54
  signal alubit_dout    : std_logic_vector(7 downto 0) := (others => '0');
55
  signal alubit_result  : std_logic_vector(8 downto 0) := (others => '0');
56
  signal a_rol          : std_logic_vector(8 downto 0) := (others => '0');
57
  signal a_ror          : std_logic_vector(8 downto 0) := (others => '0');
58
 
59
  signal carry          : std_logic_vector(7 downto 0) := (others => '0');
60
  signal alu_result     : std_logic_vector(8 downto 0) := (others => '0');
61
 
62
begin -- architecture
63
 
64
  u_add_sub : ADD_SUB
65
    generic map (
66
      WIDTH         => 8
67
      )
68
    port map (
69
      A             => A,
70
      B             => B,
71
 
72
      ADD_OR_SUB    => ADDSUB(1),
73
      DO_SUB        => ADDSUB(0),
74
 
75
      CARRY_OUT     => carry,
76
      DOUT          => add_sub_dout
77
      );
78
 
79
  add_sub_result <= carry(7) & add_sub_dout(7 downto 0);
80
  a_ror  <= A(0) & CIN & A(7 downto 1);
81
  a_rol  <= A(7) & A(6 downto 0) & CIN;
82
 
83
  u_alubit : ALUBIT
84
    generic map (
85
      WIDTH         => 8
86
      )
87
    port map (
88
      A             => A,
89
      B             => B,
90
      OP            => BIT,
91
 
92
      DOUT          => alubit_dout
93
      );
94
 
95
  alubit_result <= '0' & alubit_dout;
96
 
97
  u_mux4 : MUX4
98
    generic map (
99
      WIDTH         => 9,
100
      SLICE         => 0,
101
      OP_REG        => FALSE
102
      )
103
    port map (
104
      DIN3          => a_rol,
105
      DIN2          => a_ror,
106
      DIN1          => alubit_result,
107
      DIN0          => add_sub_result,
108
 
109
      SEL           => SEL,
110
      ENA           => '0',
111
      CLK           => '0',
112
 
113
      DOUT          => alu_result
114
      );
115
 
116
  p_zout_comb : process(alu_result)
117
  begin
118
    ZOUT <= '0';
119
    if (alu_result(7 downto 0) = "00000000") then ZOUT <= '1'; end if;
120
  end process;
121
 
122
  COUT   <=     alu_result(8);
123
  DCOUT  <=     carry(3);
124
  Y      <=     alu_result(7 downto 0);
125
end rtl;
126
 

powered by: WebSVN 2.1.0

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