← Back to Computer Science

From machine code to high-level languages

Processors understand only binary machine code. Programming languages let people write instructions in forms closer to human thought, then translate them for the machine.

Levels of language

Machine code is binary instructions the CPU executes directly. Assembly language uses short mnemonics, such as ADD and MOV, that map almost one-to-one onto machine instructions. High-level languages, such as Python, Java, and C, use words, symbols, and structures that are far easier for people to read and that work across different processors.

Early high-level languages

FORTRAN (1957), led by John Backus at IBM, was designed for scientific calculation. COBOL (1959), shaped by Grace Hopper's earlier work, targeted business data processing and still runs in banks and governments. LISP (1958), created by John McCarthy, pioneered ideas used in artificial intelligence and functional programming.

Compilers

A compiler translates a whole program from a high-level language into machine code, or another lower-level form, before it runs. C and C++ are usually compiled. Compiled programs tend to run fast, and the compiler can catch many errors in advance, but each change needs recompiling.

Interpreters

An interpreter reads and executes a program statement by statement, without producing a separate machine-code file first. Python and JavaScript are commonly run this way. Interpreters make it quick to experiment and test changes, but pure interpretation is usually slower than running compiled code.

Bytecode and virtual machines

Many languages mix the two approaches. Java compiles to bytecode, an intermediate form run by the Java Virtual Machine (JVM), so the same compiled program runs on any system with a JVM. Just-in-time (JIT) compilers translate frequently used bytecode or scripts into machine code while the program runs, which is how modern JavaScript engines run fast.

Syntax and semantics

Syntax is the set of rules for how valid code is written, such as where brackets and colons go. Semantics is what the code means when it runs. A syntax error, such as a missing bracket, stops the program from being translated. A program can be syntactically perfect yet semantically wrong, doing something other than intended.

Kinds of errors

Syntax errors break the language's grammar and are found during translation. Runtime errors occur while the program runs, such as dividing by zero or opening a file that does not exist. Logic errors produce wrong results without crashing, such as using + where - was intended; they are found only by testing and careful reasoning.

Worked example

Consider the Python line total = price * quantity. The interpreter checks the syntax, looks up the current values of price and quantity, multiplies them, and stores the result under the name total. In C, the equivalent line would first be compiled, together with declarations saying price and quantity are numbers, into a few machine instructions that load, multiply, and store values in memory.

Key takeaways

Machine code is binary; assembly uses mnemonics; high-level languages are readable and portable. FORTRAN, COBOL, and LISP were early high-level languages. Compilers translate whole programs ahead of time; interpreters execute statement by statement. Java uses bytecode on a virtual machine; JIT compilers speed up running code. Syntax is form; semantics is meaning. Errors can be syntax, runtime, or logic errors.

Flashcard

Machine code

Binary instructions run by the CPU

Lowest level.

Check your understanding

A program runs without crashing but calculates the wrong average. What kind of error is this?

Take the unit quiz

← Previous lesson Next lesson →