elks-enhanced
public
Read
Owner: themaster
Branch: master
Commits: 6893
Updated: 2026-04-19 00:15
Git CLI clone URL
git clone https://www.xt-emporium.com/git/elks-enhanced.git
Fullscreen desktop URL
Code
Commits
History
Branches
Bug Reports
Discussions
Compare
Settings
elks-enhanced
/
libc
/
asm
/
divmod.S
File editor
// Fast 32-bit combined divide and modulo routine // // unsigned long __divmod(unsigned long val, unsigned int *baserem) // Unsigned divide 32-bits by 16-bits // Store denominator in *baserem before calling // Returns 32-bit quotient in DX:AX and remainder in *baserem // // Designed for a fast replacement of the following code which calls __udivsi3/__umodsi3: // unsigned int rem, base; // rem = val % base; // val = val / base; // New code: // rem = base; // val = __divmod(val, &rem); // // inspired by OpenWatcom ltoa.c __uldiv routine // 13 Sep 2024 Greg Haerr #include <libc-private/call-cvt.h> #define NUMLO 2+FAR_ADJ_ #define NUMHI 4+FAR_ADJ_ #define ADDR 6+FAR_ADJ_ .arch i8086, nojumps .code16 .text .global __divmod __divmod: #ifndef __IA16_CALLCVT_REGPARMCALL mov %sp,%bx mov NUMLO(%bx),%ax mov NUMHI(%bx),%dx mov ADDR(%bx),%bx #else mov %cx,%bx // AX:DX = val, BX = &rem #endif // divides DX:AX / [BX] // returns DX:AX with remainder in [BX] xor %cx,%cx // temp CX = 0 cmp (%bx),%dx // is upper 16 bits numerator less than denominator jb 1f // yes - only one DIV needed xchg %dx,%ax // AX = upper numerator, DX = lower numerator xchg %dx,%cx // DX = 0, CX = lower numerator divw (%bx) // AX = upper numerator / base, DX = remainder xchg %cx,%ax // AX = lower numerator, CX = high quotient 1: divw (%bx) // AX = lower numerator / base, DX = remainder mov %dx,(%bx) // store remainder mov %cx,%dx // DX = high quotient, AX = low quotient RET_(6)
Commit message
This repository is read-only for this account.
Repository snapshot
Current branch
master
Visibility
public
Your access
Read
Remote
Configured
File activity
View file history