in mikrobasic Avr :
program MyProject
main:
dim s as char[5] data
dim s2 as char[5] data
s2="Hello"
s=s2
ddra=0
end.
in mikrobasic all code run in 96 Cpu Clock Cycle
'-------------
But in Mikroc Avr :
void main()
{
char s[6];
char s2[6]="Hello";
strcpy(s,s2);
ddra=0;
}
in mikroC All code run in 187 Cpu Clock Cycle!!!
'------------
strcpy() is very Low speed!!!
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: strcpy() is very Low speed!!!
Hi,
Indeed for execution of the strcpy() routine compiler "perform" several steps.
If you take a look at listing file, you can see something like:
I will certainly pass your suggestion to my colleagues from Software Department to consider to implement some quicker routine in our compilers.
Best regards,
Marina
Indeed for execution of the strcpy() routine compiler "perform" several steps.
If you take a look at listing file, you can see something like:
Code: Select all
;LedBlinking.c,30 :: strcpy(s,s2);
0x0094 0x922F PUSH R2
0x0096 0x923F PUSH R3
0x0098 0x924F PUSH R4
0x009A 0x925F PUSH R5
0x009C 0xE6B0 LDI R27, lo_addr(_s2+0)
0x009E 0x2E4B MOV R4, R27
0x00A0 0xE0B0 LDI R27, hi_addr(_s2+0)
0x00A2 0x2E5B MOV R5, R27
0x00A4 0xE6B6 LDI R27, lo_addr(_s+0)
0x00A6 0x2E2B MOV R2, R27
0x00A8 0xE0B0 LDI R27, hi_addr(_s+0)
0x00AA 0x2E3B MOV R3, R27
0x00AC 0xDFD8 RCALL _strcpy+0
Best regards,
Marina
Re: strcpy() is very Low speed!!!
HI,
suggestion!
//S=S2
//this is Low speed===>strcpy(s,s2);
//but is fastest... :
r30= ((unsigned int)(&s2)); //zl From
r31=((unsigned int)(&s2)) >> 8 ; //zh From
r26=((unsigned int)(&s)); //xl To
r27=((unsigned int)(&s)) >> 8; //xh To
asm {
L_loopCS2Ss2:
LD R0, Z+
ST X+, R0
TST R0
BRNE L_loopCS2Ss2
}
and also
EX)
//Set Default value
//this is Low speed===>char s2[10]="aLI201234";
//but is faster
const char a[]= "aLI201234" ;
char s2[10];
r30= ((unsigned int)(&a)); //zl 'from
r31=((unsigned int)(&a)) >> 8 ; //zh 'from
r26=((unsigned int)(&s2)); //xl 'to
r27=((unsigned int)(&s2)) >> 8; //xh 'to
asm {
L_loopCS2Ss3:
LPM R0, Z+
ST X+, R0
TST R0
BRNE L_loopCS2Ss3
}
suggestion!
//S=S2
//this is Low speed===>strcpy(s,s2);
//but is fastest... :
r30= ((unsigned int)(&s2)); //zl From
r31=((unsigned int)(&s2)) >> 8 ; //zh From
r26=((unsigned int)(&s)); //xl To
r27=((unsigned int)(&s)) >> 8; //xh To
asm {
L_loopCS2Ss2:
LD R0, Z+
ST X+, R0
TST R0
BRNE L_loopCS2Ss2
}
and also
EX)
//Set Default value
//this is Low speed===>char s2[10]="aLI201234";
//but is faster
const char a[]= "aLI201234" ;
char s2[10];
r30= ((unsigned int)(&a)); //zl 'from
r31=((unsigned int)(&a)) >> 8 ; //zh 'from
r26=((unsigned int)(&s2)); //xl 'to
r27=((unsigned int)(&s2)) >> 8; //xh 'to
asm {
L_loopCS2Ss3:
LPM R0, Z+
ST X+, R0
TST R0
BRNE L_loopCS2Ss3
}
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: strcpy() is very Low speed!!!
Hi,
Thank you very much for your suggestions, I will pass it to our software developers.
Best regards,
Marina
Thank you very much for your suggestions, I will pass it to our software developers.
Best regards,
Marina