将数组视为内存块
数组中的数据连续存储在内存中。文件(数组)指令通常需要通过数组中的起始地址和长度,来确定指令读取或写入的元素和元素数量。
小贴士:
如果指令尝试读取超出数组末尾的数据,指令会读取该处的数据,并将其作为有效数据进行处理(不发生错误)。如果指令尝试写入超出数组末尾的数据,则将发生严重故障(类型 4,代码 20)。
这些指令将数组数据作为连续的内存块进行处理(其余指令将数组数据作为单独的元素处理):
控制器对数组数据的存储方式
下表通过示例展示了在将数据视为元素集时各元素的排列顺序。
一维数组元素(升序) | 二维数组元素(升序) | 三维数组元素(升序) | |
one_d_array[0] one_d_array[1] one_d_array[2] one_d_array[3] one_d_array[4] one_d_array[5] one_d_array[6] 对于一维数组 tag_name[subscript_0],subscript_0 递增至最大值。 | two_d_array[0,0] two_d_array[0,1] two_d_array[0,2] two_d_array[0,3] two_d_array[0,4] two_d_array[1,0] two_d_array[1,1] two_d_array[1,2] two_d_array[1,3] two_d_array[1,4] two_d_array[2,0] two_d_array[2,1] two_d_array[2,2] two_d_array[2,3] two_d_array[2,4] two_d_array[3,0] two_d_array[3,1] two_d_array[3,2] two_d_array[3,3] two_d_array[3,4] 对于二维数组, tag_name[subscript_0,subscript_1],subscript_0 保持为 0,而 subscript_1 由 0 递增至最大值。subscript_0 随后递增 1(如果第 0 维大于 1),并保持不变,而 subscript_1 再次在其范围内递增。此模式一直持续到两个下标达到最大值。 | three_d_array[0,0,0] three_d_array[0,0,1] three_d_array[0,0,2] three_d_array[0,0,3] three_d_array[0,1,0] three_d_array[0,1,1] three_d_array[0,1,2] three_d_array[0,1,3] three_d_array[0,2,0] three_d_array[0,2,1] three_d_array[0,2,2] three_d_array[0,2,3] three_d_array[1,0,0] three_d_array[1,0,2] three_d_array[1,0,3] three_d_array[1,1,0] three_d_array[1,1,1] three_d_array[1,1,2] three_d_array[1,1,3] three_d_array[1,2,0] three_d_array[1,2,1] three_d_array[1,2,2] three_d_array[1,2,3] 对于三维数组 tag_name[subscript_0, subscript_1, subscript_2],subscript_0 保持为 0,而 subscript_1 和 subscript_2 以与二维数组类似的方式递增。subscript_0 随后递增 1(如果第 0 维大于 1),并保持不变,直至 subscript_1 和 subscript_2 达到各自最大值。此模式一直持续到全部三个下标达到最大值。 | |
更改的维度
AVE、SRT 和 STD 指令有一个“更改的维度”操作数。该指令通过该操作数来计算偏移量,从而确定要读写的数组元素。
数组 | Dimension to vary | 偏移 |
一维 | 0 | 1 |
二维 | 0 | dimension_1 |
1 | 1 | |
三维 | 0 | (dimension_1) ? (dimension_2) |
1 | dimension_2 | |
2 | 1 |
提供反馈