;Adobe Helvetica normal ;------------------------------------------------- ;Teilt 64-Bit-Werte und gibt das korekt gerundeten Ergebnis zurück. ;------------------------------------------------- ;Divides 64-bit-values and returns the correct rounded result. ;------------------------------------------------- ; Code for the best assembler: The Netwide Assembler: NASM ; Copyright (C) 2004 by Sebastian Beck; sebastian.bw@freenet.de ; Wenn Sie eine Spende machen wollen, fragen Sie mich über E-Mail ; nach meiner Bankverbindung. ; If you want to make a donation, please question me by e-mail for ; my banking connection. ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as ; published by the Free Software Foundation. ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ;------------------------------------------------- ;%include "./INC/div64.inc" ;[i386] ;To your global or the declaration of the calling process. ;Wert dd 0,0 ;value -unchanged ;Teiler dd 0,0 ;divider -unchanged ;Ergebnis dd 0,0 ;result ;------------------------------------------------- div64: section .data potenzer dd 1,0 section .text pushad mov dword[Ergebnis],0 mov dword[Ergebnis+4],0 mov eax,[Wert] mov ebx,[Wert+4] mov ecx,[Teiler] mov edx,[Teiler+4] cmp ecx,0 jnz .aa cmp edx,0 jnz .aa jmp .ende .aa: cmp ebx,0 ; ist wh = 0 jz .a jmp .d .a: cmp edx,0 ; ist th <> 0 jnz .c mov edx,0 ; Normale 32-Bit Division div ecx shl edx,1 jc .b cmp edx,ecx ; ist Rest*2 < tl jb .b1 .b: inc eax .b1: mov [Ergebnis],eax jmp .ende .c: shld ebx,eax,1 ; Nur Runden jc .c1 shl eax,1 cmp ebx,edx jb .c2 .c1: mov byte[Ergebnis],1 .c2: jmp .ende .d: cmp ebx,edx ; ist wh < th jb .c je .c1 ; wenn wh = th .d1: mov di,[potenzer] mov si,[potenzer+4] .d2: shld edx,ecx,1 jnc .dd2 shr edx,1 or edx,0x80000000 jmp .d4 .dd2: shl ecx,1 shld esi,edi,1 shl edi,1 cmp ebx,edx ; ist wh > th ja .d2 jz .dd3 .d3: shrd ecx,edx,1 shr edx,1 shrd edi,esi,1 shr esi,1 .dd3; cmp edi,0 ; ist P1<>0 jnz .d4 cmp esi,0 jnz .d4 .e: shld edx,ecx,1 ; P=0 shl ecx,1 mov edi,1 shld ebx,eax,1 shl eax,1 cmp ebx,edx ; ist wh>=th jae .e1 jmp .ende .e1: jnz .e2 ; ist wh<>th cmp eax,ecx ; ist wl th ja .d4 cmp ebx,0 ; ist wh <> 0 jnz .d3 .d6: cmp edx,0 ; ist th = 0 jz .f shrd ecx,edx,1 shr edx,1 shrd edi,esi,1 shr esi,1 cmp edi,0 ; ist P1<>0 jnz .d6 cmp esi,0 ; ist P1<>0 jnz .d6 jmp .e ; P=0 .f: ; P > 0, th = 0, wh = 0 ! cmp edi,1 ; ist P1<>1 jz .ff shr ecx,1 shr edi,1 jmp .f .ff: div ecx ; eax=wl edx=0 shl edx,1 jc .f1 cmp edx,ecx jb .f2 .f1: inc eax ; kein Übertrag möglich ! .f2: add dword[Ergebnis],eax adc dword[Ergebnis+4],0 .ende: popad ret