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
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.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"
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
...
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.
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