home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 4 Drivers / 04-Drivers.zip / cs0929a.zip / segsetup.asm < prev    next >
Assembly Source File  |  1999-02-24  |  5KB  |  205 lines

  1. ;
  2. ; segsetup.asm, math support
  3. ; 15-Jan-99
  4. ; watcom.c 16-bit
  5. ; wasm setsetup.asm
  6.  
  7. .386
  8. .seq
  9.  
  10. public _endData
  11. public _endHeap
  12. public _endInitData
  13. public _endCode
  14.  
  15. _HEADER         segment para public use16 'DATA'
  16. _HEADER         ends
  17.  
  18. _DATA           segment para public use16 'DATA'
  19. _DATA           ends
  20.  
  21. CONST           segment para public use16 'DATA'
  22. CONST           ends
  23.  
  24. CONST2          segment para public use16 'DATA'
  25. CONST2          ends
  26.  
  27. _BSS            segment para public use16 'BSS'
  28. _BSS            ends
  29.  
  30. ;_ENDDS          segment para public use16 'ENDDS'
  31. ;_endData        dw 0
  32. ;_ENDDS          ends
  33. ;
  34. ;_HEMP           segment dword public use16 'ENDDS'  ;named HEMP so can use _endHeap
  35. ;_HEMP           ends
  36. ;
  37. ;_ENDHEMP        segment dword public use16 'ENDDS'
  38. ;_endHeap        dw 0
  39. ;_ENDHEMP        ends
  40.  
  41. _HEMP           segment dword public use16 'BSS'  ;named HEMP so can use _endHeap
  42. _HEMP           ends                              ;in BSS so doesn't bloat .sys
  43.  
  44. _ENDHEMP        segment dword public use16 'BSS'
  45. _endHeap        dw 0
  46. _ENDHEMP        ends
  47.  
  48. _ENDDS          segment para public use16 'ENDDS'
  49. _endData        dw 0
  50. _ENDDS          ends
  51.  
  52.  
  53. _INITDATA       segment para public use16 'ENDDS'
  54. _INITDATA       ends
  55.  
  56. _ENDINITDATA    segment para public use16 'ENDDS'
  57. _endDataInit    dw 0
  58. _ENDINITDATA    ends
  59.  
  60. _TEXT           segment para public use16 'CODE'
  61. _TEXT           ends
  62.  
  63. _ENDCS          segment para public use16 'CODE'
  64. _endCode        dw 0
  65. _ENDCS          ends
  66.  
  67. RMCODE          segment para public use16 'CODE'
  68. RMCODE          ends
  69.  
  70. _INITTEXT       segment para public use16 'CODE'
  71. _INITTEXT       ends
  72.  
  73.  
  74. DGROUP          group _HEADER, CONST, CONST2, _DATA, _BSS, _ENDDS, _HEMP, _ENDHEMP, _INITDATA, _ENDINITDATA
  75. CGROUP          group _TEXT, _ENDCS, RMCODE, _INITTEXT
  76.  
  77. ; -------------------------------------------------------------
  78. ; and any needed asm (might as well just use the one .asm file)
  79.  
  80. extrn DOSIODELAYCNT:ABS     ;DOSCALLS.427
  81.  
  82. public iodelay_
  83.  
  84. public __U4M
  85. public __I4M
  86. public __U4D
  87. public __I4D
  88.  
  89. ; --------------------------------------------------------------------
  90. ; in: cx = times 500 us (cx=2 then waits 1 uS (1 millionth of a second)
  91. ;out: n/a
  92. ;nts: both _iodelay and iodelay_ available
  93.  
  94. _TEXT   segment para PUBLIC USE16 'CODE'
  95.         assume cs:cgroup, ds:dgroup
  96.  
  97. _iodelay label near
  98. iodelay_ proc near
  99.  
  100.         db 0B8h                 ;mov ax,
  101.         dw DOSIODELAYCNT        ;wordcount
  102. ALIGN 4
  103. @@:     dec   ax
  104.         jnz   @b
  105.         loop  iodelay_
  106.         ret
  107.  
  108. iodelay_ endp
  109.  
  110. _TEXT   ENDS
  111.  
  112.  
  113. ;; Long multiply routine
  114. ;;
  115. ;; Arguments
  116. ;;    DX:AX * CX:BX
  117. ;; Returns
  118. ;;    DX:AX = product
  119. ;; Notes
  120. ;;    Trashes high words of 32-bit registers EAX and EDX
  121.  
  122. _TEXT   segment para PUBLIC USE16 'CODE'
  123.         assume cs:cgroup, ds:dgroup
  124.  
  125. __U4M   proc  near
  126. __I4M:  shl   edx,10h            ;; Load dx:ax into eax
  127.         mov   dx,ax
  128.         mov   eax,edx
  129.         mov   dx,cx              ;; Load cx:bx into edx
  130.         shl   edx,10h
  131.         mov   dx,bx
  132.         mul   edx                ;; Multiply eax*edx into edx:eax
  133.         mov   edx,eax            ;; Load eax into dx:ax
  134.         shr   edx,10h
  135.         ret
  136. __U4M   endp
  137.  
  138. _TEXT   ENDS
  139.  
  140. ;; Long unsigned divide routine
  141. ;;
  142. ;; Arguments
  143. ;;    DX:AX / CX:BX
  144. ;; Returns
  145. ;;    DX:AX = quotient
  146. ;;    CX:BX = remainder
  147. ;; Notes
  148. ;;    Trashes high words of 32-bit registers EAX, ECX and EDX
  149.  
  150. _TEXT   segment para PUBLIC USE16 'CODE'
  151.         assume cs:cgroup, ds:dgroup
  152.  
  153. __U4D   proc  near
  154.         shl   edx,10h            ;; Load dx:ax into eax
  155.         mov   dx,ax
  156.         mov   eax,edx
  157.         xor   edx,edx            ;; Zero extend eax into edx
  158.         shl   ecx,10h            ;; Load cx:bx into ecx
  159.         mov   cx,bx
  160.         div   ecx                ;; Divide eax/ecx into eax
  161.         mov   ecx,edx            ;; Load edx into cx:bx
  162.         shr   ecx,10h
  163.         mov   bx,dx
  164.         mov   edx,eax            ;; Load eax into dx:ax
  165.         shr   edx,10h
  166.         ret
  167. __U4D   endp
  168.  
  169. _TEXT   ENDS
  170.  
  171. ;; Long signed divide routine
  172. ;;
  173. ;; Arguments
  174. ;;    DX:AX / CX:BX
  175. ;; Returns
  176. ;;    DX:AX = quotient
  177. ;;    CX:BX = remainder
  178. ;; Notes
  179. ;;    Trashes high words of 32-bit registers EAX, ECX and EDX
  180.  
  181. _TEXT   segment para PUBLIC USE16 'CODE'
  182.         assume cs:cgroup, ds:dgroup
  183.  
  184. __I4D   proc  near
  185.         shl   edx,10h            ;; Load dx:ax into eax
  186.         mov   dx,ax
  187.         mov   eax,edx
  188.         cdq                      ;; Sign extend eax into edx
  189.         shl   ecx,10h            ;; Load cx:bx into ecx
  190.         mov   cx,bx
  191.         idiv  ecx                ;; Divide eax/ecx into eax
  192.         mov   ecx,edx            ;; Load edx into cx:bx
  193.         shr   ecx,10h
  194.         mov   bx,dx
  195.         mov   edx,eax            ;; Load eax into dx:ax
  196.         shr   edx,10h
  197.         ret
  198. __I4D   endp
  199.  
  200. _TEXT   ENDS
  201.  
  202.         end
  203.  
  204.  
  205.