News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

what is wrong in this proc?

Started by hamidamel, November 30, 2009, 09:39:40 AM

Previous topic - Next topic

hamidamel

hi,im hamid
can you help me?

this proc should find substring within string.

what is wrong in this proc?


p2 proc near
       
    while2:
    inc esi
    cmp buffer1[esi],NULL
    jne while2
    mov len1,esi
    sub len1,2
   
   ; invoke MessageBox,NULL,str$(len1),ADDR msgt,NULL
    mov edi,0
    mov esi,0

    while1:
    cmp buffer1[esi],NULL
    je wexit1
       ; invoke MessageBox,NULL,str$(edi),ADDR msgt,NULL
        mov al,buffer2[edi]
        cmp buffer1[esi],al
        jne eif1
            invoke StdOut,chr$(13,10)
            invoke StdOut,str$(esi)
            invoke StdOut,chr$(13,10)
            invoke StdOut,str$(edi)
            inc esi
            inc edi
            mov k1,1
           
            cmp edi,len1
            jne eif2
                mov edi,0
                mov k,1
                add sum,1
               
            eif2:
            jmp while1
           
        eif1:
        cmp k1,1
        jne eif3
            mov edi,0
            mov k1,0
            jmp while1
        eif3:
            inc esi
    jmp while1
    wexit1:
     
cmp k,1
jne eif4
    print "hastesh"
    print str$(sum)
    ret
eif4:
    print "nistesh"
    print str$(sum)
    ret

p2 endp

Mirno

There are at least two things wrong with it, firstly you've not put it within code tags on the board so it's a pain to read.
Secondly the lables have stupid names that don't mean a whole lot.

There may of course be others, but given the first two I stopped reading.

Thanks,

Mirno

hutch--

Hi hamid,

I added the code tags so your post could be read but the code is pretty messy and to fix it the reader would need to write a test piece just to see what it is doing.

Put it into a working console mode test piece so that someoe who has the time can at least play with it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

there are more complex and faster algorithms to do this
but - to make it simple
1) search the string for the first character of the sub-string
2) if a match is found, compare the remaining characters of the sub-string