I have got a very interesting problem..


problem is:
there is a dword array.
Array dword 99999999, 11111111, 22222222, 33333333

how can we find the sum of all these members and display it as a string.

that is

Array[0]+Array[1]+Array[2]+Array[3] = ?

and result of this addition has to displayed as String.

bye
Posted on 2002-11-16 04:03:08 by processingspeed
This homework? Anyway I don't mind helping with homework, just won't do it for you.

Basically, if its a small array who's size you know befor hand then the answer is simple.

.data
Array dd 1111,9999,2222

.code
mov eax,Array[0]
add eax,Array[4]
add eax,Array[8]
invoke SomethingToTurnEaxIntoAString,......

If its a big array then the problem is more interesting as you need to use a loop. Read the ASMINTRO.hlp that come with Masm32 to learn how to do that :) . Then simply add up the numbers through the loop and after the loop convert them to a string.
Posted on 2002-11-16 05:49:14 by Eóin
E?in, Solving homework now are we? tsk,tsk! :grin: Hope he learned something.
What the hell, this works too.. I wonder why.. hehe :)


xor eax,eax
mov eax,[Array+0*4]
add eax,[Array+1*4]
add eax,[Array+2*4]
add eax,[Array+3*4]
invoke dwtoa,eax,addr ArrayStr ;<--- Convert's into a string
This does exactly the same operation.. ;)


xor eax,eax
mov eax,[Array+0]
add eax,[Array+2+2]
add eax,[Array+2+4+2]
add eax,[Array+4+2+2+4]
invoke dwtoa,eax,addr ArrayStr ;<--- Convert's into a string

NOTE: The funny part is that I actually didnt know this until he asked the question. And it took
me a couple of min's to find out on my own( tsk,tsk ).
Posted on 2002-11-16 06:32:19 by natas