Thread overview
asm: ja and jae mixed up?
Aug 14, 2005
Thomas Kühne
Aug 15, 2005
Dave
Aug 15, 2005
Dave
Aug 15, 2005
Thomas Kühne
Aug 15, 2005
Thomas Kühne
Aug 15, 2005
Walter
August 14, 2005
Instruction - Description
JA	- Jump if above (CF=0 and ZF=0).
JAE 	- Jump if above or equal (CF=0).

Am I missing something or should the values for test_jae be
(test_ja - 1)?

int test_ja(int i){
	asm{
		mov EAX, 0;

	loop_start:
		add EAX, 1;
		cmp i, EAX;
		ja loop_start;

		mov i, EAX;
	}
	return i;
}

int test_jae(int i){
	asm{
		mov EAX, 0;

	loop_start:
		add EAX, 1;
		cmp i, EAX;
		jae loop_start;

		mov i, EAX;
	}
	return i;
}

int main(){
	for(int i=0; i<5; i++){
		printf("[%i] ja:%i - jae:%i\n", i,
			test_ja(i), test_jae(i));
	}
	return 0;
}

Output:
[1] ja:1 - jae:2
[2] ja:2 - jae:3
[3] ja:3 - jae:4
[4] ja:4 - jae:5

Expected Output:
[1] ja:2 - jae:1
[2] ja:3 - jae:2
[3] ja:4 - jae:3
[4] ja:5 - jae:4

Thomas
August 15, 2005
In article <ddoimh$2m8n$1@digitaldaemon.com>, =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= says...
>
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Instruction - Description
>JA	- Jump if above (CF=0 and ZF=0).
>JAE 	- Jump if above or equal (CF=0).
>
>Am I missing something or should the values for test_jae be
>(test_ja - 1)?
>

It looks like it is working correctly, as:

cmp i, EAX;
ja loop_start; // Branch if i > EAX

cmp i, EAX;
jae loop_start; // Branch if i >= EAX

- Dave

>int test_ja(int i){
>	asm{
>		mov EAX, 0;
>
>	loop_start:
>		add EAX, 1;
>		cmp i, EAX;
>		ja loop_start;
>
>		mov i, EAX;
>	}
>	return i;
>}
>
>int test_jae(int i){
>	asm{
>		mov EAX, 0;
>
>	loop_start:
>		add EAX, 1;
>		cmp i, EAX;
>		jae loop_start;
>
>		mov i, EAX;
>	}
>	return i;
>}
>
>int main(){
>	for(int i=0; i<5; i++){
>		printf("[%i] ja:%i - jae:%i\n", i,
>			test_ja(i), test_jae(i));
>	}
>	return 0;
>}
>
>Output:
>[1] ja:1 - jae:2
>[2] ja:2 - jae:3
>[3] ja:3 - jae:4
>[4] ja:4 - jae:5
>
>Expected Output:
>[1] ja:2 - jae:1
>[2] ja:3 - jae:2
>[3] ja:4 - jae:3
>[4] ja:5 - jae:4
>
>Thomas
>-----BEGIN PGP SIGNATURE-----
>
>iD8DBQFC/85z3w+/yD4P9tIRAhiUAKCJYfdnSFhabu94P9RxWVphK0mfbACfSeBT
>LiPZDlCebBXii6MBAo771d0=
>=NuUY
>-----END PGP SIGNATURE-----


August 15, 2005
In article <ddp4gv$1gf$1@digitaldaemon.com>, Dave says...
>
>In article <ddoimh$2m8n$1@digitaldaemon.com>, =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= says...
>>
>>-----BEGIN PGP SIGNED MESSAGE-----
>>Hash: SHA1
>>
>>Instruction - Description
>>JA	- Jump if above (CF=0 and ZF=0).
>>JAE 	- Jump if above or equal (CF=0).
>>
>>Am I missing something or should the values for test_jae be
>>(test_ja - 1)?
>>
>
>It looks like it is working correctly, as:
>
>cmp i, EAX;
>ja loop_start; // Branch if i > EAX
>
>cmp i, EAX;
>jae loop_start; // Branch if i >= EAX
>
>- Dave

Oh yea - jg or jge would be better to use because they are for signed operands (ja, jae are for unsigned).


August 15, 2005
Dave schrieb:
> In article <ddoimh$2m8n$1@digitaldaemon.com>, =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= says...
> 
> Instruction - Description
> JA	- Jump if above (CF=0 and ZF=0).
> JAE 	- Jump if above or equal (CF=0).
> 
> Am I missing something or should the values for test_jae be
> (test_ja - 1)?
> 
> 
> 
>> It looks like it is working correctly, as:
> 
>> cmp i, EAX;
>> ja loop_start; // Branch if i > EAX
> 
>> cmp i, EAX;
>> jae loop_start; // Branch if i >= EAX

A rewrite of the test code:

=====
uint asm_ja(uint i){
	asm{
		mov EAX, 0;

	loop_start:
		add EAX, 1;
		cmp i, EAX;
		ja loop_start;

		mov i, EAX;
	}
	return i;
}

uint d1_ja(uint i){
	uint x=0;

	do{
		x+=1;
	}while(!(x>i))

	return x;
}

uint d2_ja(uint i){
	uint x=0;

	do{
		x+=1;
	}while(!(i>x))

	return x;
}

int main(){
	for(uint i=2; i<10; i++){
		printf("[%i]\td1:%i\td2:%i\tasm:%i\n",
			i, d1_ja(i), d2_ja(i), asm_ja(i));
	}
	return 0;
}
=====

Output:
[2]     d1:3    d2:1    asm:2
[3]     d1:4    d2:1    asm:3
[4]     d1:5    d2:1    asm:4
[5]     d1:6    d2:1    asm:5
[6]     d1:7    d2:1    asm:6
[7]     d1:8    d2:1    asm:7
[8]     d1:9    d2:1    asm:8
[9]     d1:10   d2:1    asm:9

Neither d1 - "do ... while(!(x>i))" - nor
d2 - "do ... while(!(i>x))" - yields the same results as asm's
"ja loop_start;".

Am I a bit dense?

Thomas
August 15, 2005
In article <ddpcbj$7if$1@digitaldaemon.com>, =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= says...
>

*smashing head against the wall*

never mind


August 15, 2005
"Thomas Kühne" <Thomas_member@pathlink.com> wrote in message news:ddpsop$net$1@digitaldaemon.com...
> In article <ddpcbj$7if$1@digitaldaemon.com>,
=?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?=
> says...
>
> *smashing head against the wall*
>
> never mind

We all have days like that <g>

P.S. An easier way to see if the code gen is correct for inline assembler is
to run:
    obj2asm -o foo.obj
on it, and compare the opcode with the Intel manuals (which can be
downloaded from www.intel.com).