Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Andy Neil
01/04/08 03:00
  01/04/08 03:20

Read: 5687 times

#149030 - Do it in assembler
Responding to: Jae-yong Kim'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:
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!

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


List of 27 messages in thread
Number of CPU cycle for 8051 function call      Jae-yong Kim      01/04/08 01:03      
   Do it in assembler      Andy Neil      01/04/08 03:00      
   Delay functions      Andy Neil      01/04/08 03:07      
   A related trick        Russ Cooper      01/04/08 05:56      
      Offset      Andy Neil      01/04/08 07:03      
         Offset      Russ Cooper      01/04/08 07:23      
            Sure      Andy Neil      01/04/08 07:40      
               Over Drive?      Neil Kurzman      01/04/08 10:20      
      a refinement      Erik Malund      01/04/08 07:58      
      NOPs are so bad waste of space...      Jan Waclawek      01/04/08 08:51      
         waste of space... waste of time      Erik Malund      01/04/08 09:24      
            fixed delay      Jan Waclawek      01/04/08 09:54      
               Variable delay      Russ Cooper      01/04/08 11:04      
                  determinism of the cache      Jan Waclawek      01/04/08 11:36      
               there are no cache misses in 'linear code'      Erik Malund      01/04/08 11:16      
                  I got only ONE cache miss...      Jan Waclawek      01/04/08 11:39      
      Old Keil Thread      Jon Ward      01/06/08 18:29      
   What about a Delay like this.      Jerry Black      01/07/08 05:31      
      No, it won't.        Christoph Franck      01/07/08 05:55      
         Ok.      Jerry Black      01/07/08 07:08      
         also      Erik Malund      01/08/08 06:47      
      Also ...      Christoph Franck      01/08/08 07:01      
         Actually...      Brett Wallace      01/08/08 08:02      
            will.      Jerry Black      01/08/08 08:21      
               ANSI C      Maarten Brock      01/10/08 05:58      
                  Keil option: Disable ANSI casts      Andy Neil      01/10/08 07:08      
         typo.      Jerry Black      01/08/08 08:24      

Back to Subject List