OpenCores
URL https://opencores.org/ocsvn/8051/8051/trunk

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_divide.v] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 simont
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// divide for 8051 Core                                         ////
4
////                                                              ////
5
//// This file is part of the 8051 cores project                  ////
6
//// http://www.opencores.org/cores/8051/                         ////
7
////                                                              ////
8
//// Description                                                  ////
9
//// Implementation of division used in alu.v                     ////
10
////                                                              ////
11
//// To Do:                                                       ////
12
////  Nothing                                                     ////
13
////                                                              ////
14
//// Author(s):                                                   ////
15
//// - Simon Teran, simont@opencores.org                          ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2001 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE. See the GNU Lesser General Public License for more  ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// ver: 1
45
//
46
 
47
// synopsys translate_off
48
`include "oc8051_timescale.v"
49
// synopsys translate_on
50
 
51
module oc8051_divide (src1, src2, des1, des2, desOv);
52
//
53
// this module is part of alu
54
// src1         (in)  first operand
55
// src2         (in)  second operand
56
// des1         (out) first result
57
// des2         (out) second result
58
// desOv        (out) Overflow output
59
//
60
 
61
input [7:0] src1, src2;
62
output desOv;
63
output [7:0] des1, des2;
64
reg desOv; reg [7:0] des1, des2;
65
reg [8:0] div1,div2;
66
 
67
always @(src1 or src2)
68
begin
69
      if (src2==8'b0000_0000) begin
70
        des1=8'bxxxx_xxxx;
71
        des2=8'bxxxx_xxxx;
72
        desOv=1'b1;
73
      end
74
      else if (src1==src2) begin
75
        des1=8'b0000_0001;
76
        des2=8'b0000_0000;
77
        desOv=1'b0;
78
      end
79
      else if (src1<src2) begin
80
        des1=8'b0000_0000;
81
        des2=src1;
82
        desOv=1'b0;
83
      end
84
      else begin
85
        des1=src1;
86
        des2=8'b0000_0000;
87
 
88
        div2={1'b0,src2};
89
 
90
// begin loop
91
//loop 0
92
        des2={des2[6:0],des1[7]};
93
        des1={des1[6:0], 1'b0};
94
        div1={1'b1, des2};
95
        div1= div1 - div2;
96
 
97
        if (div1[8]==1'b1) begin
98
          des1[0]= 1'b1;
99
          des2=div1[7:0];
100
        end
101
 
102
//loop 1
103
        des2={des2[6:0],des1[7]};
104
        des1={des1[6:0], 1'b0};
105
        div1={1'b1, des2};
106
        div1= div1 - div2;
107
 
108
        if (div1[8]==1'b1) begin
109
          des1[0]= 1'b1;
110
          des2=div1[7:0];
111
        end
112
//loop 2
113
        des2={des2[6:0],des1[7]};
114
        des1={des1[6:0], 1'b0};
115
        div1={1'b1, des2};
116
        div1= div1 - div2;
117
 
118
        if (div1[8]==1'b1) begin
119
          des1[0]= 1'b1;
120
          des2=div1[7:0];
121
        end
122
//loop 3
123
        des2={des2[6:0],des1[7]};
124
        des1={des1[6:0], 1'b0};
125
        div1={1'b1, des2};
126
        div1= div1 - div2;
127
 
128
        if (div1[8]==1'b1) begin
129
          des1[0]= 1'b1;
130
          des2=div1[7:0];
131
        end
132
//loop 4
133
        des2={des2[6:0],des1[7]};
134
        des1={des1[6:0], 1'b0};
135
        div1={1'b1, des2};
136
        div1= div1 - div2;
137
 
138
        if (div1[8]==1'b1) begin
139
          des1[0]= 1'b1;
140
          des2=div1[7:0];
141
        end
142
//loop 5
143
        des2={des2[6:0],des1[7]};
144
        des1={des1[6:0], 1'b0};
145
        div1={1'b1, des2};
146
        div1= div1 - div2;
147
 
148
        if (div1[8]==1'b1) begin
149
          des1[0]= 1'b1;
150
          des2=div1[7:0];
151
        end
152
//loop 6
153
        des2={des2[6:0],des1[7]};
154
        des1={des1[6:0], 1'b0};
155
        div1={1'b1, des2};
156
        div1= div1 - div2;
157
 
158
        if (div1[8]==1'b1) begin
159
          des1[0]= 1'b1;
160
          des2=div1[7:0];
161
        end
162
//loop 7
163
        des2={des2[6:0],des1[7]};
164
        des1={des1[6:0], 1'b0};
165
        div1={1'b1, des2};
166
        div1= div1 - div2;
167
 
168
        if (div1[8]==1'b1) begin
169
          des1[0]= 1'b1;
170
          des2=div1[7:0];
171
        end
172
 
173
 
174
// end loop
175
          desOv=1'b0;
176
      end
177
end
178
 
179
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.