Assembly or ....

Richard A. O'Keefe ok at quintus.uucp
Wed Nov 30 18:24:58 AEST 1988


In article <21390 at apple.Apple.COM> desnoyer at Apple.COM (Peter Desnoyers) writes:
>In article <1032 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
>>For example, suppose we want to
>>divide a by b, obtaining an integer result i and a remainder c.  I know
>>of no machine with this instruction, and this is not that unusual an 
>>instruction to demand.  
>
>I can't think of a machine that doesn't.

Note that Rubin was careful to identify *i* as integer, but NOT the other
variables!  Consider, for example, Burroughs Extended Algol, where
	x DIV y
was defined to be
	SIGN(x/y)*ENTIER(ABS(x/y))
and	x MOD y
was defined to be
	x - (x DIV y)*y

These definitions make perfect sense for any real x, y for which x/y is
defined.  And Burroughs Algol did in fact extend the definitions to real
and double precision x and y as well as integers.  But the B6700 did not
have any instructions with two results that I can recall (discounting
SWAP), so it only meets part of Rubin's requirements.

In fact, if we define SIGN(x) = if x = 0 then 0 else x/ABS(x), you can
extend DIV and MOD to the complex numbers as well, not that it's quite
as useful...

As for machines which lack an *integer* divide with those properties,
the VAX has an EDIV instruction, but it is awkward to set up.  The 4.1BSD
C compiler would generate the equivalent of x-(x/y)*y for x%y.  For those
with SPARCs, a look at the code generated for x%y might be illuminating.



More information about the Comp.lang.c mailing list