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 


Question about CMP/Compare

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Stacktrace
Expert Cheater
Reputation: 1

Joined: 04 Jul 2015
Posts: 105

PostPosted: Tue May 10, 2016 10:31 pm    Post subject: Question about CMP/Compare Reply with quote

Hi, I'm pretty new to Assembly and I understand some of it. (Enough to make cheats.) But, for quite a while I've been pretty confused at how the compare works. I have an example of a code I'd like you to explain in a understandable way.

"cmp dword ptr [esi+3C],00
je GameProcess+AC25B4""

So my theory is, it's like English right? But from what I know in English w/e, I'd assume that code does

it compares if the value of ESI+3C is 0, and if it's '0' it will jump to "GameProcess+AC25B4" if it's for example '1' it will ignore the jump. Now, is that right? Haha, sorry if I'm stupid but I'm trying my best. I do have a learning disability so it's quite the challenge to figure it out.

If you're gonna help I'll appreciate it a lot Smile But please explain how I'm wrong (if i'm wrong) in a way even that those with learning disabilities will understand. So a short, easy way. Thanks! Very Happy
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Tue May 10, 2016 11:02 pm    Post subject: Reply with quote

You are correct.
Back to top
View user's profile Send private message
Stacktrace
Expert Cheater
Reputation: 1

Joined: 04 Jul 2015
Posts: 105

PostPosted: Wed May 11, 2016 3:43 am    Post subject: Reply with quote

++METHOS wrote:
You are correct.


Ah, that's awesome! Thanks man Smile

Edit: Hmm, I forgot about one.
"cmp eax,edi"
it doesn't get anything to compare from that one instruction, so how does that one work? I'm sure it's extremely obvious and I'm just being silly, but rather than believing my own conclusions, I'd rather know the answer. Thanks again Razz
Back to top
View user's profile Send private message
hhhuut
Grandmaster Cheater
Reputation: 6

Joined: 08 Feb 2015
Posts: 607

PostPosted: Wed May 11, 2016 3:49 am    Post subject: Reply with quote

Could you post a bit more code (or a screenshot maybe)?

Because
Code:
cmp eax,edi

simply compares eax with edi (as you may have guessed Wink).
Back to top
View user's profile Send private message
Stacktrace
Expert Cheater
Reputation: 1

Joined: 04 Jul 2015
Posts: 105

PostPosted: Wed May 11, 2016 3:53 am    Post subject: Reply with quote

hhhuut wrote:
Could you post a bit more code (or a screenshot maybe)?

Because
Code:
cmp eax,edi

simply compares eax with edi (as you may have guessed Wink).


Yeah, my bad. This will be my first time trying to attach an image, let's hope it'll work.

I should really brush up on my assembly knowledge, but your help will be very useful! Smile



21b3c30968378cecd97c2056ff944103.png
 Description:
 Filesize:  18.77 KB
 Viewed:  9111 Time(s)

21b3c30968378cecd97c2056ff944103.png


Back to top
View user's profile Send private message
hhhuut
Grandmaster Cheater
Reputation: 6

Joined: 08 Feb 2015
Posts: 607

PostPosted: Wed May 11, 2016 3:57 am    Post subject: Reply with quote

It's pretty much the same as in your first post.

The program compares both the registers (resp. their values) eax and edx and jumps to the function's end, if they have the same value.
If not, it executes all the code in between.
Back to top
View user's profile Send private message
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2676

PostPosted: Wed May 11, 2016 4:02 am    Post subject: Reply with quote

Yep.

If you want to learn conditional jumps properly, learn about flags. They govern which direction the jump will be taken. E.g je GameProcess+AC25B4"" is actually jz - jump if zero(flag) set.

CMP can also work like this
sub ecx, 0
jz 92ace

^That is perfectly fine instruction as and does the same thing
cmp ecx, 0
jz 92ace

The magic is FLAGS. They get set as different instructions are executed. Open Ollydbg and notice them, that is an awesome way to learn to see it in action and how i learned myself

These two resources look good to learn from
https://en.wikipedia.org/wiki/FLAGS_register
http://www.cavestory.org/guides/csasm/guide/asm_flags.html

_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
Stacktrace
Expert Cheater
Reputation: 1

Joined: 04 Jul 2015
Posts: 105

PostPosted: Wed May 11, 2016 4:02 am    Post subject: This post has 1 review(s) Reply with quote

hhhuut wrote:
It's pretty much the same as in your first post.

The program compares both the registers (resp. their values) eax and edx and jumps to the function's end, if they have the same value.
If not, it executes all the code in between.


Ah, thanks for your help! If I understood you correctly, that makes a lot of sense now.

So basically, if the compare doesn't have a ",00" at the end, but rather two registers without any value checking listed, it will compare if the value/addr for the two registers are the same? So,
cmp ecx,esi
je GameProcess+1

it checks if the value for ecx,esi is the same, and if it is the same, it'll jump to GameProcess+1 and if forexample ecx is 3, esi is 9 it'll ignore the jump and continue on within the function? Hopefully I'm not asking too many questions here, just want to make extra-sure I know what I'm doing Wink Greatly appreciate it!

(Ah, I did some reverse engineering to see if I understood you. I indeed did! Smile This all makes a lot more sense now, and thanks to STN I also now have more understanding within jumps, awesome!)

-------------------------------------------------------------
I can't double post, so here's my reply to STN
Thanks for the help! I'm glad I stumbled upon this forum, such a helpful community Smile I'll take a look at the sources you shared! Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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