2024-04-20

AVR-GCC is a compiler that takes C language high level code and creates a binary source which can be uploaded into an AVR micro controller. Thus AVR-GCC might be regarded as a 'C' cross compiler for producing AVR code. AVR-libc are 'C' run-time libraries, header files, and documentation primarily for the AVR target and are used in conjunction with AVR-GCC . Please note that AVR-libc and AVRLIB are different sets of libraries but both work with the AVR-GCC compiler.

Once code in 'C' is written for a particular project AVR-GCC will turn C code into assembly language files. AVR-libc includes all the header files that contain the addresses of port and register names, the floating point library, AVR-specific macros, and AVR start-up code. It also provides a lot of documentation, both on the library items itself as well as on a number of general items on the entire tool chain, including a FAQ.

Individual assembler files are then converted into object files. Object files are files of code that AVR chips could run. The linker AVR-ld will take all these assembler files, and cross-reference functions names to create one single object file. The linker will also take modules from the 'C' library and make them into a single object. Normally this linked object is in ELF format and furthermore AVR-objcopy is used to generate a HEX format file.

source

My primary motivation for using avr-gcc at the moment is for compiling assembly to an Arduino Uno using ATMega328p.

The building process of an assembly file through avr-gcc is as follows:

  1. The assembly file goes through the preprocessor, where all macros are evaluated, and comments are removed.
  2. The assembly code needs to be converted to an object/elf file. This file is generated by an assembler. This type of file holds the opcode for the particular architecture along with the data for the program (strings, constants, etc.), plus some other metadata.
  3. Your code may require code from other libraries, or from other files. A linker will link all of the necessary files into a single program with an obvious entry point.
  4. This program now gets converted to a HEX file, which will transform the previous file with all opcodes into something that can be uploaded directly to the flash.

The avr-gcc compiler also includes the following tools:

For more info about compiling from avr-gcc straight to arduino see:

from_asm_to_arduino