FORTRAN 77 on PDP-11

Johnny Billquist bqt at Update.UU.SE
Fri Jul 29 11:00:47 CDT 2005


On Fri, 29 Jul 2005 "Jerome H. Fine" <jhfinexgs2 at compsys.to> wrote:

>  >Sean 'Captain Napalm' Conner wrote:
>
> >It was thus said that the Great Jerome H. Fine once stated:
> >
> >
> >>By the way, are there any standard algorithms for the
> >>4 basic operations (add, subtract, multiply and divide)
> >>for 128 bit numbers which are composed of 8 * 16 bit
> >>words?  As per your suggestion, I would probably use:
> >>CHARACTER * 16 ARRAY ( nnn )
> >>
> >What language?  In assembly addition and subtraction are pretty trivial if
> >you have a carry bit you can use (not all RISC based CPUs have a carry bit).
> >Just make sure you keep track of endian issues (given an array A[n] is A[0]
> >the Most Significant or Least Significant word?).
> >[Snip]
> >
> Jerome Fine replies:
>
> While the logic will probably be in FORTRAN 77 under RT-11
> on an emulated PDP-11, I might actually check that it all works
> on a real PDP-11.  However, since FORTRAN 77 is rather nasty
> using more than 32 bit integers, I will probably code the routines
> in MACRO-11 for 64/128 bit add and compare after I first write
> the program for 32 bit integers which can calculate up to 2 billion.

I've already posted code for how to do arbitrary size additions in
FORTRAN-77 on the PDP-11. Substraction is very straight forward the same
deal. Multiplication and division follows the same line as well. Nothing
difficult at all, really.

> As for endian issues, I can define the most significant word to be
> at either end, but I tend to think that I will place the most significant
> at the high end of the word since this allows FORTRAN 77 to use
> octal to output the value correctly with 64 bit floating point values.

??? Not sure what you actually say here. Floating point values hardly have
anything to do with this. Pick whatever byte order you want, and stick
with it. Output is something you'll have to figure out anyway, and you
deal with any byte order you decided on then. Either way is not that
difficult. However, I'd recommend using little-endian, since that is the
"natural" order of the PDP-11, and F77 on the machine. That means you can
let it deal with 16-bit quantities natively without having to to byte
swapping.

> >	          A  B  C  D
> >	          W  X  Y  Z
> >	---------------------
> >	         AZ BZ CZ DZ
> >	      AY BY CY DY
> >	   AX BX CX DX
> >	AW BW CW DW
> >
> >(and don't forget the carries!)  One trick you might want to try is to take
> >advantage of the fact that these are binary values so multiplication becomes
> >shifts and adds but with larger values like these, doing the multibyte
> >rotates may not be as effective as using the actual MUL instructions.
> >
> For the PDP-11, I tend to understand that MUL is only for signed
> 16 bit numbers, so I don't think MUL can be useful with unsigned
> values which are required for a 64 bit multiple as per the above
> example.
>
> CAN  SOMEONE  PLEASE  CORRECT  ME  IF  I  AM WRONG???

Yes, the MUL instruction sign adjust the 32-bit result, based on the two
16-bit input values. However, who cares?
You can get FORTRAN-77 to do unsigned 16 bit multiplication by just
grabbing the 16 bit value, and move it (unsigned) into a 32-bit variable,
do the multiplication, and you'll get an unsigned result back, in
combination with the carry into the next word (when split into two 16-bit
values again).

> That said, in MACRO-11, it should not be too difficult to do multiple shift
> and add operations.  However, maybe someone already had some code
> handy?

Someone probably have, yes. But it is still *very* easy.
No more than a days work. If you pay me, I'll throw the code together for
you.

> >  Division is nasty, but again, works like long division.
> >[Snip]
> >  I have some C code that does some of this---one is a C implementation of a
> >techique Woz used in calculating e to 100,000 digits (as described in Byte
> >magazine of either Dec 1980 or Dec 1981) and another one that does division
> >in C, if you are interested.
> >
> I am interested!!!!!!!

Do it just like you do on paper. Deal with 16 bits at a time, stuffed into
32-bit variables. Sign will be preserved, overflow dealt with, and
everything works out just fine.

	Johnny

Johnny Billquist                  || "I'm on a bus
                                  ||  on a psychedelic trip
email: bqt at update.uu.se           ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol


More information about the cctalk mailing list