flat assembler
Message board for the users of flat assembler.

Index > Main > Fastest way to reset registers?

Author
Thread Post new topic Reply to topic
saigon



Joined: 29 May 2006
Posts: 62
saigon
Hello!

I am coding some little macros to help me out with big sources to reduce complexity. I always use some registers (mostly eax and ecx) to store some temporary data or something else. However, I always move 0 to the register, like this:
MOV eax, 0

The problem is, my code was faster before I added the move instructions, so I assume they need a little more clock cycles. What I want to ask is for a better way to reset a register to 0, as I am having 10% less the speed when using MOV.

Thanks!
Post 02 Jun 2006, 09:27
View user's profile Send private message Reply with quote
Ivan2k2



Joined: 08 Sep 2004
Posts: 80
Location: Russia, Angarsk
Ivan2k2
it is strange that MOV is slow for you...

try this:

xor eax,eax
and eax,0ffffffffh
sub eax,eax
Post 02 Jun 2006, 09:52
View user's profile Send private message ICQ Number Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
saigon, it's time to use 'search' option
Post 02 Jun 2006, 10:11
View user's profile Send private message Reply with quote
saigon



Joined: 29 May 2006
Posts: 62
saigon
@Ivan2k2: I tried all of them, it seems that "XOR eax, eax" is the fastest option. (And, I have too many macros to list and each of them uses MOV, so that's why it's slow)

@Vasilev: It's not time to use the search. I searched the board before posting, but the only thread I found which had good information was http://board.flatassembler.net/topic.php?t=4485 . But I had to ask, because I didn't find the really fastest option.

Thanks!
Post 02 Jun 2006, 10:38
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Ivan2k2 wrote:

and eax,0ffffffffh


That remains EAX untouched Confused
Post 02 Jun 2006, 10:49
View user's profile Send private message Reply with quote
Ivan2k2



Joined: 08 Sep 2004
Posts: 80
Location: Russia, Angarsk
Ivan2k2
oops... of course 'and eax,0'
Post 02 Jun 2006, 11:51
View user's profile Send private message ICQ Number Reply with quote
jbojarczuk



Joined: 21 Jun 2006
Posts: 27
jbojarczuk
xor eax , eax is the fastest option on AMD64 because it is the shortest instruction for the task, and allows you to use the instruction cache in a better way. Besides, the register dependency (that made this method actually slower on Athlon XP) was taken out of this operation.
Post 21 Jun 2006, 04:53
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
saigon: how about reading http://board.flatassembler.net/topic.php?t=4816 first?
Post 21 Jun 2006, 05:15
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.