gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:41:49 25 4
gpt4 key购买 nike

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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com