2014-03-01 97 views
1

我被困在如何從8位BYTE數組中取出十進制整數,並以某種方式設法將它們移動到循環內的32位DWORD數組中。我知道它必須在OFFSET和Movezx上做些事情,但理解起來有點混亂。有沒有任何有用的提示讓新手理解它? 編輯: 例如:將8位整數數組移動到32位數組程序

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)

+0

如果它是一個組合的問題,那麼你最好註明你的目標是什麼架構。 x86,x64,ARM(6/11)等... –

+0

哎呀!謝謝,編輯它說哪個架構。 – Biowin92

+0

您的問題缺乏更多細節:「整數」的大小是多少?第一個數組中的每個字節如何與第二個字中的雙字相關? – m0skit0

回答

1

你的代碼幾乎是正確的。您設法從字節數組中獲取值並將它們轉換爲雙字。現在你只需要把它們放在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.