LDIVMODU assembly code division checks if "a/b" has "b > 64k" and ... if "a/b" will be > 64k. If neither, only a single 32:16=16 div is done. ... If "a/b" will be > 64k, but b < 64k, (a/64k)/b is high part of result. ... If "b > 64k", the whole thing uses a biggish loop. ^.[^"]*% lines in FreeDOS 2035: (SEC_SIZE: hardcoded 512 DIRENT_SIZE: 32) ... not mentioning usage of fixed powers of 2 ... FcbReadWrite: size 16 %= fcb_recsiz ... init_LBA_to_CHS: hsrem 16 = LBA_address % hs, hs is 16 bit Sector*Head LBA_address /= hs, result must be 16 bit Head = hsrem / Sector, Sector = hsrem % Sector + 1 Several places with ... % ... dpb_secsize, as well as ... / ... secsize In sysclk.c, int ByteToBcd(int): return ((x / 10) << 4) | (x % 10); In DayToBcd: x[3] = ByteToBcd(yr / 100); x[2] = ByteToBcd(yr % 100); In clk_driver ... among some / and % with 60 and 6000 and 100 ...: ticks = ((ticks / 59659u) << 16) + ((ticks % 59659u) << 16) / 59659u; ... scaling factor 1193180/6553600 = 59659/327680 = 59659/65536/5 ... Ticks = ((hs >> 16) * 59659u + (((hs & 0xffff) * 59659u) >> 16)) / 5; ... some multiplications by 365 ... is_leap_year: unless 2100, if & 3 ... which works for 1901 ... 2199 ... a modulo 7 for the day of week ... #if TOM ... void dumpBufferCache(void) ... if (++printed % 6 == 0) ... CLUSTER link_fat(struct dpb FAR * dpbp, CLUSTER Cluster1, REG CLUSTER Cluster2) ... idx = (unsigned)(clussec % secdiv); ... clussec /= secdiv; ... ... where clussec is Cluster1 and secdiv is: FAT12->2*secsize, ... FAT16->secsize/2, FAT32->secsize/4. If FAT12, clussec *= 3. LBA_to_CHS: quite similar to init_LBA_to_CHS, but other geometry source ... ... cylinder must even be at most 1023 in this case ... In prf.c and put_unsigned: 32 bit /= and % base, where base is max 16. Not mentioning % and / usage in sys and exeflat: Separate binaries! Places with [^0-9*/]/[^*2/\'] (apart from inside comments...): ... #define LENGTH(x) (sizeof(x)/sizeof(x[0])) ... lpFcb->fcb_rndm += ((unsigned)nTransfer + recsiz - 1) / recsiz; ... lpFcb->fcb_rndm = (fsize + (recsiz - 1)) / recsiz; /* Compute ceil(a/b) */ #define cdiv(a, b) (((a) + (b) - 1) / (b)) ... fatdata = NumSectors - cdiv(defbpb->bpb_ndirent * DIRENT_SIZE, defbpb->bpb_nbyte) - defbpb->bpb_nreserved; ... where nbyte is bytes_per_sector word, other is word*32 ... and for FAT12: fatlength = cdiv(fatdat + 2 * defbpb->bpb_nsector, defbpb->bpb_nbyte * 2 * defbpb->bpb_nsector / 3 + defbpb->bpb_nfat); ... clust = (fatdat - defbpb->bpb_nfat * fatlength) / defbpb->bpb_nsector; maxclust = (fatlength * 2 * defbpb->bpb_nbyte) / 3; ... FAT16: fatlength = (unsigned)cdiv(fatdata + 2 * defbpb->bpb_nsector, (ULONG)defbpb->bpb_nbyte * defbpb->bpb_nsector / 2 + defbpb->bpb_nfat); ... clust = (fatdata - defbpb->bpb_nfat * fatlength) / defbpb->bpb_nsector; maxclust = ((unsigned long)fatlength * defbpb->bpb_nbyte) / 2; ... FAT32: fatlength = cdiv(fatdata + 2 * defbpb->bpb_nsector, (ULONG)defbpb->bpb_nbyte * defbpb->bpb_nsector / 4 + defbpb->bpb_nfat); ... clust = (fatdata - defbpb->bpb_nfat * fatlength) / defbpb->bpb_nsector; maxclust = (fatlength * defbpb->bpb_nbyte) / 4; In initial kernel move and relocation code, in an error-printf: (FP_OFF(rp)-FP_OFF(_HMARelocationTableStart))/sizeof(struct RelocationTable)); A division by 14 in COUNT lfn_create_entries(COUNT handle, lfn_inode_ptr lip) ... entries_needed = (ufstrlen(lfn_name) + CHARS_IN_LFN_ENTRY - 1) / CHARS_IN_LFN_ENTRY + 1; /* We want to create SFN entry too */ in dir_read, dir_write, and bpb_to_dpb (which also has a /3 for FAT12): ... / (secsize / DIRENT_SIZE) ... STATIC void setup_int_vectors(void) ... struct vec *pvec; ... for (pvec = vectors; pvec < vectors + (sizeof vectors/sizeof *pvec); pvec++) STATIC WORD getbpb(ddt * pddt) ... where secs_per_cyl is nsecs*nheads ... ... /* this field is problematic for partitions > 65535 cylinders, in general > 512 GiB. However: we are not using it ourselves. */ pddt->ddt_ncyl = (UWORD)((count + (secs_per_cyl - 1)) / secs_per_cyl); In sys.c: BOOL check_space(COUNT drive, ULONG bytes) ... getextdrivespace(drivename, &x, sizeof(x)); return x.xfs_freeclusters > (bytes / (x.xfs_clussize * x.xfs_secsize)); ... where the a/b b part can be up to and including 0x10000 ...!