Search code examples
c++microcontrollerpointer-arithmetic

Difference between 24bit addresses and 24bit arithmetic vs 24 bit address with address arithmetic of 16 bit address?


i have found in the c167 Dokumentation a note on arithmetic of pointers. There are two macros _huge and _shuge.

A cite from the Doku:

_huge or _shuge. Huge data may be anywhere in memory and you can

also reference it using a 24 bit address. However, address arithmetic is

done using the complete address (24 bit). Shuge data may also be

anywhere in memory and you can also reference it using a 24 bit address.

However, address arithmetic is done using a 16 bit address.

So what is the difference in the usage of _huge vs _shuge? In my understanding the arithmetic of pointers is using an offset from a start address

Example of what I understood so far:

&a[0] + 1 where one element of a is int32 &a[0] gives me the address of the first element thi s would be equal to 0x1234211 + 32Bit for example.**

Is there a difference considering the Note from above and what is the difference in _huge and _shuge?

best regards


Solution

  • Huge was used in the (good?) old 8086 family mode addressing. These were 16 bit processors with a 24 bits address bus. A full address was given by a segment (16 bits) address and an offset (again 16 bits), with the following formula:

    linear_address = segment * 16 + offset
    

    The difference between 2 _huge adresses was computed by first converting both to 24 bits linear addresses and substracting that value, while for _shuge one, segment and offset were separately substracted.

    Example 0010:1236 - 0011:1234 would give 0000:0012 (18) if computed as _huge and 0001:0002 as _shuge