; Divide ; UM/MOD ( udl udh un -- ur uq ) ; Unsigned divide of a double by a ; single. Return mod and quotient. HEADER UMMOD "UM/MOD" UMMOD: PUSHW X ; save stack pointer LDW X,(X) ; un LDW YTEMP,X ; save un LDW Y,(1,SP) ; X stack pointer LDW Y,(4,Y) ; Y=udl LDW X,(1,SP) ; X LDW X,(2,X) ; X=udh CPW X,YTEMP JRULE MMSM1 ; X is still on the R-stack POPW X INCW X ; pop off 1 level INCW X ; ADDW X,#2 LDW Y,#0xFFFF LDW (X),Y CLRW Y LDW (2,X),Y RET MMSM1: LD A,#17 ; loop count MMSM3: CPW X,YTEMP ; compare udh to un JRULT MMSM4 ; can't subtract MMSMa: SUBW X,YTEMP ; can subtract RCF MMSM4: CCF ; quotient bit RLCW Y ; rotate into quotient RLCW X ; rotate into remainder DEC A ; repeat JREQ MMSMb ; if A == 0 JRC MMSMa ; if carry out of rotate JRA MMSM3 ; MMSMb: SRAW X LDW YTEMP,X ; done, save remainder POPW X INCW X ; drop INCW X ; ADDW X,#2 LDW (X),Y LDW Y,YTEMP ; save quotient LDW (2,X),Y RET