format MS COFF
public _LongMod ; ascall
public _ULongMod ; ascall
section ".code" code readable executable
;------------------------------------------------
_LongMod:
test edx, 80000000h
jz _LongMod_1
neg eax
adc edx, 0
neg edx
push dword[esp + 8]
push dword[esp + 8]
call _ULongMod
neg eax
adc edx, 0
neg edx
ret 8
_LongMod_1:
push dword[esp + 8]
push dword[esp + 8]
call _ULongMod
ret 8
;------------------------------------------------
_ULongMod:
cmp dword[esp + 8], 0
jne _ULongMod_Hard
mov ecx, eax
mov eax, edx
xor edx, edx
div dword[esp + 4]
mov eax, ecx
div dword[esp + 4]
mov eax, edx
xor edx, edx
ret 8
_ULongMod_Hard:
push ebx
push esi
push edi
_ULongMod_Hard_3:
mov esi, dword[esp + 16]
mov edi, dword[esp + 20]
cmp edx, edi
ja _ULongMod_Hard_13
jb _ULongMod_Hard_2
cmp eax, esi
jbe _ULongMod_Hard_2
_ULongMod_Hard_13:
;------------------
; osztand�
;------------------
cmp edx, 0
je _ULongMod_Hard_4
bsr ebx, edi
add ebx, 32
jmp _ULongMod_Hard_5
_ULongMod_Hard_4:
bsr ebx, eax
_ULongMod_Hard_5:
mov ecx, ebx
;------------------
; oszt�
;------------------
cmp edi, 0
je _ULongMod_Hard_6
bsr ebx, edi
add ebx, 32
jmp _ULongMod_Hard_7
_ULongMod_Hard_6:
bsr ebx, esi
_ULongMod_Hard_7:
sub ecx, ebx
;------------------
; shift left
;------------------
cmp cl, 32
ja _ULongMod_Hard_8
shld edi, esi, cl
shl esi, cl
jmp _ULongMod_Hard_9
_ULongMod_Hard_8:
and cl, 31
xor edi, edi
shl esi, cl
;------------------
; shift right 1, ha oszt� > osztand�
;------------------
_ULongMod_Hard_9:
cmp edi, edx
ja _ULongMod_Hard_10
jb _ULongMod_Hard_11
cmp esi, eax
jbe _ULongMod_Hard_11
_ULongMod_Hard_10:
shrd esi, edi, 1
shr edi, 1
dec cl
_ULongMod_Hard_11:
;------------------
; osztand� - tmp oszt�
;------------------
sub eax, esi
sbb edx, edi
_ULongMod_Hard_2:
pop edi
pop esi
pop ebx
ret 8