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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [BCDSubtract.sv] - Blame information for rev 79

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

Line No. Rev Author Line
1 78 robfinch
module BCDSubtract(clk, a, b, o, co);
2
parameter N=25;
3
input clk;
4
input [N*4-1:0] a;
5
input [N*4-1:0] b;
6
output reg [N*4-1:0] o;
7
output reg co;
8
 
9
wire [(N+1)*4-1:0] bc;
10
wire [(N+1)*4-1:0] o1, o2, o3;
11
wire c;
12
 
13
BCDNinesComplementN #(N+1) u1 (.i({4'h0,b}), .o(bc));
14
BCDAdd8NClk #(.N(N/2+1)) u2 (.clk(clk), .a({8'h00,a}), .b(bc), .o(o1), .ci(1'b0), .co(c));
15
BCDNinesComplementN #(N) u3 (.i(o1), .o(o2));
16
BCDAdd8NClk #(.N(N/2+1)) u4 (.clk(clk), .a(o1), .b({{N*8{1'b0}},1'b1}), .o(o3), .ci(1'b0), .co());
17
 
18
always_ff @(posedge clk)
19
        if (c)
20
                o <= o3;
21
        else
22
                o <= o2;
23
always_ff @(posedge clk)
24
        co <= c;
25
 
26
endmodule
27
 
28
module BCDNinesComplement(i, o);
29
input [3:0] i;
30
output reg [3:0] o;
31
 
32
always_comb
33
        case(i)
34
        4'd0:   o = 4'd9;
35
        4'd1:   o = 4'd8;
36
        4'd2:   o = 4'd7;
37
        4'd3:   o = 4'd6;
38
        4'd4: o = 4'd5;
39
        4'd5:   o = 4'd4;
40
        4'd6:   o = 4'd3;
41
        4'd7:   o = 4'd2;
42
        4'd8:   o = 4'd1;
43
        4'd9:   o = 4'd0;
44
        4'd10:  o = 4'd9;
45
        4'd11:  o = 4'd8;
46
        4'd12:  o = 4'd7;
47
        4'd13:  o = 4'd6;
48
        4'd14:  o = 4'd5;
49
        4'd15:  o = 4'd4;
50
        endcase
51
 
52
endmodule
53
 
54
module BCDNinesComplementN(i, o);
55
parameter N=25;
56
input [N*4-1:0] i;
57
output [N*4-1:0] o;
58
 
59
genvar g;
60
generate begin : gNC
61
        for (g = 0; g < N; g = g + 1)
62
                BCDNinesComplement utc1 (i[g*4+3:g*4],o[g*4+3:g*4]);
63
end
64
endgenerate
65
 
66
endmodule
67
 
68
module BCDTensComplement(i, o);
69
input [3:0] i;
70
output reg [3:0] o;
71
 
72
always_comb
73
        case(i)
74
        4'd0:   o = 4'd0;
75
        4'd1:   o = 4'd9;
76
        4'd2:   o = 4'd8;
77
        4'd3:   o = 4'd7;
78
        4'd4: o = 4'd6;
79
        4'd5:   o = 4'd5;
80
        4'd6:   o = 4'd4;
81
        4'd7:   o = 4'd3;
82
        4'd8:   o = 4'd2;
83
        4'd9:   o = 4'd1;
84
        4'd10:  o = 4'd0;
85
        4'd11:  o = 4'd9;
86
        4'd12:  o = 4'd8;
87
        4'd13:  o = 4'd7;
88
        4'd14:  o = 4'd6;
89
        4'd15:  o = 4'd5;
90
        endcase
91
 
92
endmodule
93
 
94
module BCDTensComplementN(i, o);
95
parameter N=25;
96
input [N*4-1:0] i;
97
output [N*4-1:0] o;
98
 
99
genvar g;
100
generate begin : gTC
101
        for (g = 0; g < N; g = g + 1)
102
                BCDTensComplement utc1 (i[g*4+3:g*4],o[g*4+3:g*4]);
103
end
104
endgenerate
105
 
106
endmodule

powered by: WebSVN 2.1.0

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