HCS08C: Small Memory Model and _near pointer qualifier for optimization

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

HCS08C: Small Memory Model and _near pointer qualifier for optimization

4,098件の閲覧回数
BasePointer
Contributor II
Hi,
 
I'm using small memory model for my LC60 application. All my pointers have two bytes.
When should I use __near qualifier to pointer types for more efficient code generation?
 
10x
BP.


Message Edited by BasePointer on 2008-04-28 06:18 PM
ラベル(1)
タグ(1)
0 件の賞賛
返信
6 返答(返信)

2,228件の閲覧回数
fabio
Contributor IV
Hi BP,

You should use the __near qualifier only when your variable is located in the direct page area (as this is the only area that can be accessed using DIR addressing mode and thus 1-byte address).

Best regards,


0 件の賞賛
返信

2,228件の閲覧回数
BasePointer
Contributor II
Hi,
 
If I declare an array (for example "char foo[30];" ) in direct page area, will the compiler automatically use __near pointer when it reachs them?
 
10x,
BP.
0 件の賞賛
返信

2,228件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
Yes and no, it depends on which kind of pointer we talk about.
The compiler does not touch user defined pointers, if you define a pointer into the array, the compiler will use a __near pointer only if that pointer is defined as __near pointer.
On the yes side, pointers defined by just using the array, for example with the address (&) operator, or with [] are automatically near pointers.

Below some test code

Daniel

Code:
#pragma push#pragma DATA_SEG __SHORT_SEG MY_ZEROPAGEchar foo[30];#pragma popchar * ptr_far = foo; // not a near pointerchar *__near ptr_near = foo; // explicit near pointerchar i = 0;void f0(void) {  *ptr_far = 1;}void f1(void) {  *ptr_near = 2;}void f2(void) {  foo[i] = 3; // automatically uses __near.}

 
generates:
Code:
    4:  #pragma push    5:  #pragma DATA_SEG __SHORT_SEG MY_ZEROPAGE    6:  char foo[30];    7:  #pragma pop    8:  char * ptr_far = foo; // not a near pointer    9:  char *__near ptr_near = foo; // explicit near pointer   10:     11:  char i = 0;   12:  void f0(void) {Function: f0Options : -Cs08  -Ms   13:    *ptr_far = 1;  0000 a601     [2]             LDA   #1  0002 320000   [5]             LDHX  ptr_far  0005 f7       [2]             STA   ,X   14:  }  0006 81       [6]             RTS      15:  void f1(void) {Function: f1Options : -Cs08  -Ms   16:    *ptr_near = 2;  0000 a602     [2]             LDA   #2  0002 ce0000   [4]             LDX   ptr_near  0005 8c       [1]             CLRH    0006 f7       [2]             STA   ,X   17:  }  0007 81       [6]             RTS      18:  void f2(void) {Function: f2Options : -Cs08  -Ms   19:    foo[i] = 3; // automatically uses __near.  0000 ce0000   [4]             LDX   i  0003 8c       [1]             CLRH    0004 a603     [2]             LDA   #3  0006 e700     [3]             STA   @foo,X   20:  }  0008 81       [6]             RTS  

 



0 件の賞賛
返信

2,228件の閲覧回数
BasePointer
Contributor II
Hi Guru,
 
As I saw, function f0() consumes 7 bytes (far pointer). But f1(near pointer) consumes 8 bytes. Are far pointers more efficient?
 
10x,
BP.
 
0 件の賞賛
返信

2,228件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
no, there are cases like this one, extended loading and only dereferenciation where they are a bit shorter (but not faster in this case, BTW). Most of the time, and especially when you manipulate them (increment, compute, pass around, ...) far pointers are less efficient.

For plain dereferenciation however it does not matter much.

Daniel

(and, BTW, __far pointers also occupy twice as much RAM)
0 件の賞賛
返信

2,228件の閲覧回数
fabio
Contributor IV
No,

As far as I know, you must use the __near modifier to instruct the compiler to use DIR addressing mode.

You can create a simple application and use the simulator to see the results your own.

Best regards,


Message Edited by fabio on 2008-04-28 04:00 PM
0 件の賞賛
返信