Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!agate!bionet!apple!bloom-beacon!spdcc!ima!johnl From: johnl@ima.ima.isc.com (John R. Levine) Newsgroups: comp.arch Subject: Re: register save/restore Summary: argument popping nonsense Message-ID: <2867@ima.ima.isc.com> Date: 7 Nov 88 19:40:42 GMT References: <3300037@m.cs.uiuc.edu> <5938@killer.DALLAS.TX.US> <2557@munnari.oz> <578@micropen> Reply-To: johnl@ima.UUCP (John R. Levine) Organization: Not much Lines: 34 In article <578@micropen> dave@micropen (David F. Carlson) writes: >In article <2557@munnari.oz>, jkjl@munnari.oz (John Lim) writes: >> >> Not too important you might think, but i remember that M'soft used the pascal >> calling convention in Windows to save 5% (if i remember) of code, ... > >I thought Microsoft did this because they had source to Apple's Lisa ... >[which was written in Pascal.] Probably not. A highly reliable source who wrote a lot of the Windows code tells me that Windows is written in C and assembler. Considering that the MS C compiler emits special code for Windows linkages and the Pascal compiler doesn't, I believe him. The main difference between C and Pascal calling sequences on an 8086 is that the C sequence has the caller pop the arguments off the stack, while Pascal has the callee pop. There is a "return and pop N" instruction that favors callee pop, thus a code saving. Naturally, if the caller and callee disagree about the number of arguments passed, chaos ensues. Pascal also passes arguments left to right while C passes them right to left; except for the rare varargs function this makes no practical difference. When I was working on Javelin, we also went from C to Pascal calling, and also noticed about a 5% space saving. In that case, though, the compiler returned pointer values in the ES:BX or BX, depending on size, which was a big win because the BX register can be dereferenced directly, while the AX (the normal value register) can't. To return to the original point, before that we switched from Lattice C, which was caller-save, to Wizard (father of Turbo) which was mixed, the callee saving SI and DI and the caller saving anything else. The mixed convention definitely saved a little space, though since the save and restore instructions are only a byte apiece it wasn't much. -- John R. Levine, IECC, PO Box 349, Cambridge MA 02238-0349, +1 617 492 3869 { bbn | spdcc | decvax | harvard | yale }!ima!johnl, Levine@YALE.something Disclaimer: This is not a disclaimer.