0
votes

I have two tasks:

  • Printing the length of ar2
  • Move the elements from ar1 to ar2, incrementing each item by 1

and I need help in Assembly Language x86 Irvine32. I have to do these two things which are described above. I got the first one correct, but I'm sort of lost in the second one. How do you do this? Here's what I have so far:

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
1

1 Answers

0
votes

You just have to read the WORDs(each item has sizeof 2) from the first array and copy them to the second one containing DWORDs(each item has sizeof 4):

main 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