VHDL 阵列类型 - 2023.2 简体中文

Vivado Design Suite 用户指南: 逻辑仿真 (UG900)

Document ID
UG900
Release Date
2023-10-18
Version
2023.2 简体中文

VHDL 阵列在 C/C++ 中呈现为 C/C++ 类型的阵列,此 C/C++ 类型表示 VHDL 阵列的元素类型。下表显示了 VHDL 阵列及其 C/C++ 等效类型的示例。

表 1. VHDL 阵列及其 C/C++ 等效类型
VHDL 阵列类型 C/C++ 阵列类型
std_logic_vectorstd_logic 的阵列) char [ ]
bit_vectorbit 的阵列) char [ ]
stringcharacter 的阵列) char [ ]
integer 的阵列 int [ ]
real 的阵列 double [ ]

VHDL 阵列在 C/C++ 中的组织方式为:VHDL 阵列的左侧索引映射到 C/C++ 阵列元素 0,右侧索引映射到 C/C++ 元素 <阵列大小> - 1。

表 2. VHDL 阵列映射到 C/C++
C/C++ 阵列索引 0 1 2 <阵列大小> - 1
VHDL 阵列(left TO right)索引 left left + 1 left + 2 right
VHDL 阵列(left DOWNTO right)索引 left left – 1 left – 2 right

代码示例:

// For the following VHDL definitions
// signal slv : std_logic_vector(7 downto 0);
// signal bv : bit_vector(3 downto 0);
// signal s : string(1 to 11);
// type IntArray is array(natural range <>) of integer;
// signal iv : IntArray(0 to 3);
// do the following assignments
//
// slv <= "11001010";
// bv <= B"1000";
// s <= "Hello world";
// iv <= (33, 44, 55, 66); 
const unsigned char slvVal[] = {3, 3, 2, 2, 3, 2, 3, 2}; // 3 = '1', 2 = '0'
loader.put_value(slv, slvVal);
const unsigned char bvVal[] = {1, 0, 0, 0};
loader.put_value(bv, bvVal);
const char sVal[] = "Hello world"; // ends with extra '\0' that XSI ignores
loader.put_value(s, sVal);
const int ivVal[] = {33, 44, 55, 66};
loader.put_value(iv, ivVal);