-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path17_finder.v
82 lines (73 loc) · 1.25 KB
/
17_finder.v
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
//An instering module used to find a special number
//author:WangFW
//date:2020-5-26
module finder(clk,rst_n,wr,din,find,dfind,full,is,location);
input clk;
input rst_n;
input wr;
input [7:0] din;
input find;
input [7:0] dfind;
output reg full;
output reg is;
output reg [5:0] location;
reg [7:0] mem [63:0];
reg [5:0] pointer;
reg [5:0] check;
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
pointer<=6'd0;
full<=1'b0;
end
else
begin
if(wr)
if(pointer<6'd63)
begin
mem[pointer]<=din;
pointer<=pointer+1'b1;
full<=1'b0;
end
else
begin
pointer<=6'd0;
full<=1'b1;
end
end
end
always @(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
is<=1'b0;
location<=6'd0;
check<=6'd0;
end
else
begin
if(find)
begin
if(check<6'd63)
begin
if(mem[check]==dfind)
begin
location<=check;
is<=1'b1;
end
else
begin
check<=check+1'b1;
is<=1'b0;
end
end
else
begin
check<=6'd0;
is<=1'b0;
end
end
end
end
endmodule