Reviewing Programming Languages

A review of the basics of a computer and programming languages...

A Computer and Its Instructions

🖥️ A computer operates based on a series of instructions — the source code written by a programmer.

🖥️ However, a computer’s CPU can only directly understand one language — the machine language (or machine code).

🖥️ An instruction in machine language is composed of sequences of binary digits (or bits), where each bit is either a 1 or a 0.

Machine Code

🖥️ Machine code is inherently machine-dependent, that is, the instructions are tailored to a particular computer architecture — what defines the structure and capabilities of a machine, including how it processes instructions.

🖥️ The downside? Portability. Machine code that works correctly for Computer A might behave differently for Computer B.

🖥️ Example: the instruction 01100110 00001010 might represent an instruction for adding two numbers together in the context of Computer A.
But the same bit sequence could function differently (or not at all) in the context of Computer B.

Assembly Code

🖥️ Writing instructions directly in sequences of bits is rather complex and error-prone. Hence the development of assembly language, where instructions are written using short abbreviations (or mnemonics), names, and numbers, instead of raw bits, making it more human-readable.

🖥️ Example: “ADD A, 3” in assembly means “add the value 3 to the value in register A“, where “register” is a fast storage area located in the computer’s CPU.

🖥️ Like machine code, assembly code is machine-dependent.

🖥️ Additionaly, the CPU cannot directly understand assembly language. An assembler is needed to translate assembly code to machine code.

Low-Level Languages

🖥️ Low-level languages, such as machine language and assembly language, have instructions that allow for direct and close access to the computer’s hardware, such as CPU operations and memory management.

🖥️ But the downside is the complexity in writing and understanding them, as well as issues of portability.

High-Level Languages

🖥️ High-level languages, such as C, C++, and Java, address the issues of complexity and portability associated with low-level languages.

🖥️ They provide a level of abstraction that allows programmers to write code without needing to consider the underlying computer architecture.

🖥️ A C++ program written for Computer A is generally expected to behave the same when run on Computer B, assuming the environment and dependencies are compatible.

🖥️ High-level languages have more human-readable syntax.

🖥️ Example: “c = a + b;" in C++ means “add the value in a to the value in b and store the result in c“. Here, a, b, and c are variables that represent locations in the computer’s memory.

🖥️ While these variables abstract the details of memory management, they are indeed associated with specific locations in the computer’s memory.

🖥️ I like to think of low-level languages as “closer to the machine” whilst high-level languages as “closer to the human programmer“.

Leave a Reply

Your email address will not be published. Required fields are marked *