Arrays 获取程序集中数组元素的索引
首先让我说,我知道我不应该粗暴地强制执行程序,但我有点陷入了僵局,目的是使用一个数组的元素基本上“排序”另一个数组的元素 鉴于: 开始=1 字符:H,A,C,E,B,D,F,G 链接:0,4,5,6,2,3,7,0 从第一个元素A开始,也是links数组中的数字4,它指向chars数组中的字母B,依此类推。字符按字母顺序存储在一个新数组中,我在每一步之后都很难得到字符数组的索引号,也许代码会显示出更多我遇到的问题Arrays 获取程序集中数组元素的索引,arrays,assembly,x86,masm,irvine32,Arrays,Assembly,X86,Masm,Irvine32,首先让我说,我知道我不应该粗暴地强制执行程序,但我有点陷入了僵局,目的是使用一个数组的元素基本上“排序”另一个数组的元素 鉴于: 开始=1 字符:H,A,C,E,B,D,F,G 链接:0,4,5,6,2,3,7,0 从第一个元素A开始,也是links数组中的数字4,它指向chars数组中的字母B,依此类推。字符按字母顺序存储在一个新数组中,我在每一步之后都很难得到字符数组的索引号,也许代码会显示出更多我遇到的问题 INCLUDE Irvine32.inc start = 1
INCLUDE Irvine32.inc
start = 1
.data
chars BYTE 'H','A','C','E','B','D','F','G'
links DWORD 0,4,5,6,2,3,7,0
array BYTE 0,0,0,0,0,0,0,0
.code
main PROC
mov al, chars +1
mov array, al
mov esi, start ; moves the start location into the esi register
mov eax, [links + 4] ; moves the second element of the array into eax
mov dl, chars[eax] ; moves the character element of the array chars into dl
mov array[esi], dl ; moves the character into the array
inc esi
mov eax, [links + 16]
mov dl, chars[eax]
mov array[esi], dl
inc esi
mov eax, [links + 8]
mov dl, chars[eax]
mov array[esi], dl
inc esi
mov eax, [links + 20]
mov dl, chars[eax]
mov array[esi], dl
inc esi
mov eax, [links + 12]
mov dl, chars[eax]
mov array[esi], dl
inc esi
mov eax, [links + 24]
mov dl, chars[eax]
mov array[esi], dl
inc esi
mov eax, [links + 28]
mov dl, chars[eax]
mov array[esi], dl
inc esi
main ENDP
END main
所以我想如果我知道如何在“links”数组指向它之后得到数组元素的索引,我想我可以把它放入一个循环中,我只需要知道如何做到这一点
mov al, chars +1
mov array, al
mov esi, start ; moves the start location into the esi register
mov ebx, offset links
Again:
mov eax, [ebx + esi*4] ; moves the next element of the array into eax
mov dl, chars[eax] ; moves the character element of the array chars into dl
mov array[esi], dl ; moves the character into the array
inc esi
通过测试ESI寄存器,重复此代码所需次数
您可以通过从0开始而不是从1来改进此代码。它将消除顶部的两条线。它需要修改链接的定义
links DWORD 1,4,5,6,2,3,7,0
只需将偏移量存储到寄存器中。此外,请使用索引寻址模式。