8位,16位,32位处理器/微控制器中整数的大小是多少? [英] What is the size of integer in 8-bit, 16-bit, 32-bit processors/microcontrollers?

查看:254
本文介绍了8位,16位,32位处理器/微控制器中整数的大小是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

8位,16位,32位处理器/微控制器中整数的大小是多少? 我猜这取决于内部累加器/寄存器的大小.但不确定. 谢谢

What is the size of integer in 8-bit, 16-bit, 32-bit processors/microcontrollers ? I guess it depends on the internal accumulator/register size. But not sure. Thanks

推荐答案

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

I'm only aware of one programming language that defines an integer data type, but it's seldom used for 8 and 16-bit architectures. C is the most widely used language for programming 8-bit, 16-bit, and 32-bit architectures, so I assume you are looking for an answer in the context of C.

C中有几种整数"数据类型:charshortintlong等,但是我将假设您真正的意思是int数据类型.

There are several "integer" data types in C: char, short, int, long, etc..., but I will assume what you really mean is the int data type.

int的大小不是由体系结构定义的,它是由C编程语言规范定义的,并且非常模糊.

The size of an int is not defined by the architecture, it is defined by the the C programming language specification, and it's extremely vague.

普通" int对象具有执行环境的体系结构建议的自然大小(足够大,可以包含头文件<limits.h>中定义的INT_MININT_MAX范围内的任何值) ).

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>).

我将其解释为由编译器的实现决定.

I interpret this to mean it is determined by the implementation of the compiler.

您可以在此处找到C11标准的最新公共可用版本(在撰写此答案时):

You can find the latest publicly available version of the C11 standard (at the time of writing this answer) here: http://www.open-std.org/jtc1/sc22/wg14/www/standards.html.

以下是我为了帮助回答这个问题而进行的一些测试:

Here are some tests I ran to help answer this question:

  • 在8位Atmel AVR Arduino上,使用ccc 4.3.2(WinAVR 20081205)编译时,sizeof(int)返回2(例如16位)
  • 没有16位MCU或编译器,对不起!
  • 在32位ARM Cortex-M MCU上,sizeof(int)使用GCC 4.9.2编译时返回4(例如32位).
  • 在64位Intel Core i7 CPU上,sizeof(int)返回4(例如32位),无论它是针对32位还是64位编译的.已在Visual Studio 2013和GCC 4.9.2上进行了测试.
  • On an 8-bit Atmel AVR Arduino, sizeof(int) returns 2 (e.g. 16-bits) when compiled with GCC 4.3.2 (WinAVR 20081205)
  • Don't have a 16-bit MCU or compiler, sorry!
  • On a 32-bit ARM Cortex-M MCU, sizeof(int) returns 4 (e.g. 32-bits) when compiled with GCC 4.9.2.
  • On a 64-bit Intel Core i7 CPU, sizeof(int) returns 4 (e.g. 32-bits) regardless of whether it is compiled for 32-bit or 64-bit. Tested with both Visual Studio 2013 and GCC 4.9.2.

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

A more interesting answer would be why those values were chosen.

这篇关于8位,16位,32位处理器/微控制器中整数的大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆