C is a common language for embedded systems, because of its broad compiler support and being lightweight on memory.

The volatile specifier tells the compiler not to optimise anything associated with the variable. There are a few important use cases of this, including when we interface with hardware that changes the value itself (as opposed to within the program).

In Nios, using volatile tells the compiler to use ldwio and stwio instructions instead of ldw and stw.

Certain types will map to particular bit lengths. From here, we can effectively interface with any embedded device as flexibly as needed.

  • int corresponds to a 32-bit number, so any 32-bit system can store addresses in int.
  • short int corresponds to a 16-bit number, i.e., a half-word in a 32-bit system.
  • long int corresponds to a 64-bit number, i.e., a full word in a 64-bit system.
  • char corresponds to an 8-bit number, i.e., a byte in a 32-bit system.