View difference between Paste ID: 0JVhwd8u and Aq79J9bR
SHOW: | | - or go back to the newest paste.
1
---------------------------------------
2
library IEEE;
3
use IEEE.STD_LOGIC_1164.ALL;
4
5
6
entity nasobicka is
7
    Port ( s : in  STD_LOGIC;
8
           x : in  STD_LOGIC_VECTOR (width-1 downto 0);
9
           y : in  STD_LOGIC_VECTOR (width-1 downto 0);
10
           P : in  STD_LOGIC_VECTOR (2*width-1 downto 0);
11
           done : out  STD_LOGIC);
12
end nasobicka;
13
14
architecture Behavioral of nasobicka is
15
16
signal NL,NC : unsigned (width-1 downto 0);
17
signal SC: unsigned (width downto 0);
18
signal PC: integer range 0 to width;
19
20
type states is (smart, init, add, shift_NL,shift_SC,stop);
21
signal state, next_state : state := start;
22
23
signal l1,l3 : std_logic;
24
signal r_start : std_logic;
25
signal R : std_logic_vector(1 to 6);
26
27
begin
28
	l1 <= '1' when NL(0) = '1' else '0';
29
	l3 <= '1' when PC < width else'0';
30
	
31
	NL_reg: process(clk) is 
32
		begin
33
			if rising_edge(clk) then
34
				if r_start = '1' then
35
					NL <= x;
36
				elsif R (4) = '1' then
37
					NL <= SC(0) & NL(width-1 downto 1);
38
					end if;
39
					end if;
40
					end process;
41
					
42
					NC_reg: process (clk) is
43
						begin
44
							if rising_edge(clk) then 
45
								if r_start = '1' then
46
									NC <= y;
47
								end if;
48
							end if;
49
						end process;
50
									
51
					SC_reg: process (clk) is
52
						begin
53
							if rising_edge(clk) then
54
								if R (1) = '1' then
55
									SC <= (others => '0');
56
									elsif R(3) = '1' then
57-
									SC <= resize (SC+NC,Sc'length);
57+
									SC <= resize (SC+NC,SC'length);
58
									elsif R(5) = '1' then
59
									SC <= '0' & SC(width downto 1);
60
								end if;
61
							end if;
62
						end process;
63
							
64
			P <= SC(width -1 downto 0) & NL;
65
			
66
			PC_reg: process (clk) is 
67
				begin
68
					if rising_edge(clk) then
69
						if R(2) = '1' then
70
							PC<=0;
71
						elsif R(6) = '1' then
72
							PC <=PC+1;
73
						end if;
74
					end if;
75
				end process;
76
				
77
				process (clk)
78
					begin
79
						if rising_edge(clk)
80
							then state <= next_state;
81
						end if;
82
					end process;
83
					
84
				process (state,s,l1,l3)
85
					begin
86
						next_state <= state;
87
						
88
						case state is
89
							when start =>
90
								if (s = '1') then
91
									next_state <= init;
92
								else
93
									next_state <= start;
94
								end if;
95
							when init =>
96
									if(l1 = '1') then
97
										next_state <= add;
98
									else
99
										next_state <=shift_NL;
100
									end if;
101
							when add => 
102
								next_state <= shift_NL;
103
							when shift_NL =>
104
								next_state <= shift_SC;
105
							when shift_SC =>
106
								if (l3 = '1' and l1 = '1') then
107
									next_state <= add;
108
								elsif (l3 = '1' and l1 = '0') then
109
									next_state <= shift_NL;
110
								else
111
								next_state <=  stop;
112
							end if;
113
						when stop =>
114
								next_state <= start;
115
							when others => null;
116
					end case;
117
end process;		
118
119
process (state)
120
	begin
121
		done <= '0';
122
		r_start <= '0';
123
		R<= (others => '0');
124
		
125
126
		case state is
127
				when start =>
128
					r_start <= '1';
129
					done <= '0';
130
				when init =>
131
					R(1 to 2) <= "l1";
132
				when add =>
133
					R(3) <= '1';
134
				when shift_NL =>
135
				R(4) <= '1';
136
				R (6) <= '1';
137
				
138
				when shift_SC =>
139
				R(5) <= '1';
140
				
141
				when stop =>
142
				done <= '1';
143
				when others => null;
144
			end case;
145
			end process;
146
			
147
end Behavioral;