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/] [rom32x32.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: 03/04/2018 05:14:44 PM
6
-- Design Name: 
7
-- Module Name: rom32x32 - 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
 
21
 
22
library IEEE;
23
use IEEE.STD_LOGIC_1164.ALL;
24
 
25
-- Uncomment the following library declaration if using
26
-- arithmetic functions with Signed or Unsigned values
27
use IEEE.NUMERIC_STD.ALL;
28
 
29
-- Uncomment the following library declaration if instantiating
30
-- any Xilinx leaf cells in this code.
31
--library UNISIM;
32
--use UNISIM.VComponents.all;
33
use work.sys_primegen_package.all;
34
 
35
entity rom32x32 is
36
    Port ( nCS : in STD_LOGIC;
37
           a : in STD_LOGIC_VECTOR (4 downto 0);
38
           d : out STD_LOGIC_VECTOR (31 downto 0));
39
end rom32x32;
40
 
41
architecture Behavioral of rom32x32 is
42
 
43
--signal a_int: std_logic_vector(7 downto 0);
44
--signal d_int: std_logic_vector(31 downto 0);
45
type rom is array(0 to 31) of std_logic_vector(31 downto 0);
46
 
47
constant ucode: rom := (
48
 
49
            X"2A" & muxa_zero & muxb_const      & alu_adc       & ci_zero       & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
50
 
51
        1 => -- WaitForStart: i = 0; IF (buttonstart != 1) THEN GOTO WaitForStart
52
            X"00" & muxa_m      & muxb_m                & alu_sbc       & ci_one        & i_load        & m_nop & n_nop         & mode_umul & muldiv_nop        & uart_nop      & if_next_else_repeat   & cond_buttonstart,
53
 
54
        2 => -- n = Arg0;
55
            X"00" & muxa_arg0 & muxb_const      & alu_adc       & ci_zero       & i_nop                 & m_nop  & n_load       & mode_umul & muldiv_nop        & uart_nop      & if_next_else_next             & cond_true,
56
 
57
        3 => -- LoopN: IF (n > Arg1) THEN GOTO WaitForStart
58
            X"01" & muxa_n      & muxb_arg1     & alu_sbc       & ci_one        & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_nop      & if_goto_else_next             & cond_alugreaterthan,
59
 
60
        4 => -- IF (n < 2) THEN GOTO NextN 
61
            X"10" & muxa_n      & muxb_two              & alu_sbc       & ci_one        & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_nop      & if_goto_else_next             & cond_alulessthan,
62
 
63
        5 => -- IF (n < 4) THEN GOTO FoundPrime
64
            X"0F" & muxa_n      & muxb_four             & alu_sbc       & ci_one        & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_nop      & if_goto_else_next             & cond_alulessthan,
65
 
66
        6 => -- m = 1;
67
            X"01" & muxa_zero & muxb_const      & alu_adc       & ci_zero       & i_nop                 & m_load & n_nop        & mode_umul & muldiv_nop        & uart_nop      & if_next_else_next             & cond_true,
68
 
69
        7 => -- NextM: m = m + 1;
70
            X"00" & muxa_zero & muxb_m                  & alu_adc       & ci_one        & i_nop                 & m_load & n_nop        & mode_umul & muldiv_nop        & uart_nop      & if_next_else_next             & cond_true,
71
 
72
        8 => -- kick off division n / m, note that n must be presented as dividend, divisor is hard coded to m. Keep the start signal on until unit responds with not ready
73
            X"00" & muxa_n              & muxb_const    & alu_adc       & ci_zero       & i_nop                 & m_nop  & n_nop        & mode_udiv & muldiv_start & uart_nop   & if_next_else_repeat   & cond_muldivnotready,
74
 
75
        9 => -- wait for division to finish
76
            X"00" & muxa_n              & muxb_const    & alu_adc       & ci_zero       & i_nop                 & m_nop  & n_nop        & mode_udiv & muldiv_nop        & uart_nop      & if_next_else_repeat   & cond_muldivready,
77
 
78
                  10 => -- IF (n // m = 0) THEN GOTO NextN 
79
            X"10" & muxa_zero & muxb_modulo     & alu_sbc       & ci_one        & i_nop                 & m_nop         & n_nop                 & mode_udiv & muldiv_nop        & uart_nop      & if_goto_else_next             & cond_aluzero,
80
 
81
        11 => -- kick off multiplication m * m, note that m must be presented as factor0, factor1 is hard coded to m. Keep the start signal on until unit responds with not ready
82
            X"00" & muxa_m              & muxb_const    & alu_adc       & ci_zero       & i_nop                 & m_nop  & n_nop        & mode_umul & muldiv_start & uart_nop   & if_next_else_repeat   & cond_muldivnotready,
83
 
84
        12 => -- wait for multiplication to finish
85
            X"00" & muxa_m              & muxb_const    & alu_adc       & ci_zero       & i_nop                 & m_nop  & n_nop        & mode_umul & muldiv_nop        & uart_nop      & if_next_else_repeat   & cond_muldivready,
86
 
87
                  13 => -- IF (m * m >= n) THEN GOTO FoundPrime 
88
            X"0F" & muxa_prod & muxb_n                  & alu_sbc       & ci_one        & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_nop      & if_goto_else_next             & cond_alugreaterorequal,
89
 
90
                  14 => -- GOTO NextM
91
            X"07" & muxa_zero & muxb_const      & alu_adc       & ci_zero       & i_nop         & m_nop & n_nop                 & mode_umul & muldiv_nop        & uart_nop      & if_goto_else_next             & cond_true,
92
 
93
                  15 => -- FoundPrime: GOSUB PrintIandN
94
            X"11" & muxa_zero & muxb_const      & alu_adc       & ci_zero       & i_nop         & m_nop & n_nop                 & mode_umul & muldiv_nop        & uart_nop      & if_gosub_else_repeat  & cond_ibcdready,
95
 
96
                  16 => -- NextN: n = n + 1; IF (n != 0) GOTO LoopN else GOTO Start
97
            X"03" & muxa_zero & muxb_n                  & alu_adc       & ci_one        & i_nop                 & m_nop  & n_load       & mode_umul & muldiv_nop        & uart_nop      & if_goto_else_start            & cond_alunotzero,
98
 
99
                  17 => -- PrintIandN: i = i + 1
100
            X"00" & muxa_zero & muxb_i                  & alu_adc       & ci_one        & i_load        & m_nop  & n_nop                & mode_umul & muldiv_nop        & uart_nop      & if_next_else_next             & cond_true,
101
 
102
        18 => -- PRINT "<CR>"
103
            X"0D" & muxa_zero & muxb_const      & alu_adc       & ci_zero       & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
104
 
105
        19 => -- PRINT ASC(BCD(i) >> 12 AND 0x000F)
106
            X"00" & muxa_ibcd & muxb_const   & alu_asc3  & ci_zero      & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
107
 
108
        20 => -- PRINT ASC(BCD(i) >> 8 AND 0x000F)
109
            X"00" & muxa_ibcd & muxb_const   & alu_asc2  & ci_zero      & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
110
 
111
        21 => -- PRINT ASC(BCD(i) >> 4 AND 0x000F)
112
            X"00" & muxa_ibcd & muxb_const   & alu_asc1  & ci_zero      & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
113
 
114
        22 => -- PRINT ASC(BCD(i) >> 0 AND 0x000F)
115
            X"00" & muxa_ibcd & muxb_const   & alu_asc0  & ci_zero      & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
116
 
117
        23 => -- PRINT " "
118
            X"20" & muxa_zero & muxb_const      & alu_adc       & ci_zero       & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
119
 
120
                  24 => -- Wait for BCD(n) ready
121
            X"00" & muxa_zero & muxb_const      & alu_adc       & ci_zero       & i_nop         & m_nop & n_nop                 & mode_umul & muldiv_nop        & uart_nop      & if_next_else_repeat   & cond_nbcdready,
122
 
123
        25 => -- PRINT ASC(BCD(n) >> 0 AND 0x000F)
124
            X"00" & muxa_nbcdh & muxb_const  & alu_asc0  & ci_zero      & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
125
 
126
        26 => -- PRINT ASC(BCD(n) >> 12 AND 0x000F)
127
            X"00" & muxa_nbcdl & muxb_const  & alu_asc3  & ci_zero      & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
128
 
129
        27 => -- PRINT ASC(BCD(n) >> 8 AND 0x000F)
130
            X"00" & muxa_nbcdl & muxb_const  & alu_asc2  & ci_zero      & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
131
 
132
        28 => -- PRINT ASC(BCD(n) >> 4 AND 0x000F)
133
            X"00" & muxa_nbcdl & muxb_const  & alu_asc1  & ci_zero      & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
134
 
135
        29 => -- PRINT ASC(BCD(n) >> 0 AND 0x000F)
136
            X"00" & muxa_nbcdl & muxb_const  & alu_asc0  & ci_zero      & i_nop                 & m_nop         & n_nop                 & mode_umul & muldiv_nop        & uart_send & if_next_else_repeat       & cond_uartready,
137
 
138
                  30 => -- RETURN
139
            X"00" & muxa_zero & muxb_const      & alu_adc       & ci_zero       & i_nop         & m_nop & n_nop                 & mode_umul & muldiv_nop        & uart_nop      & if_return_else_next   & cond_true,
140
                  ------------------------
141
        others => -- HALT
142
            X"00" & muxa_zero & muxb_const      & alu_adc       & ci_zero       & i_nop         & m_nop & n_nop                 & mode_umul & muldiv_nop        & uart_nop      & if_next_else_repeat   & cond_false
143
    );
144
 
145
begin
146
 
147
        d <= ucode(to_integer(unsigned(a))) when (nCS = '0') else "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
148
 
149
end Behavioral;

powered by: WebSVN 2.1.0

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