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
  • Queue

Queue

2 min read

#

In queues size is flexible. It can change easily

  1. Variable size array with automatic sizing, single dimension
  2. Many searching, sorting, and insertion methods
  3. Constant time to read, write, and insert at front & back
  4. Out of bounds access causes run-time error

A Queue is a variable size ordered collection of homogeneous objects. There are two main aspects of a queue that makes it attractive for verification purposes. First, a queue can have variable length, including a length of zero. This makes a queue an ideal candidate as a storage element that can shrink or grow as elements are deleted or added to it without fixing an artificial upper limit on its size as a regular fixed size array. The other advantage of having a queue is that, it provides a way to emulate both Last In
First Out (LIFO) and First In First Out (FIFO) behavior that are required in so many ordered transactions. At the same time a queue still allows you to access any element randomly within the queue without any overhead just as a regular array. A Queue is analogous to one dimensional unpacked array that grows and shrinks automatically. Queues are declared using the same syntax as unpacked arrays, but specifying ‘$’ as the array size.
Eg:

view source

print?

1.byte q1 [$];

2.integer my_q[$] = {1, 3, 5};

3.string names [$] = {“Ram, Sham, Laxman”};

4. 

5.bit q [$:255];

6.// A queue whose maximum size is 256 bits.

Example :

view source

print?

01.module example ;

02. 

03.int int_queue[$] = { 1, 2, 3 };

04.string string_queue [$] = {"first","second","third","forth"};

05. 

06.string s;

07. 

08.initial

09.begin

10.// example of the use of size

11.$display("\n Use of size()");

12. 

13.for (int i = 0 ; i < int_queue.size(); i++ )

14.$display(int_queue[i]);

15. 

16.$display("\n\n Elements of string_queue[$]");

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

18.$write(string_queue[i]," ");

19. 

20.// example of the use of insert

21.string_queue.insert(1,"next"); // former element 1 is now element 2.

22.string_queue.insert(2,"somewhere");

23. 

24.$display("\n\n Use of insert()");

25.for (int i = 0; i < string_queue.size; i++)

26.$write(string_queue[i]," ");

27. 

28.// example of the use of delete

29.string_queue.delete(1); // delete the element

30.string_queue.delete(3);

31. 

32.$display("\n\n Use of delete()");

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

34.$write(string_queue[i]," ");

35. 

36.// example of the use of pop_front

37.// deletes the front of the queue

38.s = string_queue.pop_front();

39.$display("\n\n Use of pop_front()");

40.$display(" %s",s);

41. 

42.for (int i = 0; i < string_queue.size; i++)

43.$write(string_queue[i]," ");

44. 

45.// example of the use of pop_back

46.// deletes the back of the queue

47.s = string_queue.pop_back();

48.$display("\n\n Use of pop_back()");

49.$display(" %s",s);

50.for (int i = 0; i < string_queue.size; i++)

51.$write(string_queue[i]," ");

52. 

53.// example of the use of push_front and push_back

54.// grows the queue

55.string_queue.push_front("in-front");

56.string_queue.push_back("in-back");

57. 

58.$display("\n\n Use of push_front() and push_back()");

59.for (int i = 0; i < string_queue.size; i++)

60.$write(string_queue[i]," \n ");

61. 

62.end

63.endmodule

Output : #

view source

print?

01.#

02.#  Use of size()

03.#           1

04.#           2

05.#           3

06.#

07.#

08.#  Elements of string_queue[$]

09.# first second third forth

10.#

11.#  Use of insert()

12.# first next somewhere second third forth

13.#

14.#  Use of delete()

15.# first somewhere second forth

16.#

17.#  Use of pop_front()

18.#  first

19.# somewhere second forth

20.#

21.#  Use of pop_back()

22.#  forth

23.# somewhere second

24.#

25.#  Use of push_front() and push_back()

26.# in-front

27.#  somewhere

28.#  second

29.#  in-back

30.#

31.<p> </p>

Updated on May 4, 2025

What are your Feelings

  • Happy
  • Normal
  • Sad
Share This Article :
  • Facebook
  • X
  • LinkedIn
  • Pinterest
Dynamic ArraysOperators

Leave a Reply Cancel reply

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

Table of Contents
  • Output :

Archives

  • May 2025

Categories

  • Slider Post
  • Uncategorized

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