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 


Two questions about this short piece of code. Thanks.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Tue Mar 01, 2016 8:31 pm    Post subject: Two questions about this short piece of code. Thanks. Reply with quote

Code:

cmp edi,01
cmovl edi,eax
mov eax,00000064
cmp edi,64
cmovg edi,eax
call .......


Here are my questions:
1. why compare "edi" to "01" and "64", it seems redundant to me....
2. if I change "mov eax, 00000064" to "mov eax,64", would the result be the same?

Thanks a lot.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Tue Mar 01, 2016 9:47 pm    Post subject: Reply with quote

I am only assuming the instruction before all of this sets EAX to 1?

It first compares EDI to 1.
If EDI is less than 1, then it will move the value of EAX (possibly 1?) into EDI.
It then compares EDI against 100.
If EDI is greater than 100, it will move the value of EAX (100) into EDI.

This chunk of code appears to be verifying that the end result is EDI containing a number between 1 and 100.

Both of those move statements would be the same, yes.
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Tue Mar 01, 2016 11:43 pm    Post subject: Reply with quote

Zanzer wrote:
I am only assuming the instruction before all of this sets EAX to 1?

It first compares EDI to 1.
If EDI is less than 1, then it will move the value of EAX (possibly 1?) into EDI.
It then compares EDI against 100.
If EDI is greater than 100, it will move the value of EAX (100) into EDI.

This chunk of code appears to be verifying that the end result is EDI containing a number between 1 and 100.

Both of those move statements would be the same, yes.


You are right! The two lines of code above are:
Code:

mov eax,00000001
movzx edi,byte ptr [ecx+1A]

Does
Code:
cmp edi,01

works with:
Code:
cmovl edi,eax
?

Or, can I just use
Code:
cmovl edi,eax
?
I mean do I need to use cmp with cmovl, or can I just use cmovl? Doesn't cmovl mean "compare and move if less"?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25830
Location: The netherlands

PostPosted: Wed Mar 02, 2016 2:44 am    Post subject: Reply with quote

cmovl is "conditional move if less"
the previous cmp does the compare, the cmov<> instruction will get executed if it's condition has been met.

(so yes, the cmp is needed)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Wed Mar 02, 2016 11:01 am    Post subject: Reply with quote

Dark Byte wrote:
cmovl is "conditional move if less"
the previous cmp does the compare, the cmov<> instruction will get executed if it's condition has been met.

(so yes, the cmp is needed)

Oh, got it. Thank you.
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