0

I would appreciate it a lot for your patience to explain on a seemingly naive question?

An Arduino Uno with 8-bit MCU (ATmega328), yet we program it with 32 bit C program customs? why?

  1. Arduino Uno(for example), uses the 8-bit AVR MCU (ATmega328), which I understand the addressing mode and basic arithmetic operations are on 8-bit operations,

  2. while when I program in the Arduino IDE, by default I am programming like it is a 32-bit C/C++ program (for example, I can define uint32_t,....or, )

so is this all done by the compiler in Arduino IDE ? (who's that ? avr-gcc? )

and... the compile does more work to translate 32-bit arithmetic operations to 8-bit arithmetic operations ?

shapiro yaacov
  • 2,308
  • 2
  • 26
  • 39
rayzi001
  • 45
  • 3
  • Maybe this related post can address some aspects of your question: http://electronics.stackexchange.com/questions/106933/how-different-are-8-bit-microcontrollers-from-32-bit-microcontrollers-when-it-co – user3704293 Jul 26 '15 at 12:27
  • @user3704293 thanks a lot, that link basically address my confusions =D – rayzi001 Jul 27 '15 at 22:20

2 Answers2

1

Each processor / micro controller operates on a specific instruction set. Essentially it is the compilers job to compile your source code into machine code, thus the compiler has to know the (8-bit) instruction set of the processor. So if you take a uint32_t addition for example, it has to "compile" it into several add instructions, because the 8-bit AVR is only able to add two 8 bit values. This is a simplified example but I hope you get the idea.

Rev
  • 5,827
  • 4
  • 27
  • 51
1

As was previously said, 32-bit arithmetic operations get broken down into multiple 8-bit operations which your 8-bit MCU can handle. I haven't tried it myself, but I would suspect that doing anything more complicated than simple arithmetic with larger variable types will consume a lot more of your hardware resources, and should probably be avoided if possible.

Daniel
  • 247
  • 3
  • 11
  • Exactly. I read from the link http://electronics.stackexchange.com/questions/106933/how-different-are-8-bit-microcontrollers-from-32-bit-microcontrollers-when-it-co and get insights that a lot more hardware resources / assembly code is required for lower-bit MCUs. – rayzi001 Jul 27 '15 at 22:21
  • Especially 32-bit floating point operations are indeed very resource intensive on a 8-bit controller, since there is (normally) no floating point arithmetic hardware support on such "small" devices. – Rev Jul 28 '15 at 06:30