Kindly i try the following code below to compute the length of string but it doesn't work
when i execute it the program hang and exit
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib
strlo proto :DWORD
.data
msg db "Hello",0
.data?
pr dd ?
.code
start:
invoke strlo,addr msg
mov pr,eax
invoke StdOut,addr pr
invoke ExitProcess,0
strlo proc parm:DWORD
xor eax,eax
l1:
cmp parm,0
je l2
inc parm
inc eax
jmp l1
l2:
ret
strlo endp
end start
Apparently parm is a pointer to a string.
You are comparing the pointer with zero (wrong).
You should dereference the pointer. Read the value that is pointed at (the current string char) and not the pointer value.
Something like this:
mov esi,[param]
xor eax,eax
loop_len:
mov dl,[esi]
cmp dl,0
jz done
inc esi
inc eax
jmp loop_len
done:
ret
that is correct - you pass a pointer to the string
the StdOut function measures and returns the string length for you
(actually, it returns the number of bytes written to the console, which will be the same)
you can view the code by looking in masm32\m32lib\stdout.asm
you will see that the function calls StrLen
at any rate, i suspect what you are trying to do is to display the length of the string as a decimal value
INVOKE StrLen,offset msg
print ustr$(eax),13,10
inkey
exit
the print, ustr$, inkey, and exit macros may be found in masm32\macros\macros.asm
the StrLen function may be found in masm32\m32lib\strlen.asm
you can find descriptions in the masm32\help folder...
masmlib.chm
hlhelp.chm