??? 09/28/04 12:05 Read: times |
#78263 - RE: Keil strncpy function doubt????? Responding to: ???'s previous message |
hi,
will generate the faster and smaller code Probably the faster code will be generated with direct copy from one location to another one. If they are placed inside data memory (0x00...0x7F) then compiler generates direct move instructions: MOV direct,direct. If they are placed somewhere inside idata then compiler uses pairs of MOV A,@Ri and MOV @Ri,A instructions. If they are placed inside xdata then pairs MOVX A,@DPTR and MOVX @DPTR,A will be used. Anyway this is the faster way. But in two last cases it is not the shortest way because compiler generates pairs of these instructions for the each byte copy. In fact, the size and speed are not well defined when you use C-language due different optimization levels. As the bad example, next part of program may produce small code: { unsigned char data volume_disp[6]; unsigned char data counted_pulses[6]; //.... //.... { unsigned char data size; unsigned char data * data dest=volume_disp; unsigned char data * data src=counted_pulses; for (size=6; size; size--,dest++, src++) *dest=*src; } // .... }But with some optimization levels, compiler may use registers for variables. As we specified that variables must be placed into data segment so compiler cannot use registers optimization and is not able to produce even smaller and faster code than above! Finalize, if you need control the size or speed of code then use assembler. But if you really need with it. Regards, Oleg |