Skip to content
asicguru.tech@gmail.com
REGISTER LOGIN
AsicGuru Ventures
  • All Courses
  • CONTACT
  • GALLERY
  • HOME
  • Tutorials

0

Verilog Tutorial

17
  • Verilog Introduction
  • Lexical Tokens
  • Gate-Level Modelling
  • Data Types
  • Operators
  • Operands
  • Modules
  • Behavioral Modeling
  • Timing Controls
  • Procedures: Always and Initial Blocks
  • Functions
  • Tasks
  • Component Inference
  • Finite State Machines.
  • Compiler Directives
  • System Tasks and Functions
  • Test Benches

System Verilog

23
  • System Verilog Introduction
  • Data Types
  • Type Casting
  • Arrays
  • Associative Arrays
  • Dynamic Arrays
  • Queue
  • Operators
  • Procedural statements and Control flow
  • Classes
  • Inheritance
  • Encapsulation
  • This and Super operator
  • In-Line Constraints
  • Class Constraints
  • Virtual Classes
  • Parameterized Classes
  • Classes Summary
  • Singleton Classes
  • Functional Coverage Introduction
  • Covergroup
  • Tools
  • Books

Scripting

15
  • Introduction
  • Perl Tutorial
  • What is Perl
  • Perl: Syntax And Variable
  • Perl Strings
  • Perl Arrays
  • Perl Associative Arrays
  • If/While Syntax
  • File Input
  • Print Output
  • String Processing with Regular Expressions
  • Subroutines
  • Running External Programs
  • References
  • Terse Perl

Makefile

1
  • Makefile Tutorial
View Categories
  • Home
  • Tutorials
  • System Verilog
  • Dynamic Arrays

Dynamic Arrays

4 min read

#

Dynamic arrays are fast and variable size is possible with a call to new () function. In dynamic size array :

  1. Similar to fixed size arrays but size can be given in the run time
  2. Dynamic arrays can have only single dimention and it can not be packed
  3. Out of bound error in dynamic arrays causes run time error.

view source

print?

01.module example;

02. 

03.reg [31:0] regArray_1[];

04.reg [31:0] regArray_2[];

05.reg [31:0] regArray_3[];

06.reg [31:0] regArray_[];

07. 

08.int i;

09. 

10.initial

11.begin

12.regArray_1 = new [5];

13.regArray_3 = new [3];

14.regArray_ = new [10];

15. 

16.// initialize values for regArray_1

17.for ( i = 0 ; i < regArray_1.size(); i ++ )

18.regArray_1[i] = i;

19. 

20.// copy regArray_1 to regArray_2

21.regArray_2 = new[regArray_1.size()] (regArray_1);

22. 

23.// initialize values for regArray_3

24.for ( i = 0 ; i < regArray_2.size(); i ++ )

25.$display ("%d: %d \n" , i, regArray_2[i]);

26. 

27.$display ("regArray_3");

28.for ( i = 0 ; i < regArray_3.size(); i ++ )

29.$display ("%d: %d \n" , i, regArray_3[i]);

30. 

31.// Display the result of the transformation

32.$display ("Transformed regArray_1, with reduced size");

33.for ( i = 0 ; i < regArray_1.size(); i ++ )

34.$display ("%d: %d \n" , i, regArray_1[i]);

35. 

36.// copying 'regArray_' to 'regArray_1'.

37.regArray_1 = new[10](regArray_);

38.$display ("regArray_");

39.for ( i = 0 ; i < regArray_.size(); i ++ )

40.$display ("%d: %d \n" , i, regArray_[i]);

41. 

42.// Display the result of the transformation

43.$display ("Transformed regArray_1, with increased size");

44.for ( i = 0 ; i < regArray_1.size(); i ++ )

45.$display ("%d: %d \n" , i, regArray_1[i]);

46. 

47.regArray_1.delete(); // Deleting the elements of regArray_1

48.// Display the size of the array after deletion

49.$display ("Size of the regArray_1 after deletion = %d",

50.regArray_1.size());

51. 

52.#100 $finish;

53.end

54.endmodule

Output :

view source

print?

01.# Copy of old regArray_1

02.#           0:          0

03.#

04.#           1:          1

05.#

06.#           2:          2

07.#

08.#           3:          3

09.#

10.#           4:          4

11.#

12.# regArray_3

13.#           0:          1

14.#

15.#           1:          1

16.#

17.#           2:          1

18.#

19.# Transformed regArray_1, with reduced size

20.#           0:          1

21.#

22.#           1:          1

23.#

24.#           2:          1

25.#

26.#           3:          x

27.#

28.#           4:          x

29.#

30.#           5:          x

31.#

32.#           6:          x

33.#

34.#           7:          x

35.#

36.#           8:          x

37.#

38.#           9:          x

39.#

40.# regArray_

41.#           0:          0

42.#

43.#           1:          0

44.#

45.#           2:          0

46.#           2:          0

47.#

48.#           3:          0

49.#

50.#           4:          0

51.#

52.#           5:          0

53.#

54.#           6:          0

55.#

56.#           7:          0

57.#

58.#           8:          0

59.#

60.#           9:          0

61.#

62.# Transformed regArray_1, with increased size

63.#           0:          0

64.#

65.#           1:          0

66.#

67.#           2:          0

68.#

69.#           3:          0

70.#

71.#           4:          0

72.#

73.#           5:          0

74.#

75.#           6:          0

76.#

77.#           7:          0

78.#

79.#           8:          0

80.#

81.#           9:          0

82.#

Updated on May 4, 2025

What are your Feelings

  • Happy
  • Normal
  • Sad
Share This Article :
  • Facebook
  • X
  • LinkedIn
  • Pinterest
Associative ArraysQueue

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Table of Contents

Archives

  • May 2025

Categories

  • Slider Post
  • Uncategorized

Copyright @ Asicguru Ventures by Misbah WP | Proudly powered by WordPress