Here is my implementation of strlne() function in MASM. But it doesn't work as it should :

strleng PROC string:DWORD
LOCAL pointer:DWORD
LOCAL ssize:DWORD
mov ssize,0
push string
pop pointer
mov dl, BYTE PTR
.WHILE dl != 0
inc pointer
mov dl, BYTE PTR
inc ssize
.ENDW
mov eax,ssize
ret
strleng ENDP

I think that this should work perfectly, but still it doesn't work. Any sugestion?
Posted on 2001-11-28 15:14:43 by maksimov
Try using registers instead of the locals.

so it will go more like...

WARNING UNTESTED!!

strleng PROC USES esi string:DWORD
xor eax, eax
mov esi, string

.WHILE (BYTE PTR ) ;;Not sure of the syntax here
inc eax
inc esi
.ENDW
ret

play with it a bit :)
====================
arrrrrg! where did the
 tag go :(
Posted on 2001-11-28 15:31:50 by rafe
Yap it works with registers but not with locals. Any idea why is it like that?
Posted on 2001-11-28 15:41:46 by maksimov
To fix your approach try this:
strleng PROC string:DWORD 

LOCAL pointer:DWORD
LOCAL ssize:DWORD
mov ssize,0
push string
pop pointer
; this doesn't do what you want: mov dl, BYTE PTR [pointer]
mov eax, pointer
mov dl,[eax]
.WHILE dl != 0
inc pointer
mov eax, pointer ; these two lines replace the one bad one.
mov dl,[eax]
inc ssize
.ENDW
mov eax,ssize
ret
strleng ENDP
Posted on 2001-11-28 15:57:45 by bitRAKE
maksimov, the problem with your original code is that you think
"mov dl, BYTE PTR " means "get the value of pointer, and
get the byte this points to", while you in fact only get a (byte of)
the pointer.

You should know that "inc pointer" and "inc " does the same
thing. Masm allows you to skip the because... well, dunno.
Some people think it's smarter. But brackets or not, it has the same
effect.
Posted on 2001-11-28 16:02:51 by f0dder
Aha, so brackets for the variable are like variable for it self :grin:
While brackets on register meanse "from memory location" :alright:

Did I get this right?
Posted on 2001-11-28 20:22:36 by maksimov
Yep. You see, a variable is nothing but an offset really, so it makes
sense to add the brackets so you can clearly see you're dealing
with memory... just as with registers. Some might claim that this
is only for newbies, but I still prefer it. Makes it easier to see what's
going on when you scan quickly through large sections of source.
Posted on 2001-11-28 20:54:26 by f0dder
Yap thanks I got it now :alright:
Posted on 2001-11-28 20:59:16 by maksimov