-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdynamic_array_data.sv
More file actions
executable file
·42 lines (33 loc) · 1.01 KB
/
dynamic_array_data.sv
File metadata and controls
executable file
·42 lines (33 loc) · 1.01 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
module dynamic_array_data();
// Declare dynamic array
reg [7:0] mem [];
initial begin
// Allocate array for 4 locations
$display ("Setting array size to 4");
mem = new[4];
$display("Initial the array with default values");
for (int i = 0; i < 4; i ++) begin
mem[i] = i;
end
// Doubling the size of array, with old content still valid
// *** New contents are all 'x' ***
mem = new[8] (mem);
// Print current size
$display ("Current array size is %d",mem.size());
for (int i = 0; i < 8; i ++) begin
$display ("Value at location %g is %d ", i, mem[i]);
end
// Doubling the size of array again, with old content still valid ? No
mem = new[16];
// Print current size
$display ("Current array size is %d",mem.size());
for (int i = 0; i < 16; i ++) begin
$display ("Value at location %g is %d ", i, mem[i]);
end
// Delete array
$display ("Deleting the array and the size becomes 0");
mem.delete();
$display ("Current array size is %d",mem.size());
#1 $finish;
end
endmodule