ok im trying to write some code that will add up all the ascii codes on a string and then do some operations
so far i have

invoke lstrlen,String
mov ecx,eax
mov esi,String
mov al,
add Buffer,al
lea esi,
dec ecx
jnz loop

Buffer is a 16 byte 0 filled buffer
String is the string
also when i SetWindowText,hStatic,Buffer I get one char in the static only. what i want is the numbers behind it
Posted on 2001-08-24 18:36:17 by jeffro
Not too sure about your purpose here, but there is a couple mistakes in your code... the most obvious is your forgetting to use 'addr' to indicate the address of something...

1) invoke lstrlen,String
2) mov ecx,eax
3) mov esi,String
4) loop:
5) mov al,
6) add Buffer,al
7) lea esi,
8) dec ecx
9) jnz loop

1) needs help, it should be "invoke lstrlen, addr String"
3) should be "mov esi, offset String" (offset == addr )
you can do it this way, "lea esi, Sting"
5) This will now work as coded...
7) This is way over done.. replace it with "inc esi"

So your code should become..
invoke lstrlen, addr String

mov ecx, eax
lea esi, String ; or mov esi, offset String
mov al, [esi]
add Buffer, al
inc esi
dec ecx
jnz loop

Hope this helps....

Posted on 2001-08-24 18:53:55 by NaN
thanks nan for the fix on lstrlen
but lea esi, is actaully faster than inc esi
thanks though
Posted on 2001-08-24 19:39:52 by jeffro
To NaN,

"mov esi,offset String"

If you are passing parameter to proc it not really necessary to use 'offset/address is it? For example:

invoke MyProc,Address String
MyProc proc Data:DWORD

mov edi,Data

this puts address of String in edi I think.
Please correct me if I wrong.

best regards,

Posted on 2001-08-24 20:05:11 by czDrillard
jeffro: Thanx for the heads up, i stand corrected :) . I think i should take some time and learn some optomizations, its one area i still havent ventured into fully yet (and i never practice math ops with lea ~~ witch i hear is a real optomization in .586 modes)

czDrillard: Yes, as im understanding you, your correct. The if the function is made to assume that the value on the stack is an address, you can simply mov it into a register. This is the only way to pass into a function anything over 4 bytes long (in one param). However, in the example shown it doesn't suggest its wrapped up in a function so i took the example as litteral code, which accesses some global memory somewhere.

To be honest I feel that i may be misunderstanding you somehow, as I know your an experience MASM programmer, and this stuff is a bit simple in nature ?? Am i off course here?

Posted on 2001-08-25 00:40:44 by NaN

Your way is how I?d write it. I?ve got to chuckle whenever someone states ?this is quicker?
or ?this will save a few cycles? when the context is some little occasionally called do_loop.

Speed is important where it?s perceptual to the user. Other then that, do it in a way that works.

That?s what?s so fundamentally great about asm, it?s like words are to a book author. Asm gives
you the freedom to tell your story your way.:grin:
Posted on 2001-08-25 04:33:08 by bcraven