LEX 'BCDLEX' * A Function to convert numbers to BCD strings ID #EC * E.g.:BCD$(3.14159265359E-2)="8999535629514130" MSG 0 * J.Elhay, 11/11/87. POLL 0 ENTRY BCD CHAR #F * A function KEY 'BCD$' * Syntax: BCD$(n), where n is a real number TOKEN 157 ENDTXT NIBHEX 811 * 1 obligatotory numeric parameter BCD GOSBVL #0E8FD * POP1R D1=D1+ 16 * reset D1 for the "end" of the string SETHEX * HEX arithmetic, and needed for ADHEAD CD1EX * save D1 D1=C * (and keep unchanged) R1=C * in R1 (for ADHEAD) C=0 W * clear C(W) P= 0 * ensure P=0 (stays 0 throughout) LCASC '0' * load C(B) with #30 (ASCII for "0") B=A W * copy the number into B(W) - already BCD! A=0 W * clear A for use D=0 A * D(0) will be used as our counter D=D-1 P * D(0)=F (convenient isn't it?) LOOP A=0 B * start of loop to convert decimal digits to ASCII A=B P * copy 1 nib from B into A(0) A=A+C B * A(B)+C(B)= ASCII for that digit BSRC * shift B 1 nib for next loop D1=D1- 2 * make room for byte on mathstack DAT1=A B * copy byte to mathstack D=D-1 P * decrement loop counter GONC LOOP * loop back if more bytes ST=0 0 * D1 is correct for ADHEAD which needs ST0=0 for no GOSBVL #1A460 * D=AVMS - return. GOVLNG #181B7 * ADHEAD - finish!