++FarPtr limited to 64K

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

++FarPtr limited to 64K

Jump to solution
1,081 Views
dp
Contributor III
CodeWarrior HCS12X 4.5
S12XDP512
Banked memory model
Minimal start-up

byte *__far FarPtr = (byte *__far)0x78FFFF;
++FarPtr;
The result is 0x780000 not 0x790000.
Labels (1)
Tags (1)
0 Kudos
1 Solution
315 Views
CompilerGuru
NXP Employee
NXP Employee
That's correct.
for the HCS12X, __far data pointers can only point inside of a 64k page.
Or in other words, the pointer arithmetic is performed on 16 bits.

The reason of this limitation is not actually the pointer increment. Doing a 24 bit pointer increment is more expensive than a 16 bit one, but not that much. The main problem I see is that for offsets (e.g. ptr[1] or ptr->field), the compiler could never use any indexed addressing modes at all (with a offset != 0), as the CPU does not propagate the offset in its address calculations to the page. And that would really generate a lot more code when accessing struct fields.

Daniel

View solution in original post

0 Kudos
1 Reply
316 Views
CompilerGuru
NXP Employee
NXP Employee
That's correct.
for the HCS12X, __far data pointers can only point inside of a 64k page.
Or in other words, the pointer arithmetic is performed on 16 bits.

The reason of this limitation is not actually the pointer increment. Doing a 24 bit pointer increment is more expensive than a 16 bit one, but not that much. The main problem I see is that for offsets (e.g. ptr[1] or ptr->field), the compiler could never use any indexed addressing modes at all (with a offset != 0), as the CPU does not propagate the offset in its address calculations to the page. And that would really generate a lot more code when accessing struct fields.

Daniel

0 Kudos