News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Return as Jump

Started by redskull, March 19, 2008, 11:58:01 PM

Previous topic - Next topic

redskull

Is there any reason a compiler would generate a

PUSH <something>
RET

instead of just a JMP?  I seem to remember something saying that doing this messes up the branch predition in the CPU, plus it's several bytes longer, so what gives?  What would be the advantage, if it's bigger and slower?

-ac
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Tedd

Yes, it's unpredictable so the processor doesn't like it.
On the other hand, it's unpredictable so it's obfuscated - though why a compiler would do that by default, I don't know.
Depending on what the code before that is, it could be for performing a dynamic jump depending on some variable - as it's dynamic it's going to be unpredictable anyway, so it's debatable whether doing it this way is better or worse than any other.
No snowflake in an avalanche feels responsible.

tenkey

Does the compiler company have their roots in embedded systems?

This is pretty much a common pattern for low performance processors that run in ROM (hardware makes SMC impossible) and no form of indirect jumps (other than subroutine return).
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

redskull

As far as I know, it's just regular old PC windows database application.  If I had to guess, I think it was originally made in Delphi (BPL files), but at this point its anyones guess.  There's tons of these PUSH/RET combinations, and it's not even anything dynamic- i.e. the PUSH value is always a constant, not a register.  But the program has so many bugs and crashes, i'm pretty much ready to wash my hands of trying to debug it.

-ac
Strange women, lying in ponds, distributing swords, is no basis for a system of government

drizz

Good guess. It's Delphi and it's the way it handles SEH.
The truth cannot be learned ... it can only be recognized.