integer - 8 位、16 位、32 位处理器/微 Controller 中整数的大小是多少?

标签 integer microcontroller processor microprocessors

8 位、16 位、32 位处理器/微 Controller 中整数的大小是多少?
我想这取决于内部累加器/寄存器的大小。但不确定。
谢谢

最佳答案

我只知道一种定义 integer 数据类型的编程语言,但它很少用于 8 位和 16 位架构。 C 是用于 8 位、16 位和 32 位体系结构编程的最广泛使用的语言,因此我假设您正在寻找 C 上下文中的答案。

C 中有几种“整数”数据类型: charshortintlong 等...,但我会假设你真正的意思是 int 数据类型。
int 的大小不是由体系结构定义的,而是由 C 编程语言规范定义的,并且非常模糊。

A ‘‘plain’’ int object has the natural size suggested by the architecture of the execution environment (large enough to contain any value in the range INT_MIN to INT_MAX as defined in the header <limits.h>).



我解释这意味着它是由编译器的实现决定的。

您可以在此处找到 C11 标准的最新公开可用版本(在撰写此答案时): http://www.open-std.org/jtc1/sc22/wg14/www/standards.html

以下是我为帮助回答这个问题而进行的一些测试:
  • 在 8 位 Atmel AVR Arduino 上,sizeof(int) 在使用 GCC 4.3.2 (WinAVR 20081205) 编译时返回 2(例如 16 位)
  • 没有 16 位 MCU 或编译器,抱歉!
  • 在 32 位 ARM Cortex-M MCU 上,sizeof(int) 在使用 GCC 4.9.2 编译时返回 4(例如 32 位)。
  • 在 64 位 Intel Core i7 CPU 上,无论是针对 32 位还是 64 位编译,sizeof(int) 都会返回 4(例如 32 位)。使用 Visual Studio 2013 和 GCC 4.9.2 进行测试。

  • 一个更有趣的答案是为什么选择这些值。

    关于integer - 8 位、16 位、32 位处理器/微 Controller 中整数的大小是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29618439/

    相关文章:

    c - 迭代未知长度的 int 数组

    C++ 获取处理器 ID

    android - 通过找到将以60fps和30fps运行的最佳设置来摆脱性能设置旋钮

    java - 如何对十进制数执行 Integer.parseInt()?

    c++ - 整数除法与浮点除法 -> 谁负责提供结果?

    c - 如何在C中显示十六进制数?

    linux - 我想继续学习 µC 编程,但我完全不知道从哪里开始

    c - 确定 C 趋势 - 微 Controller 采样

    algorithm - arctan 是如何实现的?

    c - 以英文显示整数上每个数字的程序不适用于以 "0"开头的整数