home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / msdos / programm / 11427 < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.2 KB  |  49 lines

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