-
Notifications
You must be signed in to change notification settings - Fork 0
/
csdigit.v
90 lines (83 loc) · 1.39 KB
/
csdigit.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
84
85
86
87
88
89
90
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 22:14:53 06/14/2021
// Design Name:
// Module Name: csdigit
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module csdigit(
input signed[14+2:0]a,
output reg signed [14+1:0]c
);
integer i;
reg carry=0;
//assign a[15] = a[14];
//assign a[16] = 0;
always @(a or i or carry)
begin
for(i=0;i<16;i=i+1)
begin
//if statement carry =0
if(carry == 0)
begin
if({a[i+1],a[i]}==2'b00 ||{a[i+1],a[i]}==2'b10)
begin
c[i] = 1'b0;
carry = 0;
end
else if({a[i+1],a[i]}==2'b01)
begin
c[i] = 1'b1;
carry = 0;
end
else if({a[i+1],a[i]}==2'b11)
begin
c[i] = -1'b1;
carry = 1;
end
else
begin
c = a;
carry = 0;
end
end//if end
///////else statement carry =1
else
begin
if({a[i+1],a[i]}==2'b01 ||{a[i+1],a[i]}==2'b11)
begin
c[i] = 1'b0;
carry = 1;
end
else if({a[i+1],a[i]}==2'b00)
begin
c[i] = 1'b1;
carry = 0;
end
else if({a[i+1],a[i]}==2'b10)
begin
c[i] = -1'b1;
carry = 1;
end
else
begin
c = a;
carry = 0;
end
end//else end
end// for end
end//always end
endmodule