我纠结于您应该如何从 8 位 BYTE 数组中获取十进制整数,并以某种方式设法将它们移动到循环中的 32 位 DWORD 数组中。我知道它必须与OFFSET和Movezx有关,但是理解起来有点令人困惑。新手有什么有用的技巧来理解它吗?编辑:例如:
Array1 Byte 2, 4, 6, 8, 10
.code
mov esi, OFFSET Array1
mov ecx, 5
L1:
mov al, [esi]
movzx eax, al
inc esi
Loop L1
这是正确的方法吗?还是我完全做错了?它是组装x86。(使用Visual Studios)
你的代码几乎是正确的。您设法从字节数组中获取值并将它们转换为 dword。现在你只需要把它们放在dword数组中(甚至没有在你的程序中定义)。
无论如何,这里是(FASM 语法):
; data definitions
Array1 db 2, 4, 6, 8, 10
Array2 rd 5 ; reserve 5 dwords for the second array.
; the code
mov esi, Array1
mov edi, Array2
mov ecx, 5
copy_loop:
movzx eax, byte [esi] ; this instruction assumes the numbers are unsigned.
; if the byte array contains signed numbers use
; "movsx"
mov [edi], eax ; store to the dword array
inc esi
add edi, 4 ; <-- notice, the next cell is 4 bytes ahead!
loop copy_loop ; the human-friendly labels will not affect the
; speed of the program.