Article View: comp.os.msdos.programmer
Article #6470Re: Calling convention: C vs PASCAL
From: Randall E Smith
Date: Tue, 15 Dec 1992 20:51
Date: Tue, 15 Dec 1992 20:51
37 lines
2259 bytes
2259 bytes
From previous postings on this thread: >>A Pascal routine with 20 bytes of parameters can return and clean up with >>the single instruction: > >> retf 20 > >>On all 80x86 cpus, this takes the same time (plus or minus a cycle) as the >>plain retf. The advantage comes because that's all that's needed; a return >>from a C convention routine must be followed by manual adjustment of >>the stack pointer. > >e.g. sub sp, 20 ... which takes 2 cycles on a 386. You will have >to have a very short called routine before you can see any difference. > You can argue that the performance difference between these two techniques is very small, some optimizing C compilers will even keep track of the number of bytes pushed onto the stack over several function calls and then add an adjustment later. This should out-perform the "RET 20" scheme. However, the "RET 20" scheme has the advantage of only requiring the adjustment at one point in your code segment (at the return) while the other scheme requires clean-up in your code segment everywhere the function is called. This code segment size savings may be significant if your style of coding is to write small functions that are called from many of places within your code. To summarize: Both calling conventions described above result in similar speed performance - if you need faster execution then start writing critical code in assembler, yourself. The "RET n" convention should result in tighter code .. less memory space required by your code than the "SUB SP, 20" method. Randy Smith (Note: I'm not trying to argue C vs PASCAL, just trading off the different calling conventions described above. I coded in PASCAL while in school and now code in C and 80386 assembler to produce protected-mode, embedded applications.)
Technical Details
Message-ID:
<BzBJ9I.6Gv@plato.ds.boeing.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!bcstec!plato!rsmithReferences:
<1992Dec14.124529@cs.utwente.nl> <dmurdoch.231.724340705@mast.queensu.ca> <gay.724356941@sfu.ca>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!bcstec!plato!rsmith From: rsmith@plato.ds.boeing.com (Randall E Smith) Subject: Re: Calling convention: C vs PASCAL Message-ID: <BzBJ9I.6Gv@plato.ds.boeing.com> Organization: Boeing Defense & Space Group References: <1992Dec14.124529@cs.utwente.nl> <dmurdoch.231.724340705@mast.queensu.ca> <gay.724356941@sfu.ca> Date: Tue, 15 Dec 1992 20:51:17 GMT Lines: 38