From: Dr. Ed C. <so...@in...> - 2001-06-04 16:26:27
|
Since you are using assembly for the push operation, you can do the whole thing in assembly in about 20 bytes (probably 21). Assuming 51 code and generic 51 syntax, mov B,_radix mov A,_lval div AB ; A = lval / radix, B = lval % radix mov _lval,A ; save new lval or what's left to print mov A,B add A,#'0' ; convert to ascii cjne A,'9'+1,$+3 ; set flags jc $+4 ; brif no adjustment add A,#7 ; adjust to 'A' through 'F' mov _ch,A ; value to print or whatever push ACC ; put it on the stack too I first saw this technique a zillion years ago for 8080/Z80 machines. #################### g....@gm... wrote: > On Sun, 03 Jun 2001, was wrote: > >>> Hi All! >> >> I doing my program and understand that have not more free memory in data >> segment (stack overflow). I change printfl.c and reduce use data and code >> memory of printf_small in 2 time. Offer my printfl.c for test. >> Vasiliy Zharkov >> wa...@ic... >> > > you could also save at least 20 codebytes by replacing > > do > { > if(radix != 16) ch = (lval % radix) + '0'; > else ch = "0123456789ABCDEF"[(unsigned short)lval & 0x0f]; > _asm push _ch _endasm; > lval /= radix; > } > > with somthing like this > > do > { > ch = (lval % radix) + '0'; > if (ch>'9') ch+=7; > _asm push _ch _endasm; > lval /= radix; > } > > > > ---------------------------------------- > Content-Type: application/octet-stream; name="printfl.c" > Content-Transfer-Encoding: 7bit > Content-Description: > ---------------------------------------- > -- > MFG Gernot > > _______________________________________________ > Sdcc-user mailing list > Sdc...@li... > http://lists.sourceforge.net/lists/listinfo/sdcc-user > > |