home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / MAXONC3_6OF8.DMS / in.adf / LIBSRC.LHA / LIBSRC / math_conv.asm < prev    next >
Encoding:
Assembly Source File  |  1994-09-06  |  1.4 KB  |  81 lines

  1.  
  2. * Maxon C++
  3. * Library "math_conv"
  4. * Jens Gelhar (Himpelsoft) 19.03.93, 15.04.94, 06.09.94
  5.  
  6.     xdef    lib_double2float,lib_float2double
  7.  
  8. lib_double2float:    ; d0||d1 nach d0
  9.     tst.l    d0
  10.     beq.b    dtfRet
  11.     move.l    d2,-(a7)
  12.     move.l    d0,d2
  13.     bclr    #31,d2
  14.     tst.l    d2
  15.     beq.b    dtf0        ; Null bleibt Null
  16.     clr.w    d2
  17.     swap    d2
  18.     lsr.w    #4,d2
  19.     and.w    #$7FF,d2    ; Exponent
  20.     sub.w    #$3FF,d2
  21.     cmp.w    #$80,d2
  22.     bgt.b    dtf4        ; Überlauf
  23.     cmp.w    #-$7F,d2
  24.     blt.b    dtf0        ; Unterlauf
  25.     add.w    #$7F,d2        ; richtiger Exponent
  26.     tst.l    d0
  27.     bpl.b    dtf1
  28.     bset    #8,d2        ; Vorzeichen setzen
  29. dtf1    and.l    #$FFFFF,d0    ; Mantisse ausmaskieren
  30.     ; 3 Bits aus d1 in die Mantisse shiften:
  31.     asl.l    #1,d1
  32.     roxl.l    #1,d0
  33.     asl.l    #1,d1
  34.     roxl.l    #1,d0
  35.     asl.l    #1,d1
  36.     roxl.l    #1,d0
  37.     swap    d2
  38.     asl.l    #7,d2
  39.     or.l    d2,d0
  40.     move.l    (a7)+,d2
  41.     rts
  42. dtf4    ; Überlauf:
  43.     move.l    (a7)+,d2
  44.     or.l    #$7FFFFFFF,d0
  45.     rts
  46. dtf0    ; Unterlauf bzw. Null:
  47.     moveq    #0,d0
  48.     move.l    (a7)+,d2
  49. dtfRet    rts
  50.  
  51.     SECTION "Code2",CODE
  52.  
  53. lib_float2double:    ; d0 nach d0||d1
  54.     tst.l d0
  55.     beq.b ftdNull
  56.     move.l d2,-(a7)
  57.     move.l d0,d2
  58.     and.l #$7FFFFF,d0       ; Short-Mantisse ausmaskieren
  59.     moveq #0,d1
  60.     lsr.l #1,d0             ; 3 Bits verschieben
  61.     roxr.l #1,d1
  62.     lsr.l #1,d0
  63.     roxr.l #1,d1
  64.     lsr.l #1,d0
  65.     roxr.l #1,d1
  66.     ; Vorzeichen setzen:
  67.     tst.l d2
  68.     bpl.b ftd1
  69.     bset #31,d0
  70. ftd1    and.l #$7F800000,d2     ; Mantisse
  71.     lsr.l #3,d2
  72.     add.l #$3FF00000-($3F800000/8),d2
  73.     or.l d2,d0
  74.     move.l (a7)+,d2
  75.     rts
  76. ftdNull    moveq #0,d0
  77.     moveq #0,d1
  78.     rts
  79.  
  80.     END
  81.