"create-named-in" cosmetix
[urforth.git] / level0 / urforth0_w_math_muldiv.asm
blobfc8c72fc8ce5f3d02271123449c7736ad4b00131
1 ;; Native x86 GNU/Linux Forth System, Direct Threaded Code
2 ;;
3 ;; Copyright (C) 2020 Ketmar Dark // Invisible Vector
4 ;;
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, version 3 of the License ONLY.
8 ;;
9 ;; This program is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;; GNU General Public License for more details.
14 ;; You should have received a copy of the GNU General Public License
15 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 ;; remainder has the same sign as the original number
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 urword_code "*",imul
24 ;; ( n0 n1 -- n0*n1 )
25 pop eax
26 xchg eax,TOS
27 imul TOS,eax
28 urnext
29 urword_end
31 urword_code "/",idiv
32 ;; ( n0 n1 -- n0/n1 )
33 pop eax
34 ; TOS=n1
35 ; EAX=n0
36 jecxz .zero
37 cdq
38 idiv TOS
39 mov TOS,eax
40 .zero:
41 urnext
42 urword_end
44 urword_code "MOD",imod
45 ;; ( n0 n1 -- n0%n1 )
46 pop eax
47 ; TOS=n1
48 ; EAX=n0
49 jecxz .zero
50 cdq
51 idiv TOS
52 mov TOS,edx
53 .zero:
54 urnext
55 urword_end
57 urword_code "/MOD",idivmod
58 ;; ( n0 n1 -- n0%n1 n0/n1 )
59 pop eax
60 ; TOS=n1
61 ; EAX=n0
62 jecxz .zero
63 cdq
64 idiv TOS
65 push edx
66 mov TOS,eax
67 urnext
68 .zero:
69 push TOS
70 urnext
71 urword_end
73 urword_code "U*",umul
74 ;; ( n0 n1 -- n0*n1 )
75 pop eax
76 xchg eax,TOS
77 mul TOS
78 mov TOS,eax
79 urnext
80 urword_end
82 urword_code "U/",udiv
83 ;; ( n0 n1 -- n0/n1 )
84 pop eax
85 ; TOS=n1
86 ; EAX=n0
87 jecxz .zero
88 xor edx,edx
89 div TOS
90 mov TOS,eax
91 .zero:
92 urnext
93 urword_end
95 urword_code "UMOD",umod
96 ;; ( n0 n1 -- n0%n1 )
97 pop eax
98 ; TOS=n1
99 ; EAX=n0
100 jecxz .zero
101 xor edx,edx
102 div TOS
103 mov TOS,edx
104 .zero:
105 urnext
106 urword_end
108 urword_code "U/MOD",udivmod
109 ;; ( n0 n1 -- umod ures )
110 pop eax
111 ; TOS=n1
112 ; EAX=n0
113 jecxz .zero
114 xor edx,edx
115 div TOS
116 push edx
117 mov TOS,eax
118 urnext
119 .zero:
120 push TOS
121 urnext
122 urword_end