Why Is C Easier to Port Across Platforms Than Assembly?

A question suddenly came to mind today: why does C have relatively good portability, while assembly is usually difficult to port across different architectures?

The key is that they express program behavior at different levels.

Assembly code already targets a specific ISA. When writing assembly, I need to use the instructions, registers, and operations that architecture provides. For example, a piece of RISC-V assembly cannot be executed directly on an ARM CPU. Changing architectures usually means reworking the implementation.

C provides a higher level of expression. When I write c = a + b, I am expressing “add a and b, then assign the result to c,” without specifying which registers or machine instructions must be used.

Compilers targeting different platforms can translate the same C source code into machine code suitable for each platform. The programmer keeps a relatively general description of the behavior and leaves the choice of specific instructions to the compiler. This is an important reason why C is easier to use across platforms.

What I understand as portability today is mainly source-code portability: when the language and execution-environment requirements are met, the same source code can be recompiled for different platforms, rather than the same executable running everywhere.

C leaves room for the compiler to choose an implementation for the target platform; assembly has already written more of those specific machine choices into the code.

I have been reading The C Programming Language. With my teacher’s guidance today, I began to reconsider how I approach this book: as more than a reference manual or a guide to quickly learning C syntax.

My teacher suggested a method: “pruning (planting a stake)”—choosing a single target to explore in depth.

At this stage, I do not need to finish learning all the fundamentals before tackling real problems. I can start exploring a specific problem and fill in the relevant foundations as needed.

When new questions arise during that exploration, I can write them down without immediately following every branch. First, I should clarify exactly what I want to understand this time and make that the focus of my exploration.