Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!mtune!codas!cpsc6a!rtech!wrs!dg From: dg@wrs.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: Near / Far Calls (was Re: Types) Message-ID: <342@wrs.UUCP> Date: Tue, 8-Sep-87 19:36:04 EDT Article-I.D.: wrs.342 Posted: Tue Sep 8 19:36:04 1987 Date-Received: Fri, 11-Sep-87 01:59:18 EDT References: <7264@brl-adm.ARPA> <734@sdchema.sdchem.UUCP> <293@osupyr.UUCP> <296@swlabs.UUCP> <613@sugar.UUCP> <4779@sdcrdcf.UUCP> Reply-To: dg@wrs.UUCP (David Goodenough) Organization: Wind River Systems, Emeryville, CA Lines: 36 In article <613@sugar.UUCP> peter@sugar.UUCP (Peter da Silva) writes: >> [ description of how to make an assembler that handles long/short branches ] >But that doesn't resolve the problem of how to deal with near and far >cals to seperately compiled code. If the calling sequence of the 8086 >was a little more logical, you could have 2 entry points for the routine: >near and far. The near would just push the segment and fall through to >the far. Unfortunately, segment is not the top of the stack in a far >call. See Kernighan's April column in Computer Language. I may be missing the point here, but as I remember, the objection was that the offending push can't be done without destroying a register. However since *ALL* C's I've seen are able to return a value, you just use that register i.e. AX on the 8086, and since AX is probably going to get munged in the procedure you are safe: nearentry: pop ax ; save pc in ax push cs ; do the push everyones bitching about push ax ; restore pc farentry: code ...... retfar ; or however you do a far return Caveat: I do agree with his point that if you need to preserve all regs thru a procedure then this is a problem, but in C this is not usually the case. -- dg@wrs.UUCP - David Goodenough +---+ | +-+-+ +-+-+ | +---+