-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcube_root.v
83 lines (69 loc) · 1.22 KB
/
cube_root.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
83
module cube_root(
input inc,
input sub,
input next,
input prev,
input enter,
input clk,
output wire [7:0] leds,
output wire [7:0] control
);
reg signed [31:0] exit;
wire ready;
wire [31:0] res;
reg zero = 0;
// input //
reg inc1 = 0;
reg next1 = 0;
reg prev1 = 0;
reg sub1 = 0;
reg enter1 = 0;
reg [31:0] decimal = 1;
//////////
reg [31:0] to_display;
display_bcd display(
.clk(clk),
.value(ready == 0 ? exit : res),
.control(control),
.leds(leds)
);
calculate calc(
.clk(clk),
.ready_to_calc(~enter),
.num(exit),
.ready(ready),
.res(res)
);
always @(posedge clk)
begin
if (enter == 1) begin
if ((inc1 == 1'b0) && (~inc == 1'b1)) begin
exit = exit + decimal;
end
inc1 = ~inc;
if ((sub1 == 1'b0) && (~sub == 1'b1)) begin
if (exit > 0) begin
exit = exit - decimal;
end
end
sub1 = ~sub;
if ((next1 == 1'b0) && (~next == 1'b1)) begin
decimal = decimal * 10;
end
next1 = ~next;
if ((prev1 == 1'b0) && (~prev == 1'b1)) begin
if (decimal >= 1 && decimal <= 9) begin
decimal = 1;
end else begin
decimal = decimal / 10;
end
end
prev1 = ~prev;
end else begin
if (ready == 1'b1) begin
exit = 0;
decimal = 1;
end
end
end
endmodule