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 


[ASM] Which one runs faster?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
VolatileAce
Cheater
Reputation: 0

Joined: 19 Mar 2009
Posts: 30
Location: 0001001100110111

PostPosted: Tue Mar 24, 2009 8:06 pm    Post subject: [ASM] Which one runs faster? Reply with quote

I'd appreciate it if anyone can point out the faster code (or are generally the same and is dependent on CPU given) and give a brief explanation. Thanks.

Both of the codes assign z the smaller of the two values, x and y.
Code:
00D035C3  mov         eax,dword ptr [x]
00D035C6  sub         eax,dword ptr [y]
00D035C9  mov         ecx,dword ptr [x]
00D035CC  xor         edx,edx
00D035CE  cmp         ecx,dword ptr [y]
00D035D1  setl        dl   
00D035D4  neg         edx 
00D035D6  and         eax,edx
00D035D8  add         eax,dword ptr [y]
00D035DB  mov         dword ptr [z],eax

Code:
00D035DE  mov         eax,dword ptr [x]
00D035E1  cmp         eax,dword ptr [y]
00D035E4  jle         main+61h (0D035F1h)
00D035E6  mov         ecx,dword ptr [y]
00D035E9  mov         dword ptr [ebp-0E8h],ecx
00D035EF  jmp         main+6Ah (0D035FAh)
00D035F1  mov         edx,dword ptr [x]
00D035F4  mov         dword ptr [ebp-0E8h],edx
00D035FA  mov         eax,dword ptr [ebp-0E8h]
00D03600  mov         dword ptr [z],eax
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Tue Mar 24, 2009 8:25 pm    Post subject: Reply with quote

i would say second one because movs are pretty much the fastest instructions. however if you look on masm forums there are some nice code timing macros that you can use. or i think it is already in one of the libraries included when you install masm but i just never used them
Back to top
View user's profile Send private message
DoomsDay
Grandmaster Cheater
Reputation: 0

Joined: 06 Jan 2007
Posts: 768
Location: %HomePath%

PostPosted: Wed Mar 25, 2009 5:14 am    Post subject: Reply with quote

This first would be faster;
This would be even faster:
Code:
mov    eax,dword ptr [x]
mov    ecx,dword ptr [y]
cmp    eax,ecx
cmovg  eax,ecx
mov    dword ptr [z],eax
Back to top
View user's profile Send private message
arigity
Advanced Cheater
Reputation: 0

Joined: 03 Jul 2008
Posts: 65
Location: middle of nowhere.

PostPosted: Wed Mar 25, 2009 7:39 am    Post subject: Reply with quote

second ones faster.
_________________
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 programming 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