/* This C language subroutine converts and ascii string to an integer value. The Run Time Library for the C Language. Gordon A. Sterling (617) 461 - 3076 DSP Development Tools Engineering Created on 1/1/91 Updated on 5/94 by AS Updated on 3/95 by AS - separated polymorphic functions #include
int strtol(const char *p, char **endptr, int base); unsigned long int strtoul(const char *p, char **endptr, int base); */ #include "lib_glob.h" #include "sdl_glob.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL ___strtolPP; .GLOBAL ___strtoulPP; ___strtoulPP: ___strtolPP: strtoi_core: R0=R0-R0, put(R3); put(R5); put(R6); put(R7); R9=PASS R8, put(R9); R10=PASS R12, put(R10); put(R11); R12=R12-R12, put(R13); put(R14); R15=PASS R4, put(R15); R5=48; /*ASC('0')*/ R6=97; /*ASC('a')*/ R7=122; /*ASC('z')*/ R8=57; /* ASC('9')*/ R4=32; /*OR w/alpha for lower case*/ R2=10; /*Used for alpha values*/ pm_strtoi: R0=R0+1, pm_ptr=R15; /*Used for sign value*/ ck_isspacep: R11=32; /*ASC(' ')*/ remove_spacep: R13=PM(pm_ptr,pm_1); COMP(R13,R11); /*Check for space*/ IF EQ JUMP (PC, remove_spacep); R14=13; /*Check for \n*/ COMP(R13,R14); IF GT JUMP (PC, not_spacep); R14=9; COMP(R13,R14); IF GE JUMP (PC, remove_spacep); not_spacep: R14=45; /*ASC('-')*/ COMP(R13,R14); IF EQ R0=-R0; /*Invert sign*/ R14=16; /*Test for base 16*/ COMP(R10,R14); R14=48; /*ASC ' ' used in base check*/ IF EQ JUMP (PC, base_16_checkp); /*Check for 0x in front*/ R10=PASS R10; /*Tst for no base specified*/ IF LT JUMP (PC, error_end); /*Err ret, base negative!*/ IF GT JUMP (PC, accumulatep); /*Base was specified, not 16*/ figure_basep: R10=10; /*Default to base 10*/ COMP(R13,R14); /*Test for base 8*/ IF NE JUMP (PC, accumulatep); /*Is not zero, go accumulate*/ R10=8; /*Assume base8, check for 16*/ base_16_checkp: COMP(R13,R14); /*Test of 0 of 0x*/ IF NE JUMP (PC, accumulatep); /*Non-zero, go accumulate*/ R13=PM(pm_ptr,pm_1); /*Read next character*/ R1=R4 OR R13; /*OR with caps mask*/ R14=92; /*ASC('x')*/ COMP(R1,R14); /*Test for end of 0x*/ IF NE JUMP (PC, accumulatep); /*Non-x, go accumulate*/ R10=16; /*Set to base 16*/ R13=PM(pm_ptr,pm_1); /*Read next character*/ accumulatep: /*Comp upper char/num limits*/ R11=10; /*Test for a base*/ R11=R10-R11; /* less than 10*/ IF LT JUMP (PC, accp_cont) (DB); /*Fix upper limit then cont*/ R8=R8+R11; /*Figure upper limit*/ R11=36; /*Upper limit of base*/ R7=122; /* ASC('z') */ R7=R7+R12; /*set upper limit*/ accp_cont: COMP(R10,R11); /*Test for base>36*/ IF GT JUMP (PC, error_end); /*Error return zero*/ COMP(R13,R5), R3=R5; /*Test for <0 */ IF LT JUMP (PC, error_end); /*End of number detected*/ COMP(R13,R8); /*Test for upper numer limit*/ IF LE JUMP (PC, init_sump); /*Just a #, begin summation*/ R3=R6-R2; /*Base for character*/ R13=R13 OR R4; /*Caps mask*/ COMP(R13,R6); /*Test lower alpha limit*/ IF LT JUMP (PC, error_end); /*Not a number!*/ COMP(R13,R7); /*Test upper alpha limit*/ IF GT JUMP (PC, error_end); /*Not a number!*/ init_sump: R12=R3-R13, R13=PM(pm_ptr,pm_1); /*Accumulate in negative*/ check_nextp: COMP(R13,R5), R3=R5; /*Test for <0 */ IF LT JUMP (PC, finish_upp); /*End of number detected*/ COMP(R13,R8); /*Tst for upper numer limit*/ IF LE JUMP (PC, maccp); /*Just a #, so accumulate*/ R3=R6-R2; /*Base for character*/ R13=R13 OR R4; /*Caps mask*/ COMP(R13,R6); /*Test lower alpha limit*/ IF LT JUMP (PC, finish_upp); /*End of number*/ COMP(R13,R7); /*Test upper alpha limit*/ IF GT JUMP (PC, finish_upp); /*End of number*/ maccp: R13=R3-R13; JUMP (PC, check_nextp) (DB); /*Compute value*/ R12=R12*R10 (SSI); /*Multiply sum by base*/ R12=R12+R13, R13=PM(pm_ptr, pm_1); /*Compute new running sum*/ finish_upp: R0=R0*R12 (SSI), R1=pm_ptr; R0=-R0; pm_endptr: R1=R1-1; R9=PASS R9, pm_ptr=R9; /*Tst for NULL, Pt to endptr*/ IF NE PM(pm_ptr,pm_0)=R1; FETCH_RETURN 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); get(R3,10); RETURN (DB); RESTORE_STACK RESTORE_FRAME error_end: JUMP (PC, pm_endptr) (DB); R0=R0-R0; /*Get address of string*/ R1=R1+1; /*Inc (due to dec later)*/ .ENDSEG;