💻 C and Assembly with Raspberry Pi

C Fundamentals

The C Programming Language

C (named as the successor to the B programming language) is a general-purpose, structured programming language characterized by its proximity to hardware and high execution speed. It was developed between 1969 and 1972 by Dennis Ritchie at AT&T Bell Laboratories to program the Unix operating system efficiently and portably. C represents the third generation of programming languages and bridges the gap between hardware-level assembly programming and modern high-level languages.

A key advantage of C lies in combining two worlds: while developers can write complex data structures and control structures (such as loops or branches) in readable code, C allows precise resource control through pointers and direct memory access. Written C code is translated into machine code by a compiler (such as gcc or clang). Unlike highly abstract languages such as Python or Java, C has no automatic garbage collection—the programmer retains full control, but also bears the responsibility for memory management.

Because C is highly efficient and introduces almost no abstraction overhead, it remains the foundation of modern software development to this day. Operating system kernels (such as the Linux kernel or Windows), device drivers, databases, and embedded systems are largely written in C. Many subsequent languages—such as C++, C#, Java, or PHP—have also modeled their syntax directly on C.

C on the ARM Architecture

In the world of ARM processors, C plays a key role. Because assembly code is highly specific to a particular instruction set architecture, writing larger programs in assembly requires immense effort. C offers the ideal compromise: code can be written in a largely platform-independent manner, yet translated into extremely efficient machine code using ARM-optimized compilers.

On the Raspberry Pi 4 and Raspberry Pi 5 systems, C and ARM assembly work hand in hand. Many hardware-level applications use C as the primary language and only insert short assembly routines for extremely time-critical or processor-specific sections (inline assembly).

To write and compile C programs for the Raspberry Pi, we use the GCC toolset (GNU Compiler Collection). During the compilation process, the compiler often internally translates the C code into ARM assembly code as an intermediate step before generating the final executable binary. Thus, C serves as an excellent model for understanding how abstractly defined instructions map directly to the actual microarchitecture of the Broadcom BCM2711 (ARMv8 / Raspberry Pi 4) or BCM2712 (ARMv8.2-A / Raspberry Pi 5).

In the following sections, we will set up the development environment for C and create our first programs, demonstrating how C interacts directly with the hardware resources of the Raspberry Pi.