|
|
1.1 ! root 1: ////////// ! 2: / i8086 general utilities library. ! 3: / ldiv() ! 4: / ANSI 4.10.6.4. ! 5: / Long division and remainder. ! 6: ////////// ! 7: ! 8: #include "larges.h" ! 9: ! 10: ////////// ! 11: / #include <stdlib.h> ! 12: / ldiv_t ldiv(long int numer, long int denom) ! 13: / ! 14: / Compute quotient and remainder of 'numer' by 'denom'. ! 15: / Return a pointer to a statically allocated ldiv_t object. ! 16: ////////// ! 17: ! 18: .prvd ! 19: quot: .word 0 ! 20: .word 0 ! 21: rem: .word 0 ! 22: .word 0 ! 23: ! 24: numer = 6+RASIZE ! 25: denom = 4+numer ! 26: ! 27: .shri ! 28: .globl ldiv_, vdiv ! 29: ! 30: ldiv_: ! 31: push di ! 32: push si ! 33: push bp ! 34: mov bp, sp ! 35: ! 36: mov ax, numer(bp) ! 37: mov dx, 2+numer(bp) / Dividend to DX:AX ! 38: mov cx, denom(bp) ! 39: mov bx, 2+denom(bp) / Divisor to BX:CX ! 40: ! 41: mov bp, dx ! 42: xor bp, bx ! 43: and bp, $0x8000 / Quotient sign to sign bit of BP ! 44: ! 45: or bx, bx ! 46: jns 0f ! 47: not bx / Force divisor positive ! 48: neg cx ! 49: sbb bx, $-1 ! 50: 0: ! 51: or dx, dx ! 52: jns 0f ! 53: or bp, $1 / Remainder sign to low bit of BP ! 54: not dx / Force dividend positive ! 55: neg ax ! 56: sbb dx, $-1 ! 57: 0: ! 58: Gcall vdiv / Quotient to SI:DI, rem to DX:AX ! 59: or bp, bp ! 60: jns 0f ! 61: not si / Negate quotient ! 62: neg di ! 63: sbb si, $-1 ! 64: 0: ! 65: and bp, $1 ! 66: je 0f ! 67: not dx / Negate remainder ! 68: neg ax ! 69: sbb dx, $-1 ! 70: 0: ! 71: Map (ds, bx, $@quot) ! 72: mov bx, $quot / Destination to DS:BX ! 73: mov (bx), di ! 74: mov 2(bx), si / Store quotient ! 75: mov 4(bx), ax ! 76: mov 6(bx), dx / Store remainder ! 77: ! 78: #if LARGE ! 79: mov dx, ds ! 80: #endif ! 81: mov ax, bx / Return pointer in DX:AX ! 82: ! 83: pop bp ! 84: pop si ! 85: pop di ! 86: Gret ! 87: ! 88: / end of ldiv.m
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.