aboutsummaryrefslogtreecommitdiff
path: root/src/libmp/386/mpdigdiv-Darwin.s
blob: 038214bf6aec6da22c63157774194c191c6944be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
.text

.globl _mpdigdiv
_mpdigdiv:
	/* Prelude */
	pushl %ebp		/* save on stack */
	pushl %ebx
	
	leal 12(%esp), %ebp	/* %ebp = FP for now */
	movl 0(%ebp), %ebx	/* dividend */
	movl 0(%ebx), %eax
	movl 4(%ebx), %edx
	movl 4(%ebp), %ebx	/* divisor */
	movl 8(%ebp), %ebp	/* quotient */

	xorl	%ecx, %ecx
	cmpl	%ebx, %edx		/* dividend >= 2^32 * divisor */
	jae	2f
	cmpl	%ecx, %ebx		/* divisor == 1 */
	je	2f
	divl	%ebx		/* AX = DX:AX/BX */
	movl	%eax, (%ebp)
1:
	/* Postlude */
	popl %ebx
	popl %ebp
	ret

	/* return all 1's */
2:
	notl	%ecx
	movl	%ecx, (%ebp)
	jmp 1b