-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadder_higher.v
More file actions
70 lines (58 loc) · 1.69 KB
/
adder_higher.v
File metadata and controls
70 lines (58 loc) · 1.69 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
`include "addbit_module.v"
module adder_higher (
result , // Output of the adder
carry , // Carry output of adder
r1 , // first input
r2 , // second input
ci // carry input
);
// Input Port Declarations
input [3:0] r1 ;
input [3:0] r2 ;
input ci ;
// Output Port Declarations
output [3:0] result ;
output carry ;
// Port Wires
wire [3:0] r1 ;
wire [3:0] r2 ;
wire ci ;
wire [3:0] result ;
wire carry ;
// Internal variables
wire c1 ;
wire c2 ;
wire c3 ;
// Code Starts Here
addbit_module u0 (r1[0],r2[0],ci,result[0],c1);
addbit_module u1 (r1[1],r2[1],c1,result[1],c2);
addbit_module u2 (r1[2],r2[2],c2,result[2],c3);
addbit_module u3 (r1[3],r2[3],c3,result[3],carry);
endmodule // End Of Module adder
module tb();
reg [3:0] r1,r2;
reg ci;
wire [3:0] result;
wire carry;
// Drive the inputs
initial begin
r1 = 0;
r2 = 0;
ci = 0;
#10 r1 = 10;
#10 r2 = 2;
#10 ci = 1;
#10 $display("+--------------------------------------------------------+");
$finish;
end
// Connect the lower module
adder_higher U (result,carry,r1,r2,ci);
// Hier demo here
initial begin
$display("+--------------------------------------------------------+");
$display("| r1 | r2 | ci | u0.sum | u1.sum | u2.sum | u3.sum |");
$display("+--------------------------------------------------------+");
$monitor("| %h | %h | %h | %h | %h | %h | %h |",
r1,r2,ci, tb.U.u0.sum, tb.U.u1.sum, tb.U.u2.sum, tb.U.u3.sum);
end
endmodule