hi , i am new at masm
and i have some problems with a jump

i am brainbreaking my head on this and i can't figure out what the problem is.

i want to check if a small picture present is in a bigger picture
i use 2 pictures complete different from each other
the pictures i use have the bytesize1 = 360000 an bytesize2 = 5382
it should not jump out of the mainloop (comp:)
but it does, the amout of bytesize2
how come?

FindPic proc Pointer1:LONG,Pointer2:LONG,ByteSize1:LONG,ByteSize2:LONG

push ebx
push esi
push edi

mov esi,Pointer1
mov edx,Pointer2
mov ecx,ByteSize1

mov edi,0

comp:
mov bl,
rol ebx, 8
mov bl,
rol ebx, 8
mov bl,

mov al,
rol eax, 8
mov al,
rol eax, 8
mov al,

cmp eax,ebx
jz Equal

add esi,3
sub ecx,3
jns comp

Equal:
inc edi
add esi,3
add edx,3
sub ecx,3
cmp ByteSize2,edi
jne comp

mov eax,edi
pop edi
pop esi
pop ebx

ret

FindPic endp


Posted on 2008-07-21 15:14:11 by jpam
The procedure checks wheter there are at least 'ByteSize2' identical pixels present in both pictures, whatever their location. With enough large pictures, such condition has an extremely high chance to be true. Try comparing a completely blue image with a completely green one (or any other completely, absolutely, entirely different images, most preferably consisting of single colors).
Posted on 2008-07-21 17:27:44 by ti_mo_n
hi, thanks for looking at it

but i allready use 2 compleet different pictures
1 = complete white and 2 = complete green
i have tryed different colors for both of the pictures

eax and ebx should not be equal
and still it jumps 5382 times to Equal:
the size of bytesize2

Posted on 2008-07-22 01:17:31 by jpam
JNS means "jump if no Sign flag is set'
When the 'jns comp' finally fails due to ecx getting too small, execution moves on to the next opcode, which is your Equal: label ... then you manipulate ecx and edi and then perform another compare ... its this second compare that eventually breaks and lets you get to RET..

I'm saying that your code has two paths that allow it to reach the 'Equal' label, and i don't think thats what you intended... add a few lines after the JNS and before the Label to handle it.

As a beginner, you'll have a much nicer time using the 'highlevel masm directives' to control loops such as .repeat / .until and .while / .endw perhaps you should investigate those too.
Having said that, I can hear the knives coming out :P

Posted on 2008-07-22 07:49:22 by Homer
thx Homer
i did not notice that i had 2 paths to the Equal: label
i thought a label was only executed by a conditional jump
i am just a beginner , started only 3 weeks ago with masm :)

i changed the loop
picture 1 = 400X300
picture 2 = 49X36
now when i use 2 complete differrent pictures, the output is 0 pixels (good)
but when i use a picture that is 'in' the bigger picture, the output = 49 pixels
it should be 49*36 = 1764 pixels !

any clue ?

thanks in advance for any commemts !

FindPic proc Pointer1:LONG,Pointer2:LONG

local bytesize1:LONG
local bytesize2:LONG

push ebx
push esi
push edi

mov eax,Pointer1
mov esi,
mov ecx,

mov eax,Pointer2
mov edi,
mov edx,
mov bytesize2,edx

xor edx,edx

comp:
mov bl,
rol ebx, 8
mov bl,
rol ebx, 8
mov bl,

mov al,
rol eax, 8
mov al,
rol eax, 8
mov al,

.if eax==ebx
add edi,3
add esi,3
add edx,1
sub ecx,3
cmp bytesize2,edx
je endloop
.else
add esi,3
sub ecx,3
.endif
jns comp

endloop:
mov eax,edx

pop edi
pop esi
pop ebx

ret

FindPic endp

Posted on 2008-07-23 10:33:48 by jpam
First guess is a problem with line padding..? Try with images of size 48, 50, 47, 51, etc. and inspect how the results change.
Posted on 2008-07-24 12:29:43 by ti_mo_n
yes ,
used different sizes for the search picture
and my code only gives me the width of the search picture.
so if i use a picture of 50X50 pixels, the output is 50 pixels
75X100 the output is 75 pixels
100X200 the output is 100 pixels.

thats strange because de "jns comp"  must jump until ecx = -1
or if edx == bytesize2 (the total bytes of the search picture has reached)

i did the loop even with high level syntax (.while .enw)
and the output stays the same, even when i cut out the (edx == bytesize2) compare
so that it must process the amout of bytes of the source picture (360000 bytes)

my brains are cooking  :lol:


Posted on 2008-07-24 15:07:48 by jpam