Reversing : The Hacker's Guide to Reverse Engineering

(ff) #1
_alldiv PROC NEAR

push edi
push esi
push ebx

; Set up the local stack and save the index registers. When this is
; done the stack frame will look as follows (assuming that the
; expression a/b will generate a call to lldiv(a, b)):
;
; -----------------
; | |
; |---------------|
; | |
; |--divisor (b)--|
; | |
; |---------------|
; | |
; |--dividend (a)-|
; | |
; |---------------|
; | return addr** |
; |---------------|
; | EDI |
; |---------------|
; | ESI |
; |---------------|
; ESP---->| EBX |
; -----------------
;

DVND equ [esp + 16] ; stack address of dividend (a)
DVSR equ [esp + 24] ; stack address of divisor (b)

; Determine sign of the result (edi = 0 if result is positive, non-zero
; otherwise) and make operands positive.

xor edi,edi ; result sign assumed positive

mov eax,HIWORD(DVND) ; hi word of a
or eax,eax ; test to see if signed
jge short L1 ; skip rest if a is already positive
inc edi ; complement result sign flag
mov edx,LOWORD(DVND) ; lo word of a
neg eax ; make a positive
neg edx
sbb eax,0

Listing B.2 The alldivfunction used for performing 64-bit divisions in code generated
by the Microsoft compilers. (continued)

Understanding Compiled Arithmetic 531

22_574817 appb.qxd 3/16/05 8:45 PM Page 531

Free download pdf