Xref: utzoo comp.arch:10633 comp.lang.misc:3074 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!ames!ncar!ico!nbires!maa From: maa@nbires.nbi.com (Mark Armbrust) Newsgroups: comp.arch,comp.lang.misc Subject: Re: Language Tenets (was Re: Double Width Integer Multiplication and Division Message-ID: <424@nbires.nbi.com> Date: 13 Jul 89 16:02:37 GMT References: <57125@linus.UUCP> <1989Jun24.230056.27774@utzoo.uucp> <13946@haddock.ima.isc.com> <1388@l.cc.purdue.edu> <13961@haddock.ima.isc.com> <147@ssp1.idca.tds.philips.nl> <1207@quintus.UUCP> Reply-To: maa@nbires.UUCP (Mark Armbrust) Organization: NBI Inc, Boulder CO Lines: 54 In article <1207@quintus.UUCP> pds@quintus.UUCP (Peter Schachte) writes: >In article <147@ssp1.idca.tds.philips.nl> roelof@idca.tds.PHILIPS.nl (R. Vuurboom) writes: >>In article <13961@haddock.ima.isc.com> suitti@haddock.ima.isc.com (Stephen Uitti) writes: >>>Is there anything really evil with this: >>> q = divrem(top, bottom, &remainder); >>Well, since you ask...yes. >>A basic language architectural tenet is that logical (semantic) grouping >>should lead to syntactic grouping and vice verse. Any of the notations below >>would satisfy this >> q r <- t/b >[followed with variations on this basic style] > . . . > >All is not lost, though. In C, you can have > > divrem(top, bottom, "ient, &remainder) How about: typedef struct _divResult { int q; int r; } divResult; extern divResult divide (int, int); main() { divResult qr; int i, j; . . . qr = divide (i, j); /* qr.q is quotient, qr.r is remainder */ . . . } If the compiler can't do a good enough job on divide(), it is trivial to write in assembly language. In the case of MSC 5.1, the return values from divide() are in registers, so there is very little overhead using this method. divide: push bp mov bp, sp mov ax, [bp+4] cwd idiv word ptr [bp+6] pop bp ret ; qr.q returned in ax, qr.r in dx -- Mark Armbrust maa@nbires.nbi.com maa@nbires.UUCP