Ok, I know it isn't possible without:

cmp xx xx
jcc L1
call xxxxxxxx
L1:


But surely there has to be a better way... How exactly does a call work? Doesn't it basically just place the return addy on the stack and then jump? So, my question would be: How do I simulate a call or is it even possible?

If I can, then I can just: push $ | jcc xxxxxxx or something like that...

Do you see where I'm going with this?
Posted on 2001-10-22 17:58:44 by Kenny
no you can't, your stack would end up dirty if the jump isn't taken :).
The best you can hope for is code restructure or clever macro usage.
Posted on 2001-10-22 18:31:11 by f0dder
How about this:



>ccall ne myconditionaljump

upsides:
faster than an if statement
downsides:
edx has to be preserved and the "function" can only be conditional with that type of macro eg. "call myconditionalcall" will screw stuff up
Posted on 2001-10-22 18:42:30 by Kenny
You can't "pop eip" (that's a ret ;)). Also, your method means calls
cannot be nested, and edx has to be preserved at all costs. Not really
a viable solution imo. And what's that cmov doing there?

Anyway, you'll probably want your conditional call macro to do the
call if the condition is true. Which means that in a



Jcc @@skip
call addr
@@skip:


you will have to invert the "cc"... which I dunno how to do wihtout
a lot of ugly checks :). But anyway I think making a macro would be
the best solution for this. And it might be purposeful, it saves two
lines, and saves some labels (I never liked @f and @b).
Posted on 2001-10-22 18:56:06 by f0dder
Reason for cmov: won't clog the stack if the call isn't called
I already knew about that way (see my first post), but I was just trying to see if I can make a conditional call better
Reason for not doing it that way: slighly clogs up the branch prediction buffer

Solution for edx preservation and nested calls:



[function | push edx | #1:]
[ccall | cmov edx rethere | j#1 #2-4 | rethere:]

cmp eax edx
ccall ne myfunction
call myfunction

function myfunction
....
ret


I think I made the call conditional and made it compatible with normal calls too! (only drawback is edx is not preserved when doing the actual calling, but can be changed in the function)
Posted on 2001-10-22 19:07:20 by Kenny