[142] | 1 | ; $Id: math.asm 142 2000-04-23 14:55:46Z ktk $
|
---|
| 2 |
|
---|
| 3 | ;; MATH.ASM - Math routines called by the compiler
|
---|
| 4 |
|
---|
| 5 | ;; MODIFICATION HISTORY
|
---|
| 6 | ;; DATE PROGRAMMER COMMENT
|
---|
| 7 | ;; 01-Jul-95 Timur Tabi Creation
|
---|
| 8 |
|
---|
| 9 | include segments.inc
|
---|
| 10 |
|
---|
| 11 | public __U4M
|
---|
| 12 | public __I4M
|
---|
| 13 | public __U4D
|
---|
| 14 | public __I4D
|
---|
| 15 |
|
---|
| 16 | ;; Long multiply routine
|
---|
| 17 | ;;
|
---|
| 18 | ;; Arguments
|
---|
| 19 | ;; DX:AX * CX:BX
|
---|
| 20 | ;; Returns
|
---|
| 21 | ;; DX:AX = product
|
---|
| 22 | ;; Notes
|
---|
| 23 | ;; Trashes high words of 32-bit registers EAX and EDX
|
---|
| 24 |
|
---|
| 25 | _TEXT SEGMENT DWORD PUBLIC USE16 'CODE'
|
---|
| 26 | assume cs:cgroup, ds:dgroup
|
---|
| 27 |
|
---|
| 28 | __U4M proc near
|
---|
| 29 | __I4M: shl edx,10h ;; Load dx:ax into eax
|
---|
| 30 | mov dx,ax
|
---|
| 31 | mov eax,edx
|
---|
| 32 | mov dx,cx ;; Load cx:bx into edx
|
---|
| 33 | shl edx,10h
|
---|
| 34 | mov dx,bx
|
---|
| 35 | mul edx ;; Multiply eax*edx into edx:eax
|
---|
| 36 | mov edx,eax ;; Load eax into dx:ax
|
---|
| 37 | shr edx,10h
|
---|
| 38 | ret
|
---|
| 39 | __U4M endp
|
---|
| 40 |
|
---|
| 41 | _TEXT ENDS
|
---|
| 42 |
|
---|
| 43 | ;; Long unsigned divide routine
|
---|
| 44 | ;;
|
---|
| 45 | ;; Arguments
|
---|
| 46 | ;; DX:AX / CX:BX
|
---|
| 47 | ;; Returns
|
---|
| 48 | ;; DX:AX = quotient
|
---|
| 49 | ;; CX:BX = remainder
|
---|
| 50 | ;; Notes
|
---|
| 51 | ;; Trashes high words of 32-bit registers EAX, ECX and EDX
|
---|
| 52 |
|
---|
| 53 | _TEXT SEGMENT DWORD PUBLIC USE16 'CODE'
|
---|
| 54 | assume cs:cgroup, ds:dgroup
|
---|
| 55 |
|
---|
| 56 | __U4D proc near
|
---|
| 57 | shl edx,10h ;; Load dx:ax into eax
|
---|
| 58 | mov dx,ax
|
---|
| 59 | mov eax,edx
|
---|
| 60 | xor edx,edx ;; Zero extend eax into edx
|
---|
| 61 | shl ecx,10h ;; Load cx:bx into ecx
|
---|
| 62 | mov cx,bx
|
---|
| 63 | div ecx ;; Divide eax/ecx into eax
|
---|
| 64 | mov ecx,edx ;; Load edx into cx:bx
|
---|
| 65 | shr ecx,10h
|
---|
| 66 | mov bx,dx
|
---|
| 67 | mov edx,eax ;; Load eax into dx:ax
|
---|
| 68 | shr edx,10h
|
---|
| 69 | ret
|
---|
| 70 | __U4D endp
|
---|
| 71 |
|
---|
| 72 | _TEXT ENDS
|
---|
| 73 |
|
---|
| 74 | ;; Long signed divide routine
|
---|
| 75 | ;;
|
---|
| 76 | ;; Arguments
|
---|
| 77 | ;; DX:AX / CX:BX
|
---|
| 78 | ;; Returns
|
---|
| 79 | ;; DX:AX = quotient
|
---|
| 80 | ;; CX:BX = remainder
|
---|
| 81 | ;; Notes
|
---|
| 82 | ;; Trashes high words of 32-bit registers EAX, ECX and EDX
|
---|
| 83 |
|
---|
| 84 | _TEXT SEGMENT DWORD PUBLIC USE16 'CODE'
|
---|
| 85 | assume cs:cgroup, ds:dgroup
|
---|
| 86 |
|
---|
| 87 | __I4D proc near
|
---|
| 88 | shl edx,10h ;; Load dx:ax into eax
|
---|
| 89 | mov dx,ax
|
---|
| 90 | mov eax,edx
|
---|
| 91 | cdq ;; Sign extend eax into edx
|
---|
| 92 | shl ecx,10h ;; Load cx:bx into ecx
|
---|
| 93 | mov cx,bx
|
---|
| 94 | idiv ecx ;; Divide eax/ecx into eax
|
---|
| 95 | mov ecx,edx ;; Load edx into cx:bx
|
---|
| 96 | shr ecx,10h
|
---|
| 97 | mov bx,dx
|
---|
| 98 | mov edx,eax ;; Load eax into dx:ax
|
---|
| 99 | shr edx,10h
|
---|
| 100 | ret
|
---|
| 101 | __I4D endp
|
---|
| 102 |
|
---|
| 103 | _TEXT ENDS
|
---|
| 104 |
|
---|
| 105 | end
|
---|