1 ;---------------------------------------------------------------------------
4 ;Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
5 ;This program and the accompanying materials
6 ;are licensed and made available under the terms and conditions of the BSD License
7 ;which accompanies this distribution. The full text of the license may be found at
8 ;http://opensource.org/licenses/bsd-license.php
10 ;THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 ;WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 ; 64-bit division function for IA-32
23 ;---------------------------------------------------------------------------
28 ;---------------------------------------------------------------------------
33 ; OUT UINTN *Remainder OPTIONAL
39 ; This routine allows a 64 bit value to be divided with a 32 bit value returns
40 ; 64bit result and the Remainder.
46 ; Remainder - buffer for remainder
51 ; Remainder = Dividend mod Divisor
53 ;N.B. only works for 31bit divisors!!
56 ;---------------------------------------------------------------------------
61 xor edx, edx ; Clear EDX
63 mov eax, [ebp + 0Ch] ; Put high 32 bits of 64-bit dividend in EAX
64 mov ecx, [ebp + 10h] ; Put 32 bits divisor in ECX
65 div ecx ; Dividend Divisor Quoitent...Remainder
66 ; 0:EAX / ECX = EAX EDX
68 push eax ; Push quoitent in stack
70 mov eax, [ebp + 8] ; Put low 32 bits of 64-bit dividend in EAX
71 div ecx ; Leave the REMAINDER in EDX as High 32-bit of new dividend
72 ; Dividend Divisor Quoitent...Remainder
73 ; EDX:EAX / ECX = EAX EDX
75 mov ecx, [ebp + 14h] ; Put &REMAINDER to ecx
77 jecxz Label1 ; If ecx == 0, no remainder exist, return with quoitent in EDX directly
78 mov dword ptr [ecx], edx ; Put EDX through REMAINDER pointer in ECX
81 pop edx ; Pop High 32-bit QUOITENT to EDX