第一:在汇编代码级别,没有“数组”的概念,它只是由开发人员解释的位和字节。
对于您的示例来说,实现数组的最直接方法是将字符串分解为它们自己的块:
string1: db "abcd"
string2: db "efgh"
string3: db "ijkl"
string4: db "mnop"
string5: db "qrst"
您现在已经创建了单独的字符串块,可以将其作为一个单元单独引用。最后一步是通过一个新的数据元素声明“数组”,其中包含 5 个字符串中每个字符串的起始地址:
string_array: dq string1, string2, string3, string4, string5
上面现在保存了 5 个地址(每个地址占用 64 位)。
将数组的地址获取到代码段中某处的寄存器中。以下是遍历数组并获取每个字符串本身的相当残酷的方法:
xor rdx, rdx ; Starting at offset zero
lea rdi, [string_array] ; RDI now has the address of the array
mov rsi, [rdi+rdx] ; Get the address of string1
; Process String1
; Get next string
add rdx, 8 ; Get the next offset which is 64 bits
mov rsi, [rdi+rdx] ; Get the address of string2
; Process String2
; etc.
如果不知道您正在对数组做什么,您的代码方法可能会有所不同。