Just as the title says I have a question with a program I am doing. I am just starting out using MASM assembly and kind of stuck any help would be great.

I need to calculate the sums and differences of arrays that are shown below. The little bit of code i have now is

.data
x sword 10,20,30,40,50,60,70,80
y sword -80,-70,-60,-50,-40,-30,-20,-10
a sword 8 dup (?)
b sword 8 dup (?)

.code
begin:
mov esi,offset x
mov edi,offset a
mov ecx,lengthof x

mov ebx,offset y
mov edi,offset b
mov ecx,lengthof y

next:
mov ah,[esi]
mov [edi],ah
add esi
add edi
loop next

else:
move al,[ebx]
mov [edi],al
add ebx
add edi
loop else

invoke exitProcess,0
end begin

First, line 10 uses EDI for a, in line 14 EDI is b. Overwriting the command in line 10.


I would have written

begin procedure near
mov ESI, offset X     ; or   LEA ESI, X
mov EDI, offset Y     ; or   LEA EBX, Y
mov EBX, offset a
mov EDX, offset b
mov ECX, lengthof X   ;  or mov ecx,8   ;counter

next:
mov AX,[ESI]        ; X[k]
add AX,[EDI]        ; add Y[k]
mov [EBX],AX        ; store sum

mov AX,[ESI]
sub AX,[EDI]
mov [EDX],AX       ; store X[k]-Y[k],

add ESI,2
add EDI,2
add EBX,2
add EDX,2
  dec ECX
  jg  next           ; do again if ecx >0

invoke exitProcess,0
begin endp
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.