source: sbliveos2/trunk/runtime/math.asm

Last change on this file was 142, checked in by ktk, 25 years ago

Import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
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
9include segments.inc
10
11public __U4M
12public __I4M
13public __U4D
14public __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
Note: See TracBrowser for help on using the repository browser.