4. Program for Copying a Word Array to a DoubleWord array in Assembly Langauge using Visual Studio

Chapter 4

Data Transfers, Addressing, and Arithmetic

Assembly Language Programming Exercise

Problem # 4:

Write a program that uses a loop to copy all the elements from an unsigned Word (16-bit) array into an unsigned doubleword (32-bit) array.

Solution:

.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD

.data
array WORD 0,2,5,9,10
newArray DWORD LENGTHOF array DUP(?)
.code
main PROC

  mov ecx, LENGTHOF array
  mov ESI, OFFSET array
  mov EDI, OFFSET newArray

  L1:
MOV EAX,0
MOV AX,[ESI]
MOV [EDI], EAX
ADD ESI, TYPE array
ADD EDI, TYPE newArray
  Loop L1

INVOKE ExitProcess,0
main ENDP
END main

Let me know in the comment section if you have any question.

Previous Post:
Summing the Gaps between Array Values
Next Post: