Hi guys, Please clarify... Look at the code below .data mystr db "C:\Winnt\Profiles\Administrator\Personal", 0 hello db "Hello", 0 .code MyStrChr PROC pszStr:PTR BYTE, nChar:BYTE mov edx, pszStr mov ecx, edx .repeat invoke MessageBox, 0, addr hello, 0, 0 mov al, BYTE PTR .if al == nChar mov ecx, edx .endif inc edx .until al == 0 mov eax, ecx ret MyStrChr ENDP main: invoke MyStrChr, ADDR mystr, 92 ; 92 == '\' invoke MessageBox, 0, eax, 0, 0 invoke ExitProcess, 0 end main what i'm doing in the MyStrChr is to return the address of the last occurance of '\'. The messagebox to display hello is supposed to popup so many times as the number of characters present in the mystr string. But it doesn't. Any idea why.
Posted on 2001-06-22 08:13:00 by Superman_San
I think you need to put "invoke MessageBox" within the .if block, no?
Posted on 2001-06-22 08:34:00 by Larry Hammick
use MyStrChr PROC pszStrTR BYTE, nChar:DWORD for I think masm has problems with pushing of "byte" parameters in invoke
Posted on 2001-06-22 08:41:00 by japheth
use MyStrChr PROC pszStr:PTR BYTE, nChar:DWORD
Posted on 2001-06-22 08:41:00 by japheth
The registers eax, ecx, and edx are not necessarily preserved after function calls (opposite of ebx, esi, edi, which must be preserved). This means after you "invoke MessageBox", the contents of edx are no longer reliable. You need to either remove the message box function, or push ecx, and edx onto the stack before the call, then pop them off afterwards. Its a case of your debug screwing the actual app :P By the way, you can swap eax, for ecx, and avoid the mov eax, ecx at the end of your function! How your code needs to be (plus swapping eax for ecx):

MyStrChr PROC pszStr:DWORD, nChar:BYTE
  mov edx, pszStr
  mov eax, edx

  .repeat
    push eax
    push edx
    invoke MessageBox, 0, edx, 0, 0
    pop edx
    pop eax

    mov cl, BYTE PTR 
    .if cl == nChar
      mov eax, edx
    .endif

    inc edx
  .until cl == 0
  ret
MyStrChr ENDP
I also replaced "ADDR hello" with "edx" as it shows whats going on better! Mirno This message was edited by Mirno, on 6/22/2001 8:54:17 AM
Posted on 2001-06-22 08:44:00 by Mirno
ok, third time: MyStrChr proc pszStr:ptr byte,nChar:dword
Posted on 2001-06-22 08:54:00 by japheth
Thanks Mirno, I get it Clark
Posted on 2001-06-25 01:26:00 by Superman_San