Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Confusing Assembly instructions

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
Corruptor
Advanced Cheater
Reputation: 3

Joined: 10 Aug 2011
Posts: 82

PostPosted: Wed May 08, 2013 1:01 pm    Post subject: Confusing Assembly instructions Reply with quote

Hi there, im back with assembler im to stupid to understand for.

Code:
worldedit.exe+1158A9 - 33 C0                 - xor eax,eax
worldedit.exe+1158AB - 39 82 18020000        - cmp [edx+00000218],eax
worldedit.exe+1158B1 - 5E                    - pop esi
worldedit.exe+1158B2 - 0F95 C0               - setnc al
worldedit.exe+1158B5 - C3                    - ret


[edx+218] is a flag that either is 0 or 1 (a bool if you will). Because of the xor eax,eax, eax is always 0, so the cmp seemingly compares the flag to 0. The function is supposed to return 0 when the flag is 0 and 1 if the flag is 1. Why not just return the flag itself? boolean-paranoia i guess.

However, i wonder how this works. A cmp is a subtraction, so it subtracts eax from the flag and sets the flags according to this subtraction. The Carry flag is the flag that is set when an overflow occurs (unlike the overflow flag, which is set when the msb is changed... douh)

But subtracting a zero from anything will never change the value and could thus never result in the carry flag being set, so setnc should always set al to 1. However, somehow the carry flag IS set when the cmp kicks in. Why does this happen?
Back to top
View user's profile Send private message
TsTg
Master Cheater
Reputation: 5

Joined: 12 Dec 2012
Posts: 340
Location: Somewhere....

PostPosted: Fri May 10, 2013 11:21 am    Post subject: Reply with quote

because the CMP command will compare between the values in [edx+00000218] and in EAX(which is always zero), if they are equal: the ZERO or (Z) flag is set to 1, if not equal, the Z flag is set to 0, this flag is what a following conditional jump decides what to do (jump or don't), this doesn't have a relation with the value in AL as actually it's a part of eax's value (ex: eax = 00342015, then AL = 15), the SETNC will set it's value to 1, but the Z flag is not touched.


ZF.png
 Description:
 Filesize:  14.05 KB
 Viewed:  3421 Time(s)

ZF.png


Back to top
View user's profile Send private message
Corruptor
Advanced Cheater
Reputation: 3

Joined: 10 Aug 2011
Posts: 82

PostPosted: Sat May 11, 2013 4:08 pm    Post subject: Reply with quote

setnc is short for "set if not carry", so it's supposed to check the carry flag, not the zero flag. The zero flag is sort of insignificant for this case, isnt it?
Back to top
View user's profile Send private message
TsTg
Master Cheater
Reputation: 5

Joined: 12 Dec 2012
Posts: 340
Location: Somewhere....

PostPosted: Sun May 12, 2013 6:40 am    Post subject: Reply with quote

yes, the SETNC will change the value of AL to 1 if the Carry flag = 0 (or condition is true), or will set the AL to zero if the carry flag = 1 (condition false), the CMP instruction is the one that will change the value of the carry flag according to the compare result(equal or not), beside changing the zero flag.

So, in your code, the whole thing depends on the comparison instruction.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites