Logo 
Search:

Assembly Language Forum

Ask Question   UnAnswered
Home » Forum » Assembly Language       RSS Feeds

Compute the sum of both positive and negative elements of an array

  Asked By: Art    Date: Nov 02    Category: Assembly Language    Views: 2852
  

Develop an 8086 assembly program that calculate the sum of both positive and negative
elements of a signed integer array.
Both the array and the two result variables (negative_sum_result and positive_sum_result) are stored in
memory.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Sergey Kamenev     Answered On: Nov 12

;Tested in FASM
format PE console
include 'win32a.inc'

mov esi,nD
mov ecx,[qcnD]
mov [negative_sum_result],0
mov [positive_sum_result],0
mSum:
cmp dword [esi],0
jg mNotNeg
mov eax,[negative_sum_result]
add eax,dword [esi]
mov [negative_sum_result],eax
mNotNeg:

cmp dword [esi],0
jl mNotPos
mov eax,[positive_sum_result]
add eax,dword [esi]
mov [positive_sum_result],eax
mNotPos:
add esi,4
loop mSum

invoke ExitProcess,0

nD dd 1,-2,-3,4,5,-6,-7,8,9,10
qcnD dd ($-nD)/4
negative_sum_result dd ?
positive_sum_result dd ?

include 'API\kernel32.inc'

data import

library kernel32,'KERNEL32.DLL'

end data

 




Tagged: