home *** CD-ROM | disk | FTP | other *** search
/ Black Art of 3D Game Programming / Black_Art_of_3D_Game_Programming.iso / source / borland / chap_17 / fpdiv.asm < prev    next >
Encoding:
Assembly Source File  |  1995-05-25  |  1009 b   |  44 lines

  1.  
  2. ; this function uses 64 bit math to divide two numbers in 32 bit 16:16
  3. ; fixed point format
  4.  
  5. .MODEL MEDIUM              ; use medium memory model C function names
  6.  
  7. .386
  8.  
  9. .CODE                        ; begin the code segment
  10.  
  11. PUBLIC _FP_Div               ; export function name to linker
  12.  
  13.  
  14. _FP_Div PROC
  15.  
  16. ARG dividend:DWORD, divisor:DWORD
  17.  
  18.     push bp          ; create stack frame
  19.     mov bp,sp
  20.  
  21.     mov eax,dividend ; move dividend into eax
  22.     cdq              ; convert eax into edx:eax using sign extension
  23.     shld edx,eax,16  ; shift edx:eax 16 bits to the left in so that
  24.                      ; result is in fixed point
  25.     sal eax,16       ; but manually shift eax since shld doesn't change the
  26.                      ; source register (pretty stupid!)
  27.  
  28.     idiv divisor     ; perform divison
  29.  
  30.     shld edx,eax,16  ; move result into dx:ax since it's in eax
  31.  
  32.     pop bp           ; fixup stack
  33.  
  34.     ret              ; return to caller
  35.  
  36. _FP_Div ENDP
  37.  
  38. END
  39.  
  40.  
  41.  
  42.  
  43.  
  44.