home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / MATH02.ASM < prev    next >
Assembly Source File  |  1994-10-15  |  3KB  |  135 lines

  1.     PAGE    66,132
  2. ;******************************** MATH02.ASM *********************************
  3. LIBSEG           segment byte public "LIB"
  4.         assume cs:LIBSEG , ds:nothing
  5. ;----------------------------------------------------------------------------
  6.  
  7.  
  8. comment 
  9. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MATH   )
  10. ; dword_negate - negate dword in dx,ax
  11. ;  inputs:  dx,ax = number
  12. ;  optput:  dx,ax negated
  13. ;* * * * * * * * * * * * * *
  14. 
  15.     public    dword_negate
  16. dword_negate    proc    far
  17.            not    dx
  18.     neg    ax
  19.     sbb    dx,-1
  20.     retf
  21. dword_negate    endp    
  22.  
  23. comment 
  24. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MATH   )
  25. ; dword_divide - divide dword values
  26. ;  inputs: dx,ax divided by bx
  27. ;  output: dx,ax = result
  28. ;* * * * * * * * * * * * * *
  29. 
  30.     public    dword_divide
  31. dword_divide    proc    far
  32.          push    cx
  33.     xchg    cx,dx
  34.     xchg    ax,cx
  35.     sub    dx,dx
  36.     div    bx
  37.     xchg    cx,ax
  38.     div    bx
  39.     mov    dx,cx
  40.     pop    cx
  41.     retf
  42. dword_divide    endp    
  43.  
  44. comment 
  45. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MATH   )
  46. ; dword_add - add dword values
  47. ;  inputs:  dx,ax = value 1
  48. ;           cx,bx = value 2
  49. ;  output:  dx,ax = result
  50. ;           carry set if overflow
  51. ;* * * * * * * * * * * * * *
  52. 
  53.     public    dword_add
  54. dword_add    proc    far
  55.     add    ax,bx
  56.     adc    dx,cx
  57.     retf
  58. dword_add    endp    
  59.  
  60. comment 
  61. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MATH   )
  62. ; dword_sub - subtract dword values
  63. ;  inputs:  dx,ax = value 1
  64. ;           cx,bx = value 2
  65. ;  output:  dx,ax = dx,ax - cx,bx
  66. ;           carry set if overflow
  67. ;* * * * * * * * * * * * * *
  68. 
  69.     public    dword_sub
  70. dword_sub    proc    far
  71.     sub    ax,bx
  72.     sbb    dx,cx
  73.     retf
  74. dword_sub    endp    
  75.  
  76. comment 
  77. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MATH   )
  78. ; dword_mul - multiply dword values
  79. ;   inputs:  dx,ax = value 1
  80. ;            cx,bx = value 2
  81. ;   output:  dx,cx,bx,ax = result
  82. ;* * * * * * * * * * * * * *
  83. 
  84.  
  85. v1    dw    0        ;temp value 1
  86. v2    dw    0        ;temp value 2
  87. v3    dw    0        ;temp value 3
  88. ;v4    dw    0        ;temp value 4 (in BP )
  89.  
  90.     public    dword_mul
  91. dword_mul    proc    far
  92.         push    si                      ; save registers
  93.         push    di
  94.         push    bp                      ; set up stack frame
  95.  
  96.         mov     di,dx                   ; save copy of argument 1
  97.         mov     si,ax
  98.  
  99.         mul     bx                      ; arg1 low * arg2 low
  100.         mov     cs:v1,ax
  101.         mov     cs:v2,dx
  102.  
  103.         mov     ax,di                   ; arg1 high * arg2 high
  104.         mul     cx
  105.         mov     cs:v3,ax
  106.         mov     bp,dx            ;save v4
  107.  
  108.         mov     ax,di                   ; arg1 high * arg2 low
  109.         mul     bx
  110.         add     cs:v2,ax                   ; accumulate result
  111.         adc     cs:v3,dx
  112.         adc     bp,0
  113.  
  114.         mov     ax,si                   ; arg1 low * arg2 high
  115.         mul     cx
  116.         add     cs:v2,ax                   ; accumulate result
  117.         adc     cs:v3,dx
  118.         adc     bp,0
  119. ;
  120. ; load up return registers, dx,cx,bx,ax
  121. ;
  122.     mov    dx,bp            ;get v4
  123.     mov    cx,cs:v3
  124.     mov    bx,cs:v2
  125.     mov    ax,cs:v1
  126.     
  127.         pop     bp                      ; restore registers
  128.         pop     di
  129.         pop     si
  130.     retf
  131. dword_mul    endp    
  132.  
  133. LIBSEG    ENDS
  134.     end
  135.