1 #---------------------------------------------------------------------------
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
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 #---------------------------------------------------------------------------
24 #include "EfiBind.h" //For ASM_PFX
25 #---------------------------------------------------------------------------
27 #---------------------------------------------------------------------------
31 #---------------------------------------------------------------------------
33 .globl ASM_PFX(DivU64x32)
39 # OUT UINTN *Remainder OPTIONAL
45 # This routine allows a 64 bit value to be divided with a 32 bit value returns
46 # 64bit result and the Remainder.
52 # Remainder - buffer for remainder
57 # Remainder = Dividend mod Divisor
59 #N.B. only works for 31bit divisors!!
62 #---------------------------------------------------------------------------
67 xorl %edx, %edx # Clear EDX
69 movl 0xC(%ebp), %eax # Put high 32 bits of 64-bit dividend in EAX
70 movl 0x10(%ebp), %ecx # Put 32 bits divisor in ECX
71 divl %ecx # Dividend Divisor Quoitent...Remainder
72 # 0:EAX / ECX = EAX EDX
74 pushl %eax # Push quoitent in stack
76 movl 8(%ebp), %eax # Put low 32 bits of 64-bit dividend in EAX
77 divl %ecx # Leave the REMAINDER in EDX as High 32-bit of new dividend
78 # Dividend Divisor Quoitent...Remainder
79 # EDX:EAX / ECX = EAX EDX
81 movl 0x14(%ebp), %ecx # Put &REMAINDER to ecx
83 jecxz Label1 # If ecx == 0, no remainder exist, return with quoitent in EDX directly
84 movl %edx, (%ecx) # Put EDX through REMAINDER pointer in ECX
87 popl %edx # Pop High 32-bit QUOITENT to EDX