home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / grafik / mandel / mand.asm < prev    next >
Assembly Source File  |  1993-01-17  |  2KB  |  91 lines

  1. ;; Mandelbrot Point Computation FPU routine.
  2. ;; Written by John W. Ratcliff, January 19, 1993.
  3. ;; This source is free,but if you choose to use it, please credit the
  4. ;; author, because his ego needs feeding, practically on a daily basis.
  5.     IDEAL
  6.     JUMPS
  7.     include "prologue.mac"
  8.     P386            ; 386 specific opcodes and shit allowed.
  9.  
  10. SMALL_MODEL    equ    0   ;: True if you need a small model version.
  11.  
  12.     SETUPSEGMENT
  13.  
  14. Macro    CPROC    name
  15.     public    _&name
  16. IF    SMALL_MODEL
  17. Proc    _&name    near
  18. ELSE
  19. Proc    _&name    far
  20. ENDIF
  21.     endm
  22.  
  23. P387
  24.  
  25. ;; This is the Mandelbrot point computation procedure.
  26. CPROC    MandelbrotPoint
  27.     ARG    LIMIT:QWORD,ITERATIONS:WORD,REAL:QWORD,IMAGINARY:QWORD
  28.     PENTER    0
  29.  
  30.     mov    cx,[ITERATIONS]
  31.     mov    bx,cx
  32.     finit
  33.     fld    [LIMIT]     ; 7 Load floating point limit
  34.     fld    [REAL]        ; 6 load floating point real.
  35.     fld    [IMAGINARY]    ; 5 load floating point imaginary.
  36.     fld    [REAL]        ; 4 fx store 0.0 real accum.
  37.     fld    [IMAGINARY]    ; 3 fy store 0.0 imaginary accum
  38.     fldz            ; 2 xs store 0.0 holds real squared
  39.     fldz            ; 1 ys store 0.0 holds imaginary squared
  40.     fldz            ; 0 store 0.0, clear accum.
  41.  
  42. @@GO:
  43. ;;    xs = fx*fx;
  44.     fxch    st(4)        ; get FX
  45.     fst    st(4)        ; save it back.
  46.     fmul    st,st        ; Square it.
  47.     fst    st(2)        ; Save in XS xsquared.
  48.  
  49. ;;    ys = fy*fy;
  50.     fxch    st(3)        ; Get FY
  51.     fst    st(3)        ; save it back.
  52.     fmul    st,st        ; sqare it.
  53.     fst    st(1)        ; Save it.
  54.  
  55. ;;  fy = (2*fx*fy)+imaginary;
  56.     fxch    st(4)        ; get FX
  57.     fadd    st,st        ; *2
  58.     fmul    st,st(3)    ; * fy
  59.     fadd    st,st(5)    ; plus imaginary portion.
  60.     fst    st(3)        ; Store result back into FY!
  61.  
  62. ;;    fx = xs-ys+real;
  63.  
  64.     fxch    st(2)        ; Get xsquared.
  65.     fst    st(2)        ; Save it back again for loop test!
  66.     fsub    st,st(1)    ; less ysquared.
  67.     fadd    st,st(6)    ; Plus real portion.
  68.     fst    st(4)        ; Store result back into FX
  69.  
  70. ;; while ( xs+ys < limit && count < iterations);
  71.     fxch    st(2)        ; Get x squared.
  72.     fadd    st,st(1)    ; Add y sqaured
  73.  
  74.     fcom    st(7)        ; is it < limit?
  75.     fstsw   ax              ;sw till ax
  76.     shr    ah,1
  77.     jnc    @@exit        ; exit if >= limit
  78.     dec    cx
  79.     jnz    @@GO        ; Next iteration.
  80.  
  81. @@exit: mov     ax,bx
  82.     sub    ax,cx
  83.     finit                   ;Initialisera coprocessorn!!
  84.  
  85.     PLEAVE
  86.     ret
  87.     endp
  88.  
  89.     ENDS
  90.     END
  91.