The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: rufus16 on December 30, 2011, 06:35:36 PM

Title: Masm directives for signed comparision and other problems
Post by: rufus16 on December 30, 2011, 06:35:36 PM
Hello
Could someoen tell me how to change the comparision to get io worked?
I use masm.


.IF DWORD PTR[P+ECX*4] ==-1
;something

.ENDIF

P is an array with 10000 elements. I have filled  it with  -1 per byte, so it contains fffffffff. ffff  but anyway the comparision doesnt work.  COould someone tell me how to fix it?

And in native assembly, how it would look like? couldnt find anythint that would match " jump when signed and equal"

I have found one more problem, which might fix many others:



when i use something like that

DWORD PTR[P+ECX*4]

masm changes it to DWORD PTR[OFFSET P+ECX*4]
which i dont want to.

ANy idea how to fix it? ( it might fix the previous one because it was inteprpreted worng)


thanks in advanced
Title: Re: Masm directives for signed comparision and other problems
Post by: qWord on December 30, 2011, 06:45:52 PM
Overwrite the datatype with:
Quote.if SDWORD ptr ... </</<=/>= ...
.endif

When testing for equality, the singe doesn't matter.

The used jump-instructions for signed compares are:
jl/jle/jg/jge dest

For more details about conditional jumps see Intel's/AMD's documentation.
Title: Re: Masm directives for signed comparision and other problems
Post by: rufus16 on December 30, 2011, 07:16:27 PM

Then the  problem is here :

masm changes

IF DWORD PTR[P+ECX*4]

to

IF DWORD PTR[OFFSET P+ECX*4]


Do you knwo how to fix it?



Title: Re: Masm directives for signed comparision and other problems
Post by: jj2007 on December 30, 2011, 07:28:30 PM
Quote from: rufus16 on December 30, 2011, 07:16:27 PM

masm changes

IF DWORD PTR[P+ECX*4]

to

IF DWORD PTR[OFFSET P+ECX*4]



How does Masm change it??
What you probably mean is that you have a variable P like this:
.data
P dd 0
... and you want the value of [P+ecx*4]
That requires dereferencing:
mov edx, P
IF DWORD PTR[edx+ECX*4]
  ...
Title: Re: Masm directives for signed comparision and other problems
Post by: rufus16 on December 30, 2011, 07:34:33 PM
Eh, my lack of knowledge costs alot :|

Thanks for help
Title: Re: Masm directives for signed comparision and other problems
Post by: KeepingRealBusy on December 30, 2011, 10:46:48 PM
Rufus16,

Just keep reading this forum and keep asking questions when you have problems. Having a short working (whether it works correctly) code example to post along with your question also helps.

Learning is allowed here.

Dave.
Title: Re: Masm directives for signed comparision and other problems
Post by: dedndave on December 31, 2011, 12:30:20 AM
i can tell you how i would do it....

        cmp dword ptr P[4*ecx],-1
        jnz     dont_do_it


there, now wasn't that easy ?   :bg
Title: Re: Masm directives for signed comparision and other problems
Post by: Hobbit on December 31, 2011, 08:54:02 PM
Interesting, more than one way to skin a cat I guess.

Ralph