flat assembler
Message board for the users of flat assembler.

Index > Main > push A, ret or jmp A?

Author
Thread Post new topic Reply to topic
Artlav



Joined: 23 Dec 2004
Posts: 188
Location: Moscow, Russia
Artlav
What kind of jump to a fixed address would be faster on most processors?
Code:
push A
ret    

or
Code:
jmp A    


I was expecting second to be faster, but for some reason first seems to be at least ~5% faster.

Also, sometimes the part with first runs twice as fast, which never happens if i use the second one. Branch prediction/cache stuff?
Post 13 May 2011, 10:46
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
jmp A is faster, i don't see why 2 instructions should be faster than just one.
even if push/ret is HW optimized, jmp too is optimized, then, jmp is faster

but if you want to make some code obfuscation, push, code, ret is a good solution
Smile
Post 13 May 2011, 10:54
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Either one could be faster, depending on the surrounding context...
Post 13 May 2011, 11:43
View user's profile Send private message Reply with quote
ass0



Joined: 31 Dec 2008
Posts: 521
Location: ( . Y . )
ass0
i gues jmp address takes more bytes to encode...plus it may not be aligned.

_________________
Image
Nombre: Aquiles Castro.
Location2: about:robots
Post 13 May 2011, 11:58
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
Artlav, would be possible for you to share your speed testing code? Besides the fact PUSH/RET is harder for the processor to predict the target (if not impossible), you spoil the processor's return address buffer because the RET isn't paired with a CALL.
Post 13 May 2011, 14:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
I think a more appropriate answer would be: If you can't measure any perceivable difference in your code then is does not matter which code sequence you use.
Post 07 Jun 2011, 11:22
View user's profile Send private message Visit poster's website Reply with quote
Enko



Joined: 03 Apr 2007
Posts: 678
Location: Mar del Plata
Enko
push A
ret

whould be not a bad trick for obfuscating the code for some noob reversers.
Post 07 Jun 2011, 14:10
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
Enko wrote:
push A
ret

whould be not a bad trick for obfuscating the code for some noob reversers.


Hey! What do i have to do with it? Leave me alone! Very Happy
Post 07 Jun 2011, 14:41
View user's profile Send private message Reply with quote
asmdev



Joined: 21 Dec 2006
Posts: 18
asmdev
According to "some" manuals that I have read "some years ago", call & ret are meant to work together. If you got one "call" instruction and then "ret" following the call (some instructions are allowed in between) then CPU will cache call+ret pair.

So if we are inside function that was called and executing some other functions:
Code:
; We are inside some function

push A ;calling some 
ret    ;      other function

    

Then "call" of the function that we are inside in will be paired with the "ret" belonging to a different function.

To which extend this can affect performance I don't know.

After I have typed this I can see that precise logic is way too complicated.
Post 08 Jun 2011, 05:47
View user's profile Send private message 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 GitHub, YouTube, Twitter.

Website powered by rwasa.