【问题标题】:moving 8bit integers array to 32bit array assembly将 8 位整数数组移动到 32 位数组组件
【发布时间】:2014-03-01 20:07:04
【问题描述】:

我不知道你应该如何从 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 Studio)

【问题讨论】:

  • 如果这是一个组装问题,那么您最好指定您的目标架构。 x86、x64、ARM(6/11)等...
  • 哎呀!谢谢,编辑它说哪个架构。
  • 您的问题缺少更多细节:“整数”的大小是多少?第一个数组中的每个字节如何与第二个数组中的双字相关?

标签: arrays assembly x86


【解决方案1】:

您的代码几乎是正确的。您设法从字节数组中获取值并将它们转换为 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.

【讨论】:

    猜你喜欢
    • 2013-09-18
    • 2014-10-07
    • 1970-01-01
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    • 2014-10-25
    • 1970-01-01
    • 2011-02-27
    相关资源
    最近更新 更多