Hi All,
I have noticed what may be an interesting result when I use the
PDP-11 Integer Divide Instruction "Div". Since I have noticed
at least one individual who worked on the microcode for the
PDP-11, perhaps there is an explicit "Yes / No" answer to my
question:
If I divide 196612 by 3 - i.e. "Div (R2),R0" where R0 = 3, R1 = 4, (R2) = 3
the result (in addition to the condition bits) is R0 = 1, R1 = 1 which is
exactly correct if the quotient is regarded as a 32 bit result with R0 being
the low order 16 bits of that result and the high order 32 bits are
somewhere
else - probably inaccessible as far as programming is concerned, but easily
obtained by:
Mov R1-(SP) ; Save low order 16 bits of dividend
Mov R0,R1 ; Divide high order 16 bits
Clr R0 ; of dividend
Div (R2),R0 ; by the divisor
Mov R0,R3 ; Save high order 16 bits of quotient
Mov R1,R0 ; Divide the remainder
Mov (SP)+,R1 ; of the dividend
Div (R2),R0 ; by the divisor
i.e. R3 now contains the high order 16 bits of the 32 bit quotient
with R0 holding the low order 16 bits of the 32 bit quotient
Reason for the question: I require the complete quotient
ONLY when the remainder is ZERO (specifically when the
dividend is not a prime number since (R2) is ALWAYS a
prime number). Thus, if I can avoid performing the first
division except when the remainder is zero and I require
the high order 16 bits of the quotient to continue, I can
optimize the code. Thus far I have tested the code on
numbers up to 100,000,000 when I divide by 3 and the
results are always correct.
Can anyone confirm what I have found in practice?
Even better would be a method of retrieving the high
order 16 bits of the quotient in a manner which takes
fewer instructions and without a second divide instruction!
For those who are interested, I am attempting to calculate
the Mobius Function - mu(n). If you check on Google, mu(n)
requires the number of factors of n. Thus while a sieve
program can be used to remove the prime numbers, the
rest of the numbers must be factored to obtain the number of
factors.
Sincerely yours,
Jerome Fine
--
If you attempted to send a reply and the original e-mail
address has been discontinued due a high volume of junk
e-mail, then the semi-permanent e-mail address can be
obtained by replacing the four characters preceding the
'at' with the four digits of the current year.