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

Subversion Repositories signed_unsigned_multiplier_and_divider

[/] [signed_unsigned_multiplier_and_divider/] [trunk/] [alu_with_hex2ascii.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zpekic
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    23:32:07 03/05/2018 
6
-- Design Name: 
7
-- Module Name:    alu_with_hex2ascii - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
 
23
-- Uncomment the following library declaration if using
24
-- arithmetic functions with Signed or Unsigned values
25
use IEEE.NUMERIC_STD.ALL;
26
 
27
-- Uncomment the following library declaration if instantiating
28
-- any Xilinx primitives in this code.
29
--library UNISIM;
30
--use UNISIM.VComponents.all;
31
 
32
entity alu_with_hex2ascii is
33
    Port ( a : in  STD_LOGIC_VECTOR (15 downto 0);
34
           b : in  STD_LOGIC_VECTOR (15 downto 0);
35
                          bcdmode: in STD_LOGIC;
36
           operation : in  STD_LOGIC_VECTOR (2 downto 0);
37
           carry_in : in  STD_LOGIC;
38
           carry_out : out  STD_LOGIC;
39
           zero : out  STD_LOGIC;
40
           y : out  STD_LOGIC_VECTOR (15 downto 0));
41
end alu_with_hex2ascii;
42
 
43
architecture Behavioral of alu_with_hex2ascii is
44
 
45
signal hexchar, ascii, offset: std_logic_vector(7 downto 0);
46
signal y_out, a_padded, b_padded, a_plus_b, a_minus_b, b_2compl: std_logic_vector(17 downto 0);
47
 
48
begin
49
 
50
-- select hex digit to convert to ASCII code
51
        with bcdmode & operation(1 downto 0) select
52
                hexchar <=  X"3" & b(3 downto 0) when "000",             -- hex is coming through input B
53
                                                X"3" & b(7 downto 4) when "001",
54
                                                X"3" & b(11 downto 8) when "010",
55
                                                X"3" & b(15 downto 12) when "011",
56
                                                X"3" & a(3 downto 0) when "100",         -- bcd is coming through input A
57
                                                X"3" & a(7 downto 4) when "101",
58
                                                X"3" & a(11 downto 8) when "110",
59
                                                X"3" & a(15 downto 12) when others;
60
 
61
-- convert to ASCII
62
        offset <= X"07" when hexchar(3) = '1' and (hexchar(2) = '1' or hexchar(1) = '1') else X"00";
63
   ascii <= std_logic_vector(unsigned(hexchar) + unsigned(offset));
64
 
65
-- 2's complement add and substract
66
        a_padded <= '0' & a & carry_in;
67
        b_padded <= '0' & b & carry_in;
68
        --b_2compl <= ('0', not b(15), not b(14), not b(13), not b(12), not b(11), not b(10), not b(9), not b(8), not b(7), not b(6), not b(5), not b(4), not b(3), not b(2), not b(1), not b(0), carry_in);
69
        a_minus_b <= std_logic_vector(unsigned(a_padded) + unsigned(b_padded xor "011111111111111110"));
70
        a_plus_b <= std_logic_vector(unsigned(a_padded) + unsigned(b_padded));
71
 
72
-- result is either +/- or ASCII code
73
 
74
with operation(2 downto 0) select
75
        y_out <= a_plus_b               when "000",
76
                                a_minus_b       when "001",
77
                                a_padded                when "010", -- for possible future use
78
                                b_padded                when "011", -- for possible future use
79
                                '0' & X"00" & ascii & '0' when others;
80
 
81
-- generate outputs
82
        y <= y_out(16 downto 1);
83
        carry_out <= y_out(17);
84
        zero <= '1' when y_out(16 downto 1) = X"0000" else '0';
85
 
86
end Behavioral;
87
 

powered by: WebSVN 2.1.0

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