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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/17/07 16:53
Read: times


 
#139448 - More on Erik's Rules
Responding to: ???'s previous message
It maybe be worth the trouble to elaborate on Erik's rules a little bit. The reasoning behind them is that at the assembly language level, each of the different address spaces needs a different sequence of code to access it. As an example, consider this simple C fragment:
int i;
i = 520;
If 'i' is in the DATA space, a hypothetical compiler might generate something like this:
MOV   i,#2
MOV   i+1,#8
If 'i' is in the IDATA space, the same compiler might generate this:
MOV   R0,#i
MOV   @R0,#2
INC   R0
MOV   @R0,#8
Finally, if 'i' is in the XDATA space, the compiler needs to do this:
MOV   DPTR,#i
MOV   A,#2
MOVX  @DPTR,A
INC   DPTR
MOV   A,#8
MOVX  @DPTR,A
From these examples, it's easy to see that DATA variables are accessed the fastest, followed by those in the IDATA space, followed by those in the XDATA space. These facts form the basis for Erik's rules.

Stay away from the LARGE memory model, always use SMALL

The large memory model puts all variables in XDATA space by default, which is exactly what you don't want if you're worried about execution speed and/or code size.

If it is accessed diretly, use DATA

DATA variables are the only ones the 8051 can access directly, so it only makes sense to put variables that you plan to access directly there.

If it is pointed to, use IDATA

Variables in IDATA space are naturally accessed indirectly, so IDATA is the natural place to put variables that you plan to access through pointers. (You could just as well put indirectly accessed variables in the DATA space, except that you will probably want to conserve it for directly addressed variables due to its limited size.)

If then you run out of variable storage, carefully select the most rarely accessed variables and move those to XDATA.

When all else fails, use XDATA where it will hurt you the least.

One other point, of course, is that larger data structures won't fit in the relatively small DATA and IDATA areas. If you need a 500-byte buffer, it has to go in XDATA.

-- Russ




List of 43 messages in thread
TopicAuthorDate
How to speed code?            01/01/70 00:00      
   How did you come to that bizarre idea...            01/01/70 00:00      
      bizarre!?            01/01/70 00:00      
         I am a C-hater, remember...            01/01/70 00:00      
      Smaller, Faster            01/01/70 00:00      
   Is that true??            01/01/70 00:00      
   Often mutually exclusive...            01/01/70 00:00      
   Take my contribution with a grain of salt.            01/01/70 00:00      
      http://www.8052.com/users/disasm/            01/01/70 00:00      
   what compiler?            01/01/70 00:00      
   Data types            01/01/70 00:00      
   Getting the least            01/01/70 00:00      
   My Two Cents            01/01/70 00:00      
      Turn in your Programmer's ID Card.            01/01/70 00:00      
         heheh...yeah            01/01/70 00:00      
         SJMP            01/01/70 00:00      
   Comments            01/01/70 00:00      
   How to speed code?            01/01/70 00:00      
   a couple of \'rules\'            01/01/70 00:00      
      More on Erik's Rules            01/01/70 00:00      
         a comment            01/01/70 00:00      
         PDATA            01/01/70 00:00      
            don't forget about @DPTR access to CDATA            01/01/70 00:00      
               but            01/01/70 00:00      
                  WHAT??? You mean I have it too? Dystypia?            01/01/70 00:00      
                     Enginnering is all about the tradeoffs            01/01/70 00:00      
                        two places where you REALLY can make an impact            01/01/70 00:00      
                           b) buffer at 256 byte boundary            01/01/70 00:00      
                              Alignment            01/01/70 00:00      
                              you did'nt hear ?            01/01/70 00:00      
               Another \"but\"            01/01/70 00:00      
                  it is, after all, quicker            01/01/70 00:00      
                     Errr...            01/01/70 00:00      
                        perhaps, but it has to "live" somewhere.            01/01/70 00:00      
                           You\'re assuming...            01/01/70 00:00      
                              confirming Andys statement            01/01/70 00:00      
                                 We WERE discusisng 805x ...            01/01/70 00:00      
                                    well, does it not?            01/01/70 00:00      
                                       Tables in code space vs data space            01/01/70 00:00      
                                          Philps XA, the best "16 bit '51"            01/01/70 00:00      
                                             Maxim/Dallas DS89C450            01/01/70 00:00      
   most compilers            01/01/70 00:00      
      Thanks            01/01/70 00:00      

Back to Subject List