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

Subversion Repositories uos_processor

[/] [vhdl/] [cpualu.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 droggen
-- ALU
2
-- The ALU uses 1 or 2 operands
3
-- The opcode are bits 14,13,12,11,10 of the instruction
4
-- a: input A of ALU
5
-- b: input B of ALU (not used for single operand instructions)
6
-- q: result (except for compare which is not used)
7
-- f: flag vectors with zero flag, overflow flag, carry flag and sign flag.
8
 
9
 
10
 
11
library IEEE;
12
use IEEE.STD_LOGIC_1164.ALL;
13
use IEEE.STD_LOGIC_UNSIGNED.ALL;
14
 
15
entity cpualu is
16
        port (
17
                clk : in STD_LOGIC;
18
                rst : in STD_LOGIC;
19
                op : in STD_LOGIC_VECTOR(4 downto 0);
20
                a : in STD_LOGIC_VECTOR(7 downto 0);
21
                b : in STD_LOGIC_VECTOR(7 downto 0);
22
                q : out STD_LOGIC_VECTOR(7 downto 0);
23
                f : out STD_LOGIC_VECTOR(3 downto 0)
24
                );
25
end cpualu;
26
 
27
architecture Behavioral of cpualu is
28
        signal sub : STD_LOGIC_VECTOR(8 downto 0);       -- Do subtraction on 9 bits to obtain the carry
29
        signal r: STD_LOGIC_VECTOR(7 downto 0);          -- ALU result
30
        signal zf,ovf,cf,sf : STD_LOGIC;
31
begin
32
 
33
        --comp_rng: entity work.rng port map(clk=>clk,rst=>rst
34
 
35
        sub <= ('0'&a) - ('0'&b);
36
 
37
 
38
        r <=            a+b when op(4 downto 3)="01" and op(1 downto 0)="00" else
39
                                sub(7 downto 0) when op(4 downto 3)="01" and op(1 downto 0)="01" else
40
                                a and b when op(4 downto 3)="01" and op(1 downto 0)="10" else
41
                                a or b when op(4 downto 3)="01" and op(1 downto 0)="11" else
42
                                a xor b when op(4 downto 3)="10" and op(1 downto 0)="00" else
43
                                not a when op(4 downto 0)="11000" else
44
                                '0'&a(7 downto 1) when op(4 downto 0)="11001" else
45
                                a(0)&a(7 downto 1) when op(4 downto 0)="11010" else
46
                                a(7)&a(7 downto 1) when op(4 downto 0)="11011" else
47
                                a(6 downto 0)&a(7) when op(4 downto 0)="11100" else
48
                                "00000000";
49
 
50
        sf <= sub(7);
51
        zf <= not(sub(7) or sub(6) or sub(5) or sub(4) or sub(3) or sub(2) or sub(1) or sub(0));
52
        cf <= sub(8);
53
        ovf <= (not a(7) and b(7) and sub(7)) or (a(7) and not b(7) and not sub(7));
54
 
55
        f<=zf&ovf&cf&sf;
56
        q<=r;
57
 
58
end Behavioral;
59
 

powered by: WebSVN 2.1.0

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