****************************************************************************
*
*    $RCSfile: OberonSysMUL.asm $
* Description: Runtime support for the Oberon-A compiler
*
*  Created by: fjc (Frank Copeland)
*   $Revision: 1.2 $
*     $Author: fjc $
*       $Date: 1994/05/12 20:31:15 $
*
* Copyright © 1994, Frank Copeland.
* This file is part of the Oberon-A Library.
* See Oberon-A.doc for conditions of use and distribution.
*
* Log entries are at the end of the file.
*
****************************************************************************
*
* This file contains the MC68000 source code for part of the runtime
* support library of the Oberon-A compiler.  It contains the code to
* perform multiplication on 32-bit signed integers (LONGINTs).
*
* Other parts of the runtime system may be found in the other files in
* this directory.  The object files resulting from assembling these
* files are concatenated to create OberonSys.lib.
*
* This code is by definition *not* re-entrant and is not suitable for
* creating shared-code libraries.
*
* Acknowledgements
* ----------------
*
* The 32-bit multiply and divide procedures are from the runtime
* library of Patrick Quaid's PCQ freeware Pascal compiler, which in
* turn came from the runtime library of Sozobon C.
*
**********************************************************************

;---------------------------------------------------------------------
;    Program unit hunk name

     TTL OberonSys

**********************************************************************

**********
* lmath.s
**********
* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to redistribute it freely, with the
* following restrictions:
* 1) No charge may be made other than reasonable charges for reproduction.
* 2) Modified versions must be clearly marked as such.
* 3) The authors are not responsible for any harmful consequences
*    of using this software, even if they result from defects in it.
*

*       For PCQ Pascal:
*            These are the 32-bit math functions from Sozobon-C,
*       as noted above.  I changed the names of the routines to
*       be more similar to the rest of my library, and handle the
*       divide by zero condition differently.  Other than that I
*       haven't changed the code a bit.

*       For Oberon-A:
*            I have changed the names (again) and modified the
*       routines to accept parameters passed in registers instead of
*       on the stack, in keeping with the conventions I use in the
*       rest of the compiler.

**********************************************************************

;---------------------------------------------------------------------

     ;----------------------------------------------------------------
     ; PROCEDURE OberonSys_MUL (
     ;   l1 {D0} : LONGINT;
     ;   l2 {D1} : LONGINT)
     ; : LONGINT;
     ;
     ; Calculates l1 * l2, returning the result in D0.
     ;----------------------------------------------------------------

     SECTION OberonSys,CODE

     XDEF      OberonSys_MUL

OberonSys_MUL:

        movem.l d2-d4,-(a7)     ; save registers
        tst.l   d0
        smi     d4
        bpl     lm1
        neg.l   d0
lm1:
        tst.l   d1
        bpl     lm2
        not.b   d4
        neg.l   d1
lm2:
        bsr     i_lmul          /* d0 = d0*d1 */
        tst.b   d4
        beq     lm3
        neg.l   d0
lm3:
        movem.l (a7)+,d2-d4
        rts

;---------------------------------------------------------------------

     SECTION OberonSys,CODE

* A in d0, B in d1, return A*B in d0
i_lmul:
        move.l  d3,a2           /* save d3 */
        move.w  d1,d2
        mulu    d0,d2           /* d2 = Al * Bl */

        move.l  d1,d3
        swap    d3
        mulu    d0,d3           /* d3 = Al * Bh */

        swap    d0
        mulu    d1,d0           /* d0 = Ah * Bl */

        add.l   d3,d0           /* d0 = (Ah*Bl + Al*Bh) */
        swap    d0
        clr.w   d0              /* d0 = (Ah*Bl + Al*Bh) << 16 */

        add.l   d2,d0           /* d0 = A*B */
        move.l  a2,d3           /* restore d3 */
        rts

;---------------------------------------------------------------------

     END  ; OberonSys

****************************************************************************
*
* $Log: OberonSysMUL.asm $
* Revision 1.2  1994/05/12  20:31:15  fjc
* - Prepared for release
*
* Revision 1.1  1994/01/15  18:31:52  fjc
* Start of revision control
*
* (12 Jan 1994) Modified to assemble with PhxAss instead of A68K
* (29 May 1993) Split OberonSys.asm into several files to create
*               OberonSys.lib.
*
****************************************************************************

