]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/Ia32/DivU64x32.asm
afe58667d65e2a32add530b7615d449a3647ec61
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EfiCommonLib / Ia32 / DivU64x32.asm
1 ;---------------------------------------------------------------------------
2 ;/*++
3 ;
4 ;Copyright (c) 2006, Intel Corporation
5 ;All rights reserved. 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
9 ;
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.
12 ;
13 ;Module Name:
14 ;
15 ; DivU64x32.c
16 ;
17 ;Abstract:
18 ;
19 ; 64-bit division function for IA-32
20 ;
21 ;--*/
22
23 ;---------------------------------------------------------------------------
24 .386
25 .model flat,C
26 .code
27
28 ;---------------------------------------------------------------------------
29 ;UINT64
30 ;DivU64x32 (
31 ; IN UINT64 Dividend,
32 ; IN UINTN Divisor,
33 ; OUT UINTN *Remainder OPTIONAL
34 ; )
35 ;/*++
36
37 ;Routine Description:
38
39 ; This routine allows a 64 bit value to be divided with a 32 bit value returns
40 ; 64bit result and the Remainder.
41 ;
42 ;Arguments:
43
44 ; Dividend - dividend
45 ; Divisor - divisor
46 ; Remainder - buffer for remainder
47 ;
48 ;Returns:
49
50 ; Dividend / Divisor
51 ; Remainder = Dividend mod Divisor
52 ;
53 ;N.B. only works for 31bit divisors!!
54 ;
55 ;--*/
56 ;---------------------------------------------------------------------------
57
58 DivU64x32 PROC
59 push ebp
60 mov ebp, esp
61 xor edx, edx ; Clear EDX
62
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
67
68 push eax ; Push quoitent in stack
69
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
74
75 mov ecx, [ebp + 14h] ; Put &REMAINDER to ecx
76
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
79
80 Label1:
81 pop edx ; Pop High 32-bit QUOITENT to EDX
82 pop ebp
83
84 ret
85
86 DivU64x32 ENDP
87 END