I really need an instruction that would do something like jz (jump if 0) but with a call instead of a jump because I need the program to return to the place it was before the jump. I am working with nasm (if that makes any difference) Thank you so much for your help.
Asked
Active
Viewed 679 times
0
-
2No, but you can do something hackish like manually pushing a return address on the stack and then do the conditional branch to a function. The `ret` of that function will not know how you started executing the function, it only cares there is a return address at the top of the stack at the point the `ret` is executed. – Michael Petch Apr 24 '16 at 17:34
-
3Possible duplicate of [call subroutines conditionally in assembly](http://stackoverflow.com/questions/7301683/call-subroutines-conditionally-in-assembly) – Michael Petch Apr 24 '16 at 17:35
-
I had thought of doing that, but how do I push the address? I know how to use the stack but I mean how do I get the address to the point of return? – Tammy Moscoso Apr 24 '16 at 18:31
-
The link to the duplicate question has an answer that shows how – Michael Petch Apr 24 '16 at 18:35
-
There were conditional calls (and returns) on the Intel 8080, but not the 8086 or its updates. – harold Apr 24 '16 at 18:54
-
4While it's possible to implement what you want by pushing the return address you never want to do this. It hurts performance and makes your code harder to understand and maintain. Just jump around an unconditional call instruction by using a conditional instruction using the opposite test. eg: `jnz dont_call; call foo; dont_call:` – Ross Ridge Apr 24 '16 at 20:05
-
I agree with @RossRidge: you should jump to the call instruction and redesign your algorithm around that constraint. Can you expatiate on why this might be an obstacle? – James M. Lay Apr 25 '16 at 07:51