[Simh] Ferranti Pegasus Simulator
Bob Supnik
bob at supnik.org
Fri Jun 10 21:52:46 EDT 2016
There are any number of strange-length divide algorithms in SimH. Here
is the PDP-10 code for dividing a 70b unsigned integer by a 35b
(unsigned) integer.
// dvd[0:1] = 70b dividend, high order first (35b in each word)
// dvr = 35b divisor
// rs[0:1] = quotient remainder
// all variables (except i) are unsigned 64b
for (i = 0, rs[0] = 0; i < 35; i++) { /* 35 quotient
bits */
dvd[0] = (dvd[0] << 1) | ((dvd[1] >> 34) & 1);
dvd[1] = (dvd[1] << 1) & MMASK; /* shift
dividend and mask */
rs[0] = rs[0] << 1; /* shift
quotient */
if (dvd[0] >= dvr) { /* subtract
work? */
dvd[0] = dvd[0] - dvr; /* quo bit is 1 */
rs[0] = rs[0] + 1;
}
}
rs[1] = dvd[0]; /* store
remainder */
It's easy enough to see how to expand this to a computer with 39b in
each word of dvd - just increase the loop count from 35 to 39, increase
the shift count in the second line from 34 to 38, and define MMASK to be
39 bits of 1s.
In general, it's simplest to implement this sort of multi-precision
divide unsigned. Simply calculate the sign of the quotient and dividend
before starting (quo sign = dividend sign XOR divisor sign; rem sign =
dividend sign), then take the absolute value of dividend and divisor
before running the bit-by-bit loop; fix up the signs of quotient and
remainder when done.
This assumes that the Ferranti did a precise divide. That's not
necessarily the case. The IBM 7094 approximated double precision
floating divide with a two term Taylor-series expansion...
I hope the available Pegasus documentation provides sufficient detail on
how divide was actually implemented.
/Bob
On 6/10/2016 8:15 PM, simh-request at trailing-edge.com wrote:
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 11 Jun 2016 00:46:02 +0100
> From: "Dave Wade"<dave.g4ugm at gmail.com>
> To:<simh at trailing-edge.com>
> Subject: [Simh] Ferranti Pegasus Simulator
> Message-ID:<002401d1c372$3fc331e0$bf4995a0$@gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Whilst its not a SIMH simulator, I hope you can help. I want to write an
> emulator for the Pegasus. The Ferranti Pegasus was (there are none operating
> at present) a strange beast with two 18-bit instructions per 39-bit word.
> Generally, it does 39-bit twos complement arithmetic. The multiply results
> in a 77-bit result which I have no problems implementing.
>
> Where I am struggling is with the divide. I need to be able to divide a
> 77-bit number by a 39-bit number and get a 39 bit quotient and a 39 bit
> remainder. As the compiler I am using only does 64-bit numbers this is
> proving challenging. Any one got a good article on how to do this?
>
> Dave Wade
> G4UGM
More information about the Simh
mailing list