dpsub001h.vmd
2 KB
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
/**************************************************************/
/* Verilog module of datapath cell dpsub001h */
/* Designed by Chunling Liu Compass July 30,1992 */
/* */
/* The following is the port description */
/* Data ports */
/* A : the input port */
/* B : the input port */
/* CIN : the carry input */
/* SO : the output port */
/* COUT : the carry output */
/* Control ports */
/* INST_OVR : the carry overflow flag output */
/* INST_CIN : the carry input */
/* Parameters */
/* WORDSIZE : the word size of the datapath cell */
/* DELAY : the delay time from input to output */
/* BF : the with/without buffer flag */
/* 0 for without buffer; 1 for with buffer */
/**************************************************************/
module dpsub001h(A, B, INST_CIN, SO, INST_COUT, INST_OVR);
parameter WORDSIZE = 8, DELAY = 15, BF = 1;
input [WORDSIZE-1:0] A, B;
input INST_CIN;
output [WORDSIZE-1:0] SO;
output INST_COUT;
output INST_OVR;
reg [WORDSIZE:0] carry;
function [WORDSIZE-1:0] sub;
input [WORDSIZE-1:0] a, b, cin;
integer i;
begin
carry[0] = cin[0];
for (i=0; i<WORDSIZE; i=i+1)
begin
sub[i] = a[i] ^ ~b[i] ^ carry[i];
carry[i+1] = (a[i]&~b[i]) |
(a[i]&carry[i]) |
(~b[i]&carry[i]) ;
end
end
endfunction
assign #DELAY
SO = sub(A,B,INST_CIN),
INST_COUT = carry[WORDSIZE],
INST_OVR = carry[WORDSIZE-1];
endmodule