??? 01/04/08 10:00 Modified: 01/04/08 10:20 Read: times |
#149030 - Do it in assembler Responding to: ???'s previous message |
Jae-yong Kim said:
I don't know CPU cycle of function call and return First rule of High-Level Language (HLL) programming: You can never know the CPU cycle count of anyrhing written in any HLL; eg, 'C'. You need to write the entire function in assembler - then you will know exactly what instructions are used, and how long it will take. To do this, prodeed as follows: 1. Start with a "skeleton" in 'C' eg, in delay.c void OW_Delay( Uint8 delay ) { ++delay; // dummy access to the parameter }The dummy access to the parameter is to show you how the compiler accesses the parameter. 2. Get the compiler to translate this to assembler; Use the SRC directive - see: http://www.keil.com/support/m...51_src.htm Be sure to use the minimum optimisation settings. This will create an assembler source file; eg, delay.s Because the Compiler itself has done the translation, you know that the generated assembler is fully compatible with all its Calling Conventions, etc - and, therefore, it is perfect for calling from 'C'! Note that you will need to repeat this operation if you require different Memory Models. 3. Throw away the original 'C' file It has served its purpose - it is of no further use or value. 4. Edit the generated assembler file ie, delay.s In this case, to give the required delay. QEF - Job Done! Addendum Specifically for a software delay function, you don't want any interrupts to mess-up your timing. You can achieve this by using the DISABLE directive in the original 'C' source file - so, for example, it becomes: #pragma DISABLE void OW_Delay( Uint8 delay ) { ++delay; // dummy access to the parameter } See: http://www.keil.com/support/m...isable.htm |
Topic | Author | Date |
Number of CPU cycle for 8051 function call | 01/01/70 00:00 | |
Do it in assembler | 01/01/70 00:00 | |
Delay functions | 01/01/70 00:00 | |
A related trick | 01/01/70 00:00 | |
Offset | 01/01/70 00:00 | |
Offset | 01/01/70 00:00 | |
Sure | 01/01/70 00:00 | |
Over Drive? | 01/01/70 00:00 | |
a refinement | 01/01/70 00:00 | |
NOPs are so bad waste of space... | 01/01/70 00:00 | |
waste of space... waste of time | 01/01/70 00:00 | |
fixed delay | 01/01/70 00:00 | |
Variable delay | 01/01/70 00:00 | |
determinism of the cache | 01/01/70 00:00 | |
there are no cache misses in 'linear code' | 01/01/70 00:00 | |
I got only ONE cache miss... | 01/01/70 00:00 | |
Old Keil Thread | 01/01/70 00:00 | |
What about a Delay like this. | 01/01/70 00:00 | |
No, it won't. | 01/01/70 00:00 | |
Ok. | 01/01/70 00:00 | |
also | 01/01/70 00:00 | |
Also ... | 01/01/70 00:00 | |
Actually... | 01/01/70 00:00 | |
will. | 01/01/70 00:00 | |
ANSI C | 01/01/70 00:00 | |
Keil option: Disable ANSI casts | 01/01/70 00:00 | |
typo. | 01/01/70 00:00 |