Warning: Undefined variable $mode in /var/www/virtual/qbnz.com/htdocs/highlighter/examples/asm/64-bit-divide.php on line 6
GeSHi - Generic Syntax Highlighter :: Examples
 
Navigation
Home News Examples Demo Downloads FAQ Documentation Mailing Lists License
Support GeSHi!
If you're using GeSHi, why not help GeSHi out? You can link to GeSHi with this image:
Powered by GeSHi
Get the HTML

Project Status
The latest stable version of GeSHi is 1.0.8.11, released on the 19th of Aug, 2012.

Supported Languages:
*ABAP
*Actionscript
*ADA
*Apache Log
*AppleScript
*APT sources.list
*ASM (m68k)
*ASM (pic16)
*ASM (x86)
*ASM (z80)
*ASP
*AutoIT
*Backus-Naur form
*Bash
*Basic4GL
*BlitzBasic
*Brainfuck
*C
*C for Macs
*C#
*C++
*C++ (with QT)
*CAD DCL
*CadLisp
*CFDG
*CIL / MSIL
*COBOL
*ColdFusion
*CSS
*D
*Delphi
*Diff File Format
*DIV
*DOS
*DOT language
*Eiffel
*Fortran
*FourJ's Genero
*FreeBasic
*GetText
*glSlang
*GML
*gnuplot
*Groovy
*Haskell
*HQ9+
*HTML
*INI (Config Files)
*Inno
*INTERCAL
*IO
*Java
*Java 5
*Javascript
*KiXtart
*KLone C & C++
*LaTeX
*Lisp
*LOLcode
*LotusScript
*LScript
*Lua
*Make
*mIRC
*MXML
*MySQL
*NSIS
*Objective C
*OCaml
*OpenOffice BASIC
*Oracle 8 & 11 SQL
*Pascal
*Perl
*PHP
*Pixel Bender
*PL/SQL
*POV-Ray
*PowerShell
*Progress (OpenEdge ABL)
*Prolog
*ProvideX
*Python
*Q(uick)BASIC
*robots.txt
*Ruby
*Ruby on Rails
*SAS
*Scala
*Scheme
*Scilab
*SDLBasic
*Smalltalk
*Smarty
*SQL
*T-SQL
*TCL
*thinBasic
*TypoScript
*Uno IDL
*VB.NET
*Verilog
*VHDL
*VIM Script
*Visual BASIC
*Visual Fox Pro
*Visual Prolog
*Whitespace
*Winbatch
*Windows Registry Files
*X++
*XML
*Xorg.conf

GeSHi 1.0.8.11 is the current stable release, with eighteen new languages and bug fixes over the last release.

GeSHi 1.1.2alpha5 is the current latest version from the development branch, with full C support (see the GeSHi development website).
Subscribe
RSS 2
Mailing Lists
HomeNewsExamplesDemoDownloadsFAQDocumentationMailing ListsLicense 
7:23 am GMT

Examples

Examples » ASM
;
; _ulldiv divides two unsigned long long numbers, the dividend and the divisor
; resulting in a quotient and a remainder.
;
; input:
;   edx:eax = dividend
;   ecx:ebx = divisor
;
; output:
;   edx:eax = quotient of division of dividend by divisor
;   ecx:ebx = remainder of division of dividend by divisor
;
; destroys:
;   eflags
;
 
PROC    _ulldiv NEAR
 
             test    ecx, ecx           ; divisor > 2^32-1 ?
             jnz     $big_divisor       ; yes, divisor > 32^32-1
             cmp     edx, ebx           ; only one division needed ? (ecx = 0)
             jb      $one_div           ; yes, one division sufficient
             mov     ecx, eax           ; save dividend-lo in ecx
             mov     eax, edx           ; get dividend-hi
             xor     edx, edx           ; zero extend it into edx:eax
             div     ebx                ; quotient-hi in eax
             xchg    eax, ecx           ; ecx = quotient-hi, eax =dividend-lo
$one_div:    div     ebx                ; eax = quotient-lo
             mov     ebx, edx           ; ebx = remainder-lo
             mov     edx, ecx           ; edx = quotient-hi(quotient in edx:eax)
             xor     ecx, ecx           ; ecx = remainder-hi (rem. in ecx:ebx)
             ret
$big_divisor:push    esi                ; save temp
             push    edi                ;  variables
             push    edx                ; save
             push    eax                ;  dividend
             mov     esi, ebx           ; divisor now in
             mov     edi, ecx           ;  edi:ebx and ecx:esi
             shr     edx, 1             ; shift both
             rcr     eax, 1             ;  divisor and
             ror     edi, 1             ;   and dividend
             rcr     ebx, 1             ;    right by 1 bit
             bsr     ecx, ecx           ; ecx = number of remaining shifts
             shrd    ebx, edi, CL       ; scale down divisor and
             shrd    eax, edx, CL       ;   dividend such that divisor
             shr     edx, CL            ;    less than 2^32 (i.e. fits in ebx)
             rol     edi, 1             ; restore original divisor (edi:esi)
             div     ebx                ; compute quotient
             pop     ebx                ; get dividend lo-word
             mov     ecx, eax           ; save quotient
             imul    edi, eax           ; quotient * divisor hi-word (low only)
             mul     esi                ; quotient * divisor lo-word
             add     edx, edi           ; edx:eax = quotient * divisor
             sub     ebx, eax           ; dividend-lo - (quot.*divisor)-lo
             mov     eax, ecx           ; get quotient
             pop     ecx                ; restore dividend hi-word
             sbb     ecx, edx           ; subtract divisor * quot. from dividend
             sbb     edx, edx           ; 0 if remainder > 0, else FFFFFFFFh
             and     esi, edx           ; nothing to add
             and     edi, edx           ;  back if remainder positive
             add     ebx, esi           ; correct remaider
             adc     ecx, edi           ;  and quotient if
             add     eax, edx           ;   necessary
             xor     edx, edx           ; clear hi-word of quot (eax<=FFFFFFFFh)
             pop     edi                ; restore temp
             pop     esi                ;  variables
             ret
 
ENDP    _ulldiv

This category contains 2 examples, and has been viewed 47022 times.