PE4) Add Two Arrays And Store The Result In A New Array

Write a program that adds each value in the valueB array to the corresponding value in the valueD array and stores the result in the result array.

valueB BYTE 1,2,3,-1,-2,-3
valueD DWORD 6,5,4,3,2,1
result DWORD LENGTHOF valueD dup(0)

; Program Name:  Add Two Arrays and Store the result in a result array
; Description: 

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

.data
valueB BYTE 1,2,3,-1,-2,-3
valueD DWORD 6,5,4,3,2,1
result DWORD LENGTHOF valueD dup(0)

.code
main PROC
	mov eax, 0                               ;clarity purposes only
	mov ecx, LENGTHOF valueB                 ;loop counter: ecx = 6
	mov edi, 0
	mov esi, 0

L1:
	mov al, [valueB + esi * TYPE BYTE]       ;index scaling: al = first value in array
  movsx eax, al                            ;Must zero out the bytes and put it to larger register so we can add
	mov ebx,[valueD + esi * TYPE DWORD]      ;bx = first value in array
	mov result[edi], ebx					
	add result[edi], eax                     ;result = ebx+eax
	inc esi                                  ;inc by one because valueB is a BYTE.  
                                                 ;valueD is a dword but the *TypeDword 
                                                 ;takes care of that
	add edi, 4                               ;Add 4 because result is a DWORD
	loop L1

INVOKE ExitProcess,0
main ENDP
END main

Show Code