home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / obero / oberon-a / source / oberonsys / mul.asm < prev    next >
Encoding:
Assembly Source File  |  1994-08-08  |  4.7 KB  |  155 lines

  1. ****************************************************************************
  2. *
  3. *    $RCSfile: MUL.asm $
  4. * Description: Runtime support for the Oberon-A compiler
  5. *
  6. *  Created by: fjc (Frank Copeland)
  7. *   $Revision: 1.2 $
  8. *     $Author: fjc $
  9. *       $Date: 1994/05/12 20:31:15 $
  10. *
  11. * Copyright © 1994, Frank Copeland.
  12. * This file is part of the Oberon-A Library.
  13. * See Oberon-A.doc for conditions of use and distribution.
  14. *
  15. * Log entries are at the end of the file.
  16. *
  17. ****************************************************************************
  18. *
  19. * This file contains the MC68000 source code for part of the runtime
  20. * support library of the Oberon-A compiler.  It contains the code to
  21. * perform multiplication on 32-bit signed integers (LONGINTs).
  22. *
  23. * Other parts of the runtime system may be found in the other files in
  24. * this directory.  The object files resulting from assembling these
  25. * files are concatenated to create OberonSys.lib.
  26. *
  27. * This code is by definition *not* re-entrant and is not suitable for
  28. * creating shared-code libraries.
  29. *
  30. * Acknowledgements
  31. * ----------------
  32. *
  33. * The 32-bit multiply and divide procedures are from the runtime
  34. * library of Patrick Quaid's PCQ freeware Pascal compiler, which in
  35. * turn came from the runtime library of Sozobon C.
  36. *
  37. **********************************************************************
  38.  
  39. ;---------------------------------------------------------------------
  40. ;    Program unit hunk name
  41.  
  42.      TTL OberonSys
  43.  
  44. **********************************************************************
  45.  
  46. **********
  47. * lmath.s
  48. **********
  49. * Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  50. *
  51. * Permission is granted to anyone to use this software for any purpose
  52. * on any computer system, and to redistribute it freely, with the
  53. * following restrictions:
  54. * 1) No charge may be made other than reasonable charges for reproduction.
  55. * 2) Modified versions must be clearly marked as such.
  56. * 3) The authors are not responsible for any harmful consequences
  57. *    of using this software, even if they result from defects in it.
  58. *
  59.  
  60. *       For PCQ Pascal:
  61. *            These are the 32-bit math functions from Sozobon-C,
  62. *       as noted above.  I changed the names of the routines to
  63. *       be more similar to the rest of my library, and handle the
  64. *       divide by zero condition differently.  Other than that I
  65. *       haven't changed the code a bit.
  66.  
  67. *       For Oberon-A:
  68. *            I have changed the names (again) and modified the
  69. *       routines to accept parameters passed in registers instead of
  70. *       on the stack, in keeping with the conventions I use in the
  71. *       rest of the compiler.
  72.  
  73. **********************************************************************
  74.  
  75. ;---------------------------------------------------------------------
  76.  
  77.      ;----------------------------------------------------------------
  78.      ; PROCEDURE OberonSys_MUL (
  79.      ;   l1 {D0} : LONGINT;
  80.      ;   l2 {D1} : LONGINT)
  81.      ; : LONGINT;
  82.      ;
  83.      ; Calculates l1 * l2, returning the result in D0.
  84.      ;----------------------------------------------------------------
  85.  
  86.      SECTION OberonSys,CODE
  87.  
  88.      XDEF      OberonSys_MUL
  89.  
  90. OberonSys_MUL:
  91.  
  92.         movem.l d2-d4,-(a7)     ; save registers
  93.         tst.l   d0
  94.         smi     d4
  95.         bpl     lm1
  96.         neg.l   d0
  97. lm1:
  98.         tst.l   d1
  99.         bpl     lm2
  100.         not.b   d4
  101.         neg.l   d1
  102. lm2:
  103.         bsr     i_lmul          /* d0 = d0*d1 */
  104.         tst.b   d4
  105.         beq     lm3
  106.         neg.l   d0
  107. lm3:
  108.         movem.l (a7)+,d2-d4
  109.         rts
  110.  
  111. ;---------------------------------------------------------------------
  112.  
  113.      SECTION OberonSys,CODE
  114.  
  115. * A in d0, B in d1, return A*B in d0
  116. i_lmul:
  117.         move.l  d3,a2           /* save d3 */
  118.         move.w  d1,d2
  119.         mulu    d0,d2           /* d2 = Al * Bl */
  120.  
  121.         move.l  d1,d3
  122.         swap    d3
  123.         mulu    d0,d3           /* d3 = Al * Bh */
  124.  
  125.         swap    d0
  126.         mulu    d1,d0           /* d0 = Ah * Bl */
  127.  
  128.         add.l   d3,d0           /* d0 = (Ah*Bl + Al*Bh) */
  129.         swap    d0
  130.         clr.w   d0              /* d0 = (Ah*Bl + Al*Bh) << 16 */
  131.  
  132.         add.l   d2,d0           /* d0 = A*B */
  133.         move.l  a2,d3           /* restore d3 */
  134.         rts
  135.  
  136. ;---------------------------------------------------------------------
  137.  
  138.      END  ; OberonSys
  139.  
  140. ****************************************************************************
  141. *
  142. * $Log: MUL.asm $
  143. * Revision 1.2  1994/05/12  20:31:15  fjc
  144. * - Prepared for release
  145. *
  146. * Revision 1.1  1994/01/15  18:31:52  fjc
  147. * Start of revision control
  148. *
  149. * (12 Jan 1994) Modified to assemble with PhxAss instead of A68K
  150. * (29 May 1993) Split OberonSys.asm into several files to create
  151. *               OberonSys.lib.
  152. *
  153. ****************************************************************************
  154.  
  155.