Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the size of integer in 8-bit, 16-bit, 32-bit processors/microcontrollers?

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

like image 817
Kiran Avatar asked Dec 19 '22 05:12

Kiran


1 Answers

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.

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.

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.

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.

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:

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

like image 124
Verax Avatar answered Apr 26 '23 21:04

Verax