Arrays in Verilog 1690008267
Arrays in Verilog 1690008267
MEMORIES
PACKED ARRAY:
Size of packed array will be constant throughout simulation
Size is determined before the variable name.
One dimensional packed array called as vector
Ex:
bit [9:0] [8:0] mem
// here [9:0] is no. of groups and [8:0] no. of bits per group
bit [10] [4] mem;
//here 10 no. of groups and [4] is no. of bits per group
UNPACKED ARRAY:
Size of array will be constant throughout the simulation
Size is determined after the variable name
Unpacked array is called array of array or multidimensional array.
Ex:
Que 1) What is an array in Verilog, and what are its applications in hardware
design?
Array is a collection of the same data type
Arrays are used to store multiple values of the same data type and
provide organized way to access and manipulate data.
They find extensive application in hardware design for tasks such as
representing memories,fifo,buffers.
Ex:
Que 3) Describe the process of initializing a Verilog array with specific values.
Que 4) Write Verilog code to implement a 2D unpacked array of 4x4 2-bit elements.
Que 5) What is the purpose of using initial and always block with arrays?
The initial block is used toperform one time initialization of arrays at the
beginning of simulation
The always block is used to model sequential behavior
Que 6) Describe the use of looping constructs iterate through arrays in verilog
Que 8) How can you use verilog arrays for hardware modelling ,like shift registers or
FIFOs?
Arrays can be used to model shift registers,FIFO.
Que 9) What are the different types of memories you can implement using arrays in
verilog?
Memories such as RAM,ROM,FIFO,SHIFT REGISTER.
Que 10) How do you use $urandom to initialize a random array in verilog testbenches?
We can us $urandom to initialize random array in verilog testbenches by calling inside initial
and always block
Ex:
initial
begin
my_array[i] =$urandom;
end
EX:
module tb;
reg [5:0] a; //packed array
reg b [0:4]; //unpacked array
integer i;
initial
begin
for(i=0;i<8;i++)
begin
b[i] = $urandom;
$display("b[%0d]=%0d",i,b[i]);
end
end
initial
begin
a=6'b101011;
$display("A=%0d",a);
end
initial
begin
for(i=0;i<8;i++)
begin
c[i]=$urandom;
$display("c[%0d]=%0d",i,c[i]);
end
end
endmodule
https://www.edaplayground.com/x/JVBh
Que 11) How do you implement a circular buffer using a verilog array?
A circular buffer can be implemented using an array along with read and write
pointers.
--------------------------------------------------------------------------------------------------------------------------------------
Que 12) What are the different methods to pass an array as an argument to a verilog
function or module?
We can pass array as an argument to a verilog function or module using the input
and output keyword followed by the array
Que 13) How do you handle multi-dimensional arrays in verilog testbenches for stimulus
generation?
For stimulus generation in testbenches,we can use nested loops to iterate though
elements of multidimensional array.
module mux(in,sel,out);
input sel;
input [1:0]in;
output out;