;copyright (c) 2012 Kazuki Iwamoto http://www.maid.org/ iwm@maid.org
;
;Permission is hereby granted, free of charge, to any person obtaining
;a copy of this software and associated documentation files (the
;"Software"), to deal in the Software without restriction, including
;without limitation the rights to use, copy, modify, merge, publish,
;distribute, sublicense, and/or sell copies of the Software, and to
;permit persons to whom the Software is furnished to do so, subject to
;the following conditions:
;
;The above copyright notice and this permission notice shall be included
;in all copies or substantial portions of the Software.
;
;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
;IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
;CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
;TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
;SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

.586
.model flat, c

.code

_aulldvrm proc
        push    esi
        mov     eax, [esp + 20]
        or      eax, eax
        jz      short @@4
        mov     ecx, eax
        mov     ebx, [esp + 16]
        mov     edx, [esp + 12]
        mov     eax, [esp + 8]
@@1:    shr     ecx, 1
        rcr     ebx, 1
        shr     edx, 1
        rcr     eax, 1
        or      ecx, ecx
        jnz     short @@1
        div     ebx
        mov     esi, eax
        mul     dword ptr [esp + 20]
        mov     ecx, eax
        mov     eax, [esp + 16]
        mul     esi
        add     edx, ecx
        jc      short @@2
        cmp     edx, [esp + 12]
        ja      short @@2
        jb      short @@3
        cmp     eax, [esp + 8]
        jbe     short @@3
@@2:    dec     esi
        sub     eax, [esp + 16]
        sbb     edx, [esp + 20]
@@3:    xor     ebx, ebx
        jmp     short @@5
@@4:    mov     eax, [esp + 12]
        mov     ecx, [esp + 16]
        xor     edx, edx
        div     ecx
        mov     ebx, eax
        mov     eax, [esp + 8]
        div     ecx
        mov     esi, eax
        mov     eax, ebx
        mul     dword ptr [esp + 16]
        mov     ecx, eax
        mov     eax, esi
        mul     dword ptr [esp + 16]
        add     edx, ecx
@@5:    sub     eax, [esp + 8]
        sbb     edx, [esp + 12]
        neg     edx
        neg     eax
        sbb     edx, 0
        mov     ecx, edx
        mov     edx, ebx
        mov     ebx, ecx
        mov     ecx, eax
        mov     eax, esi
        pop     esi
        ret     16
_aulldvrm endp

end
