1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2006, Intel Corporation
4 ; All rights reserved. This program and the accompanying materials
5 ; are licensed and made available under the terms and conditions of the BSD License
6 ; which accompanies this distribution. The full text of the license may be found at
7 ; http://opensource.org/licenses/bsd-license.php
9 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 ; DivU64x64Remainder.asm
18 ; Calculate the quotient of a 64-bit integer by a 64-bit integer and returns
19 ; both the quotient and the remainder
21 ;------------------------------------------------------------------------------
27 EXTERN InternalMathDivRemU64x32:PROC
29 ;------------------------------------------------------------------------------
32 ; InternalMathDivRemU64x64 (
35 ; OUT UINT64 *Remainder OPTIONAL
37 ;------------------------------------------------------------------------------
38 InternalMathDivRemU64x64 PROC
41 jnz _@DivRemU64x64 ; call _@DivRemU64x64 if Divisor > 2^32
44 and dword ptr [ecx + 4], 0
47 jmp InternalMathDivRemU64x32
48 InternalMathDivRemU64x64 ENDP
50 _@DivRemU64x64 PROC USES ebx esi edi
51 mov edx, dword ptr [esp + 20]
52 mov eax, dword ptr [esp + 16] ; edx:eax <- dividend
54 mov esi, eax ; edi:esi <- dividend
55 mov ebx, dword ptr [esp + 24] ; ecx:ebx <- divisor
63 mov ebx, eax ; ebx <- quotient
65 mul dword ptr [esp + 24]
68 mov ecx, dword ptr [esp + 32]
69 jc @TooLarge ; product > 2^64
70 cmp edi, edx ; compare high 32 bits
72 jb @TooLarge ; product > dividend
74 jae @Correct ; product <= dividend
76 dec ebx ; adjust quotient by -1
77 jecxz @Return ; return if Remainder == NULL
78 sub eax, dword ptr [esp + 24]
79 sbb edx, dword ptr [esp + 28]
83 sbb edi, edx ; edi:esi <- remainder
87 mov eax, ebx ; eax <- quotient