2016-02-26 148 views
0

我有两个任务:汇编语言的x86欧文

  • 打印ar2
  • 移动的长度从ar1的元素ar2,由1

递增每一个项目,我需要帮助汇编语言x86 Irvine32。我必须做上面描述的这两件事情。我得到了第一个正确的,但我有点在第二个失败。你怎么做到这一点?这是我到目前为止有:

INCLUDE Irvine32.inc 

.data 

ar1 WORD 1,2,3 
ar2 DWORD 3 DUP(?) 

.code 
main PROC 

    mov eax, 0 
    mov eax, LENGTHOF ar2 

    mov bx, ar1 
    mov ebx, ar2 
    inc ebx 
    call DumpRegs 
    exit 
main ENDP 
END main 

回答

0

你必须从第一阵列读的话(每件商品都有的sizeof 2),并将其复制到包含DWORD值,第二个(每个项目都有的sizeof 4):

主PROC

mov ecx, LENGTHOF ar2   ; ECX should result in '3' 
    lea esi, ar1     ; source array  - load effective address of ar1 
    lea edi, ar2     ; destination array - load effective address of ar2 
loopECX: 
    movzx eax, word ptr [esi]  ; copies a 16 bit memory location to a 32 bit register extended with zeroes 
    inc eax      ; increases that reg by one 
    mov dword ptr [edi], eax  ; copy the result to a 4 byte memory location 
    add esi, 2     ; increases WORD array 'ar1' by item size 2 
    add edi, 4     ; increases DWORD array 'ar2' by item size 4 
    dec ecx      ; decreases item count(ECX) 
    jnz loopECX     ; if item count(ECX) equals zero, pass through 
           ; and ... 
    call DumpRegs     ; ... DumpRegs 
    exit 
main ENDP 
END main