首先看下下面的這個示例:
module PU;
int A[2:0][3:0][4:0], B[2:0][3:0][4:0], C[5:0][4:0];
initial
begin
A[0][2][4] = 1024; //row 0, column 2, element #4
//display index #4 (i.e., 5th element)
$display("A[0][2][4]=",A[0][2][4]);
//display 5 elements of row 0, column 2
$display("A[0][2]=",A[0][2]);
//display row 0 (4 columns; 5 elements each)
$display("A[0]=",A[0]);
//display 3 rows * 4 columns of 5 elements each
$display("A=",A);
$display("
");
B[1][1][1]=512; //row 1; column 1; element #1
// assign a subarray composed of fve ints
A[2][3] = B[1][1];
//display 5 elements of row 2, column 3
$display("A[2][3]=",A[2][3]);
B[0][0][0]=128; //Assign only to the last unpacked element
A[1] = B[0];
$display("
");
$display("A[1]=",A[1]); //display row 1 (4 columns; 5
elements each)
C[5][4]=64;
A[0][1] = C[5];
$display("
");
$display("C[5]=",C[5]);
$display("A[0][1]=",A[0][1]);
end
endmodule
仿真log:
A[0][2][4]= 1024 //index #4 (i.e., 5th element)
A[0][2]='{1024, 0, 0, 0, 0} //5 elements of row 0, column 2
A[0]='{'{0, 0, 0, 0, 0}, '{1024, 0, 0, 0, 0}, '{0, 0, 0, 0, 0}, '{0, 0, 0, 0, 0}}
//4 columns of row 0 with value assigned to column 2, element #4 (5th position)
A='{'{'{0, 0, 0, 0, 0}, '{0, 0, 0, 0, 0}, '{0, 0, 0, 0, 0}, '{0, 0, 0, 0, 0}}, '{'{0, 0, 0, 0,
0}, '{0, 0, 0, 0, 0}, '{0, 0, 0, 0, 0}, '{0, 0, 0, 0, 0}}, '{'{0, 0, 0, 0, 0}, '{1024, 0, 0,
0, 0}, '{0, 0, 0, 0, 0}, '{0, 0, 0, 0, 0}}}
//Entire 3 rows*4 columns (12 entries – 5 elements each with value assigned to
column 2, element #5)
A[2][3]='{0, 0, 0, 512, 0} // display 5 elements of row 2, column 3
A[1]='{'{0, 0, 0, 0, 0}, '{0, 0, 0, 0, 0}, '{0, 0, 0, 0, 0}, '{0, 0, 0, 0, 128}}
// display row 1 (4 columns; 5 elements each)
C[5]='{64, 0, 0, 0, 0} //Row 5, 5 elements with index 4 assigned
A[0][1]='{64, 0, 0, 0, 0} //Row 0, column 1 of 5 elements
V C S S i m u l a t i o n R e p o r t
Packed和Unpacked數(shù)組作為子程序的參數(shù)
數(shù)組可以作為參數(shù)傳遞給子程序,當(dāng)數(shù)組作為值傳遞給子程序時,會將這個數(shù)組復(fù)制一份傳遞給子程序。
task trial (int a[3:1][3:1]); //’a’ is a two-dimensional array
//(2-D unpacked)
上面是一個SystemVerilog task聲明的示例,該task會將一個2維unpacked數(shù)組作為參數(shù)值傳遞。
int b[3:1][3:1]; // OK: same type, dimension, and size
int b[1:3][0:2]; // OK: same type, dimension, & size
// (different ranges)
logic b[3:1][3:1]; // ERROR: incompatible element type
// (logic vs. int)
event b[3:1][3:1]; // ERROR: incompatible type (event
vs. int)
int b[3:1]; // ERROR: incompatible number of dimensions
int b[3:1][4:1]; // ERROR: incompatible size (3 vs. 4)
-
Verilog
+關(guān)注
關(guān)注
28文章
1366瀏覽量
111812 -
數(shù)組
+關(guān)注
關(guān)注
1文章
419瀏覽量
26368
原文標(biāo)題:SystemVerilog中數(shù)組的賦值、索引和切片
文章出處:【微信號:芯片驗證工程師,微信公眾號:芯片驗證工程師】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
在testbench中如何使用阻塞賦值和非阻塞賦值

給uint32_t數(shù)組填充整型值,除使用循環(huán)賦值外有沒有c庫函數(shù)可以實現(xiàn)?
FIB聚焦離子束切片分析

創(chuàng)建唯一索引的SQL命令和技巧
Labivew 實現(xiàn)鼠標(biāo)在數(shù)組中選中元素時,精準(zhǔn)的顯示所在位置的行、列值方法
什么是半導(dǎo)體芯片的失效切片分析?

數(shù)組名之間可以直接賦值嗎
指針數(shù)組和二維數(shù)組有沒有區(qū)別
C語言數(shù)組應(yīng)用計算機(jī)導(dǎo)論A第6講:數(shù)組
labview按行讀取二維數(shù)組之后再按讀取順序重新組成二維數(shù)組如何實現(xiàn)?
MATLAB中的矩陣索引

labview字符串數(shù)組轉(zhuǎn)化為數(shù)值數(shù)組
一文了解MySQL索引機(jī)制

ClickHouse內(nèi)幕(3)基于索引的查詢優(yōu)化

評論