1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
| library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
USE work.my_data_types.all;
use ieee.std_logic_arith;
use ieee.numeric_std.all;
ENTITY Projem_With_adder IS
GENERIC (n : INTEGER := 4);
PORT( clk : IN STD_LOGIC;
--matris_in : IN integer_array(0 TO n+1);
matris_out : OUT int_arr_out;
we : in std_logic
);
end Projem_With_adder;
architecture behv of Projem_With_adder is
SIGNAL matris_in :integer_array :=((0,0,0,0,0,0), (0,25,69,54,30,0), (0,215,14,3,98,0), (0,51,150,117,200,0), (0,100,13,82,9,0), (0,0,0,0,0,0));
SIGNAL s1,s2,s3,s4,s5,s6,s7,summary : std_logic_vector(7 downto 0);
VARIABLE counter : INTEGER;
TYPE state IS (st0,st1,st2,st3,st4);
SIGNAL pr_state,nx_state: state;
function adder (A,B : in integer) return unsigned is
variable tmp: unsigned(8 downto 0);
variable SUM: unsigned(7 downto 0);
begin
--tmp := (conv_unsigned(A,8) + conv_unsigned(B,8) );
-- G1 : FOR i IN 0 TO 7 LOOP
-- if (A(i) XOR ( B(i) XOR CI )) =1 then
--tmp(i) := '1';
--else tmp(i) := 0;
--end if;
--end LOOP;
--SUM:=tmp (7 downto 0);
--co:=tmp(8);
return SUM;
end adder;
BEGIN
PROCESS(clk,we)
BEGIN
if(we='1') then
pr_state <=st0;
elsif(clk'event and clk = '1') then
pr_state <= nx_state;
end if;
END PROCESS;
PROCESS(pr_state,counter)
BEGIN
counter := 0;
FOR i IN 1 TO n LOOP
FOR j IN 1 TO n LOOP
CASE pr_state IS
WHEN st0 =>
IF(counter = 0) THEN
s1<=conv_integer(adder(matris_in(i-1,j-1),matris_in(i-1,j)));
s2<=adder(matris_in(i-1,j+1),matris_in(i,j-1));
s3<=adder(matris_in(i,j),matris_in(i,j+1));
s4<=adder(matris_in(i+1,j-1),matris_in(i+1,j));
counter:=counter + 1;
nx_state <= st1;
end if;
WHEN st1 =>
IF(counter = 1) then
s5<=adder(s1,s2);
s6<=adder(s3,s4);
counter:=counter + 1;
nx_state <= st2;
end if;
WHEN st2 =>
IF(counter = 2) THEN
s7<=adder(s5,s6);
counter:=counter + 1;
nx_state <= st3;
end if;
WHEN st3 =>
IF(counter = 3) THEN
summary<=(s7,matris_in(i+1,j+1));
matris_out(i,j)<=conv_integer(summary);
end if;
END CASE;
end loop;
end loop;
end process;
end behv; |