File: x_dividev1.v

package info (click to toggle)
vbs 1.4.0-9
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,200 kB
  • ctags: 4,401
  • sloc: cpp: 17,648; yacc: 1,880; ansic: 884; makefile: 419; sh: 375; lex: 345
file content (59 lines) | stat: -rw-r--r-- 983 bytes parent folder | download | duplicates (2)
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
/*
 * Divide module
 *  dependencies:
 *	register declaration
 *	io declaration
 *	always procedural block
 *	system tasks
 *	ifelse statement
 */

module divider (clk, quot, rem, fin, dvdend, dvsor, reset);
	output [31:0] quot;
	output [63:0] rem;
	output fin;
	input [63:0] dvdend;
	input [31:0] dvsor;
	input clk, reset;

	reg [31:0] quot;
	reg [63:0] rem, dvsor_copy;
	reg fin;
	reg [5:0] rep;

	always @(posedge clk)
		begin
		if (reset == 1)
			begin
			quot = 0;
			dvsor_copy = 0;
			fin = 0;
			rep = 0;
			end
		else
			begin
			if (rep == 0)
				begin
				// Make copies of the data.
				rem = dvdend;
				dvsor_copy[63:32] = dvsor;
				rep = rep + 1;
				end
			else if (rep >= 1)
				begin
				rem = rem - dvsor_copy;
				quot = quot << 1;
				if (rem[63:63] == 1)
					rem = dvsor_copy + rem;
				else
					quot[0:0] = 1;
				dvsor_copy = dvsor_copy >> 1;
				// When are we finished?
				if (rep == 33)
					fin = 1;
				rep = rep + 1;
				end
			end
		end

endmodule