which to use? say I had a proc like this: ;;;;;;;;;;;; This proc uses edi cmp al,cl jz @f do_some_stuff jmp @fini @@: do_some_other_stuff @fini: ret This endp ;;;;;;;;;;;;; or do this? ;;;;;;;;;;;;; That proc uses edi cmp al,cl jz @f do_some_stuff ret @@: do_some_other_stuff ret That endp ;;;;;;;;;;; it seems like either way work but is one better or faster or something than the other and is edi saved properly either way? best regards, czDrillard
Posted on 2001-06-25 00:16:00 by czDrillard
80486 execution times:
                      Clock Cycles
intersegment direct call      3
ret                           5
jmp                           3
Neither call, ret, or jmp affect edi. They only affect eip, and esp. The use depends on what you are doing. For subs, use call.
Posted on 2001-06-25 00:52:00 by eet_1024
use ml with switches -Sg -Fl and you will see that edi is saved and restored properly, together with other stack cleanup. I prefer "jmp exit"
Posted on 2001-06-25 03:43:00 by japheth
Within a PROC, "ret" is actually a macro that expands into something like this: leave retn 10h So, for file size anyway, it is well to use a jmp to some single "ret" instruction within the procedure. Outside a procedure it usually costs nothing to use use multiple ret's. A complete control freak like myself will avoid "proc" altogether. Then several functions can share exit code: cmp al,cl ja AnyRet ... AnyRet10: retn 10h ... AnotherRoutine: ... je AnyRet10 ...
Posted on 2001-06-25 11:03:00 by Larry Hammick
czDrillard, I think what you're asking is is it better to have a single RET per PROC, and jmp to it, or just drop a RET wherever you find convienent? Either way is fine. The compiler accepts this and makes the proper code. An extra jmp isn't going to affect execution time, and you give your code a well defined structure, with every proc having the same exit place. Placing RET as convienent makes for slightly longer but slightly faster code. My personal choice is place RETs where convienent.
Posted on 2001-06-25 18:27:00 by Ernie
many thanks to all the peoples that respond to my post. like ernie I like the ret instead jump just for the reason it makes code more readable for me. best regards, czDrillard
Posted on 2001-06-26 00:18:00 by czDrillard