What will be the size of pointer on a 8 bit microcontroller like 8051?

陌路散爱 提交于 2021-01-29 02:47:26

问题


We know that size of the pointer depends on address bus,so what will be the size of pointer on 8 bit microcontroller like 8051?


回答1:


The 8051 is not a C friendly processor.

It has several address spaces. I used the Keil 8051 compiler extensively and it had several pointer types.

  • An 8 bit pointer to point at the internal memory space or internal indirect space.
  • A 16 bit pointer to point to either external ram or code space.
  • A "smart" 24 bit pointer that could point anywhere. Basically a tag followed by 16 bits.

All of this is without the added complexity of bank switching schemes that make things even more "interesting".

The smart pointers where to be avoided because they were big and slow.




回答2:


A compliant C compiler requires SIZE_MAX to be at least 65535 (0xFFFF). This implies an object pointer must be at least 16 bits.

Given the 8051 architecture, it is not likely to have a wider pointer, but could. It depends on the compiler and more than just the processor, but the target platform with its memory. The extended 8051 family does include 32-bit machines.

Note that an object pointer and function pointer may have different widths.




回答3:


The limits imposed by stdint.h contain the constants INTPTR_MIN/INTPTR_MAX in both freestanding and hosted implementations (4. Conformance, ISO/IEC 9899:).

From 7.18 Integer types <stdint.h>

7.18.2.4 Limits of integer types capable of holding object pointers
— minimum value of pointer-holding signed integer type
INTPTR_MIN                           −(2^15 − 1)
— maximum value of pointer-holding signed integer type
INTPTR_MAX                            2^15 − 1
— maximum value of pointer-holding unsigned integer type
UINTPTR_MAX                           2^16 − 1

If you have an exotic processor that has an address bus of 8 you cannot implement C on it, but surely such a processor does not exist.

If you have a processor that has a bus width of 16 and a data bus of 3 bits, you can implement the data types imposed by the C abstract machine, but using many fetches for each operation.

Also, on exotic architectures, it is not a direct correspondence (isomorphism) between the bits from the abstract C machine and the physical wires. Some wires may not be used, other wires could keep correction codes, other wires may generate trap representation. On such architectures it is more difficult to make implementations of C.



来源:https://stackoverflow.com/questions/40977168/what-will-be-the-size-of-pointer-on-a-8-bit-microcontroller-like-8051

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!