/* This C language subroutine converts and ascii string to a floating point value. The Run Time Library for the C Language. Gordon A. Sterling (617) 461 - 3076 DSP Development Tools Engineering Created on 12/12/92 Altered on 1/95 by AS - separated polymorphism #include
double atof(pm char *p); */ #include "lib_glob.h" #include "sdl_glob.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL ___atofP; ___atofP: atof_core: put(R2); R2=MR2F; put(R2); R2=MR1F; put(R2); R2=MR0F; put(R2); put(R3); put(R5); put(R6); put(R7); put(R9); put(R10); put(R11); put(R13); put(R14); put(R15); pm_atof: R12=R12-R12, pm_ptr=R4; /* Clr out acc regs, Pt to str*/ R13=R13-R13, pm_lnt=R12; /* Clear out LSW acc */ R7=R7-R7, dm_lnt=R12; /* Used for sign value */ R10=32; /* 32 = ASC(' ') */ R9=13; /* 13 = ASC('/n') */ R8=9; /* 9 = ASC('/r') */ clean_pspaces: R11=PM(pm_ptr,pm_1); /* Read character */ COMP(R11,R10); /* Compare to ' ' */ IF EQ JUMP (PC, clean_pspaces);/* Remove more spaces*/ COMP(R11,R9); /* Compare to '/n' */ IF GT JUMP (PC, acc_psign); /* Check for number */ COMP(R11,R8); /* Compare to '/r' */ IF GE JUMP (PC, clean_pspaces);/* Remove more spaces*/ acc_psign: R10=43; /* 43 = ASC('+') */ R9=45; /* 45 = ASC('-') */ COMP(R11,R10); /* Compare to '+' */ IF EQ R7=R7-R7, R11=PM(pm_ptr,pm_1);/* Sign is positive */ COMP(R11,R9); /* Compare to '-' */ IF EQ R7=R7-1, R11=PM(pm_ptr,pm_1);/* Sign is negative */ acc_pnum: dm_mdf=R7; /* Hold sign for now */ R10=46; /* 46 = ASC('.') */ R9=101; /* 101 = ASC('e') */ R8=69; /* 69 = ASC('E') */ R7=57; /* 57 = ASC('9') */ R6=48; /* 48 = ASC('0') */ F14=0x40240000; /* MSW of 10.0 */ acc_pint: COMP(R11,R10); /* Compare to '.' */ IF EQ JUMP (PC, acc_pfract); /* Accumulate fraction*/ COMP(R11,R9); /* Compare to 'e' */ IF EQ JUMP (PC, acc_pexp); /* Get exponent */ COMP(R11,R8); /* Compare to 'E' */ IF EQ JUMP (PC, acc_pexp); /* Get exponent */ COMP(R11,R7); /* Compare to '9' */ IF GT JUMP (PC, non_num); /* Not a number, end */ COMP(R11,R6); /* Compare to '0' */ IF LT JUMP (PC, non_num); /* Not a number, end it*/ CALL (PC, ___lib_dmult) (DB); /* Multiply sum by 10.0 */ R15=R15-R15; /* Zero out LSW of 10.0 */ NOP; /* DEAD CYCLE */ CALL (PC, ___lib_itod) (DB); /* Convert number to dbl*/ R12=PASS R0, R13=R1; /* Hold sum */ R0=R11-R6; /* Convert number to int*/ CALL (PC, ___lib_dadd) (DB); /* Add to sum */ R11=PASS R14; /* Hold MSW of 10.0 */ R14=PASS R0, R15=R1; /* Copy num for add */ JUMP (PC, acc_pint) (DB); /* Get next character*/ R12=PASS R0, R13=R1; /* Copy current sum */ R14=PASS R11, R11=PM(pm_ptr,pm_1);/* Copy MSW of 10.0 */ acc_pfract: R14=0x3ff00000; /* MSW of 1.0 */ R15=0; /* LSW of 1.0 */ get_nextpfract: R11=PM(pm_ptr,pm_1); COMP(R11,R9); /* Compare to 'e' */ IF EQ JUMP (PC, acc_pexp); /* Get exponent */ COMP(R11,R8); /* Compare to 'E' */ IF EQ JUMP (PC, acc_pexp); /* Get exponent */ COMP(R11,R7); /* Compare to '9' */ IF GT JUMP (PC, non_num); /* Not a number, end */ COMP(R11,R6); /* Compare to '0' */ IF LT JUMP (PC, non_num); /* Not a number, end it*/ CALL (PC, ___lib_itod) (DB);/* Convert number to dbl*/ R0=R11-R6; /* Convert to num first */ R10=0x3fb99999; /* Load MSW of 0.1 */ R1=0x9999999a; /* Load LSW of 0.1 */ R11=R0; /* Hold MSW of num */ CALL (PC, ___lib_dmult) (DB); /* Multiply fract by .1*/ R4=PASS R12, R5=R13; /* Hold sum */ R13=PASS R1, R12=R10; /* Copy number */ CALL (PC, ___lib_dmult) (DB); /* Multiply num by fract*/ R14=PASS R0, R15=R1; /* Hold fractional part */ R13=R13-R13, R12=R11; /* Copy current number */ R10=PASS R14, R11=R15; /* Hold current fract */ CALL (PC, ___lib_dadd) (DB); /* Add to current sum*/ R14=PASS R0, R15=R1; /* Move for add */ R12=PASS R4, R13=R5; /* Copy old sum */ JUMP (PC, get_nextpfract) (DB);/* Get next number*/ R12=PASS R0, R13=R1; /* Copy current sum */ R14=PASS R10, R15=R11; /* Copy current fract */ acc_pexp: R8=R8-R8, R11=PM(pm_ptr,pm_1);/*For exp sign,Rd 1st expr part*/ R10=43; /* 43 = ASC('+') */ R9=45; /* 45 = ASC('-') */ COMP(R11,R10); /* Compare to '+' */ IF EQ R8=R8-R8, R11=PM(pm_ptr,pm_1);/* Sign is positive */ COMP(R11,R9); /* Compare to '-' */ IF EQ R8=R8-1, R11=PM(pm_ptr,pm_1);/* Sign is negative */ R9=0; /* Clear sum */ R10=10; /* Used for multiply */ get_next_pexp: COMP(R11,R7); /* Compare to '9' */ IF GT JUMP (PC, got_exp); /* Not a number, end */ COMP(R11,R6); /* Compare to '0' */ IF LT JUMP (PC, got_exp); /* Not a number, end it*/ R11=R11-R6; /* Get number */ JUMP (PC, get_next_pexp) (DB);/* Get next number*/ R9=R9*R10 (SSI); /* Mult sum by 10 */ R9=R9+R11, R11=PM(pm_ptr,pm_1); /* Add to sum */ compute_exp: CALL (PC, ___lib_dmult) (DB); /* Multiply sum by exp */ R12=PASS R0, R13=R1; /* Copy exp value */ R14=PASS R10, R15=R11; /* Copy old sum */ restore_state: get(R15,1); get(R14,2); get(R13,3); get(R11,4); get(R10,5); get(R9,6); get(R7,7); get(R6,8); get(R5,9); FETCH_RETURN get(R2,11); MR0F=R2, get(R2,12); MR1F=R2, get(R2,13); MR2F=R2, get(R3,10); RETURN (DB); RESTORE_STACK RESTORE_FRAME .ENDSEG;