News:

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

Testing Memory Location for Zero/Minus

Started by msmith, March 19, 2006, 07:17:20 AM

Previous topic - Next topic

msmith

I cannot find an X386 instruction to test a memory location for Zero/Minus.

Is there a single instruction solution to do this?

zooba

No. You'll need to compare with zero and then jump/set/cmov depending on the result.

msmith

Thanks zooba,

The rules for a FOR loop require that I know which branch (greater or less) depending on the step arg. In this case the step arg is a constant, but it could just as well be a var.

It turns out that I could just load it into ebx as follows:


; LN:12 for i=10 to 1 step -2
mov eax,10
mov [i],eax
mov eax,1
mov [_LopVec1],eax
mov eax,0
mov edx,2
sub eax,edx
mov [_LopVec1+4],eax
_Lbl6:
mov eax,[i]
mov ebx,[_LopVec1+4]
or ebx,ebx
js _Lbl9
cmp eax,[_LopVec1]
jg _Lbl8
jmp _Lbl10
_Lbl9:
cmp eax,[_LopVec1]
jl _Lbl8
_Lbl10:


Would it be better to replace:

mov ebx,[_LopVec1+4]
or ebx,ebx


With...


cmp [_LopVec1+4],0


This also seems to work, but since what i really need to know is the sign of the step arg, the or ebx,ebx seems more straightforward.

zooba

If it comes down to speed, you'd just have to benchmark it. If this is part of your compiler, it's probably not worth it. Personally, I'd use cmp mem, 0, simply to save the register.