home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / MATH05.ASM < prev    next >
Assembly Source File  |  1994-11-28  |  5KB  |  196 lines

  1.     PAGE    66,132
  2. ;******************************** MATH05.ASM *********************************
  3. LIBSEG           segment byte public "LIB"
  4.         assume cs:LIBSEG , ds:nothing
  5. ;----------------------------------------------------------------------------
  6.     include    mac.inc
  7.     
  8.  
  9. comment 
  10. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MATH   )
  11. ; DWORD_COMPARE - unsigned 32 bit number compare
  12. ;  inputs  ax,bx = first number
  13. ;          cx,dx = second number
  14. ;  outputs  zf (zero flag) = 1 if equal
  15. ;           if 1 greater than 2  zf=0 and carry=0
  16. ;           if 1 less than 2     zf=0 and carry=1
  17. ;           registers are unchanged
  18. ;
  19. ;* * * * * * * * * * * * * *
  20. 
  21.     public    DWORD_COMPARE
  22. DWORD_COMPARE    proc    far
  23.     cmp    ax,cx
  24.     jnz    comp32_end
  25.     cmp    bx,dx
  26. comp32_end:
  27.     retf
  28. DWORD_COMPARE    endp
  29.  
  30. comment 
  31. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MATH   )
  32. ; QUAD_DIVIDE - divide quad value by dword
  33. ;   inputs:  dx,cx,bx,ax = divident
  34. ;                  si,di = divisor
  35. ;   output:  dx,ax = quotient
  36. ;            cx,bx = remainder
  37. ;
  38. ;* * * * * * * * * * * * * *
  39. 
  40.     public    QUAD_DIVIDE
  41. QUAD_DIVIDE    proc    far
  42.         apush   bp,si,di    
  43.         mov     bp,cx       
  44.         mov     cx,32       
  45.         clc                 
  46.  
  47. qdiv1:  rcl     ax,1        
  48.         rcl     bx,1
  49.         rcl     bp,1
  50.         rcl     dx,1
  51.         jnc     qdiv3       
  52.  
  53. qdiv2:  sub     bp,di       
  54.         sbb     dx,si
  55.         stc                 
  56.         loop    qdiv1       
  57.         jmp     qdiv5
  58.  
  59. qdiv3:  cmp     dx,si      
  60.         jc      qdiv4      
  61.         jne     qdiv2      
  62.         cmp     bp,di
  63.         jnc     qdiv2      
  64.  
  65. qdiv4:  clc                
  66.         loop    qdiv1      
  67.  
  68. qdiv5:  rcl     ax,1       
  69.         rcl     bx,1
  70.  
  71.         mov     cx,bp
  72.         xchg    dx,bx      
  73.         xchg    cx,bx      
  74.  
  75.         apop   di,si,bp    
  76.         retf               
  77. QUAD_DIVIDE    endp
  78.  
  79. comment 
  80. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MATH   )
  81. ; QUAD_MULTIPLY1 - multiply two dwords
  82. ;   inputs: dx,ax = value 1
  83. ;           cx,bx = value 2
  84. ;   output: dx,cx,bx,ax = result
  85. ;
  86. ;* * * * * * * * * * * * * *
  87. 
  88.  
  89.  
  90. temp0      dw    0
  91. temp1      dw    0
  92. temp2      dw    0
  93. temp3      dw    0
  94.  
  95.     public    QUAD_MULTIPLY1
  96. QUAD_MULTIPLY1    proc    far
  97.     apush    si,di
  98.  
  99.         mov     di,dx    
  100.         mov     si,ax
  101.  
  102.         mul     bx       
  103.         mov     cs:temp0,ax
  104.         mov     cs:temp1,dx
  105.  
  106.         mov     ax,di    
  107.         mul     cx
  108.         mov     cs:temp2,ax
  109.         mov     cs:temp3,dx
  110.  
  111.         mov     ax,di        
  112.         mul     bx
  113.         add     cs:temp1,ax     
  114.         adc     cs:temp2,dx
  115.         adc     cs:temp3,0
  116.  
  117.         mov     ax,si        
  118.         mul     cx
  119.         add     cs:temp1,ax     
  120.         adc     cs:temp2,dx
  121.         adc     cs:temp3,0
  122.         mov    ax,cs:temp0
  123.         mov    bx,cs:temp1
  124.         mov    cx,cs:temp2
  125.         mov    dx,cs:temp3
  126.         apop    di,si
  127.         retf                 
  128. QUAD_MULTIPLY1    endp
  129.  
  130. comment 
  131. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MATH   )
  132. ; QUAD_MULTIPLY2 - multiply two 32 bit unsigned numbers
  133. ;  inputs - cx,bx = value 1
  134. ;           dx,ax = value 2
  135. ;  outputs - product in dx,cx,bx,ax (high to low)
  136. ;
  137. ;* * * * * * * * * * * * * *
  138. 
  139. quad_struc  struc
  140.  high_value1        dw    ?
  141.  low_value1        dw    ?
  142.  high_result1        dw    ?
  143.  low_result1        dw    ?
  144.  high_result2        dw    ?
  145.  low_result2        dw    ?
  146.  high_result3        dw    ?
  147.  low_result3        dw    ?
  148.  high_result4        dw    ?
  149.  low_result4        dw    ?
  150. quad_struc    ends
  151.  
  152.     public    QUAD_MULTIPLY2
  153. QUAD_MULTIPLY2    proc    far
  154.     push    bp
  155.     sub    sp,size quad_struc
  156.     mov    bp,sp
  157.     mov    [bp.high_value1],dx    
  158.     mov    [bp.low_value1],ax    
  159.     mul    bx            
  160.     mov    [bp.high_result1],dx    
  161.     mov    [bp.low_result1],ax    
  162.     mov    ax,[bp.high_value1]    
  163.     mul    bx            
  164.     mov    [bp.high_result2],dx    
  165.     mov    [bp.low_result2],ax    
  166.     mov    ax,[bp.low_value1]    
  167.     mul    cx            
  168.     mov    [bp.high_result3],dx    
  169.     mov    [bp.low_result3],ax    
  170.     mov    ax,[bp.high_value1]    
  171.     mul    cx            
  172.     mov    [bp.high_result4],dx    
  173.     mov    [bp.low_result4],ax    
  174. ;
  175. ; combine the intermediate results
  176. ;
  177.     mov    ax,[bp.low_result1]    
  178.     mov    bx,[bp.high_result1]    
  179.     add    bx,[bp.low_result2]
  180.     adc    [bp.high_result2],0
  181.     add    bx,[bp.low_result3]
  182.     add    cx,[bp.high_result2]
  183.     adc    cx,[bp.high_result3]
  184.     adc    [bp.high_result4],0
  185.     add    cx,[bp.low_result4]
  186.     mov    dx,[bp.high_result4]
  187.     adc    dx,0
  188.  
  189.     add    sp,size quad_struc
  190.     pop    bp
  191.     retf
  192. QUAD_MULTIPLY2    endp
  193.  
  194. LIBSEG    ENDS
  195. ;;    end
  196.