Arrays 将8位整数数组移动到32位数组部件
我一直想知道如何从8位字节数组中提取十进制整数,然后在循环中设法将它们移动到32位DWORD数组中。我知道它与OFFSET和Movezx有关,但理解起来有点混乱。对于新手来说,有什么有用的提示可以让他们理解吗? 编辑: 例如:Arrays 将8位整数数组移动到32位数组部件,arrays,assembly,x86,Arrays,Assembly,X86,我一直想知道如何从8位字节数组中提取十进制整数,然后在循环中设法将它们移动到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 es
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 Studio)您的代码几乎正确。您设法从字节数组中获取值并将其转换为dword。现在,您只需将它们放入dword数组(该数组甚至没有在您的程序中定义) 无论如何,这里是(FASM语法):
;数据定义
阵列1分贝2,4,6,8,10
Array2路5号;为第二个数组保留5个DWORD。
; 代码
电影集1
mov edi,Array2
mov ecx,5
复制循环:
movzx-eax,字节[esi];此指令假定数字是无符号的。
; 如果字节数组包含带符号的数字,请使用
; “movsx”
mov[edi],eax;存储到dword数组
公司esi
增加edi,4;如果这是一个组装问题,那么您最好指定您的目标架构。x86、x64、ARM(6/11)等等……哎呀!谢谢,编辑它来说明哪种架构。你的问题缺少更多细节:一个“整数”的大小是多少?第一个数组中的每个字节如何与第二个数组中的一个双字相关联?
; 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.