Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#114 common function head merging

open
nobody
None
1
2006-01-29
2006-01-29
No

it would be nice to have a merging of common function
heads:

------------------8<------------------------------------
/* both calls of "printf("%05u\n", scale(adc16));"
share a few bytes of code.

It would be nice if both calls would be
substituted against
lcall _commoncode
instead of
lcall _printf

with commoncode in this case being
commoncode::
mov dph,(_adc16 + 1)
lcall _scale
mov r2,dpl
mov r3,dph
push ar2
push ar3
mov a,#__str_0
push acc
mov a,#(__str_0 >> 8)
push acc
mov a,#0x80
push acc
; lcall _printf
ljmp _printf

(in this moderately pushed up case about
32 bytes are saved which would be difficult
to save elsewhere:)

*/

#include <stdio.h>

volatile unsigned int adc16;
unsigned char sel;

unsigned int scale(unsigned int in){
return in*4/3;
}

void select(unsigned char i){
sel = i;
}

void main(void){
while(1){
select(0);
printf("%05u\n", scale(adc16));

select(1);
printf("%05u\n", scale(adc16));
}
}

Discussion