Log in

View Full Version : Asm help: Opcode JNB xxxxx help needed


morlac
February 13th, 2001, 22:58
Hi guys,
Im faced with a problem.
How can i translate the JNB 'Jump not below' to C/C++ statement?
I tried the following:
if ( var < 3 ) {
statement1
} else {
statement2
}
but that translates to:
cmp var,3
jge ggg <-- should be 'jnb ggg'
statement1
ggg:
statement2

And according to the opcode docs 'JGE' is different from 'JNB'
so, what can i do?

Morlac.

The Owl
February 14th, 2001, 05:00
Quote:

so, what can i do?


maybe check the intel manuals (vol 2: instruction set, to be precise) and observe the difference between signed/unsigned compares (hint, hint ;-)).

morlac
February 14th, 2001, 07:52
Hi Owl,

I did check the manuals before i asked. I always do.

I tried unsigned/signed integer compares but still the same.
'JNB' seems to depened on CF, but how? I dont have a clue.

The Owl
February 14th, 2001, 11:26
hmmm.... guys, beat me if i understand what your problems are...


1. JNB is 'jump if not below', ie. when CF=0 (it's in the manual...).
CF is set to 0 for example by 'CMP' when the first operand is NOT BELOW
(ie. above or equal to) the second operand IF the values were being treated
as unsigned integers. CF is also set to 0 (cleared) by CLC for example.


2. JNB has two equivalent mnemonics: JAE (jump if above or equal) and
JNC (jump if no carry). it's quite logical (and confusing at first perhaps), since
they all test CF for the same value. an assembly programmer uses one over
the other to express what the purpose of the Jcc is: test for integer values
used in the program logic somewhere earlier or test for CF itself (which can
be used for signaling error from a previous function call as it is the case for
many DOS interrupts or VxD calls - just for example).


3. the following compiled by djgpp (gcc/dosx) will do what was asked for
(tweak the direction of the comparison and perhaps some optimization
flags if needed for your compiler):


int main()
{
unsigned int a,b;
if (a<b)
printf("a
";
}


the only thing you have to pay attention to is that BOTH sides of the comparison
should have the same signedness property (ie. a constant by deault is treated as
signed in c/c++, you have to either cast it or append a 'u' to make it unsigned).

morlac
February 14th, 2001, 22:07
Thanx guys.

I got it right this time.

Cheers.

morlac
February 16th, 2001, 08:57
Thanks alot for your time.
Hopefully ill return the favour sometime.

Morlac