Concepts / Programming Languages: High-Level vs. Low-Level

Programming Languages: High-Level vs. Low-Level

A compiler translates an entire program from high-level source code to machine language in one complete pass, then saves the result to an executable file for later execution.

  • Programming

From Human-Friendly Code to CPU Instructions

When programmers write code in a high-level language, they use instructions designed to be practical for humans to write and read. A compiler translates an entire program from high-level source code into machine language in one complete pass. It then saves the translated result in an executable file that can be run later.

The key change is the level of representation. The source file contains high-level statements, while the compiled output contains low-level byte sequences intended for direct CPU execution. The compiler performs the translation before the program is executed.

High-level sourcecodeentire programCompilerchecks and translatesMachine languagelow-level byte sequencesExecutable filesaved for later executionsubmit entire filetranslate every statementsave result
What happens to an entire high-level program during compilation, and where does the resulting machine code go?

A Complete Compilation Pass

  1. 1
    Write the program in a text editor and save it as a source file.
  2. 2
    Run the compiler on that source file.
  3. 3
    The compiler reads the entire file and checks it for errors.
  4. 4
    The compiler translates every statement into machine instructions.
  5. 5
    The compiler outputs a new file containing machine language.
Worked example

Compiling a C Program

Imagine that you have written a program in C and want to run it.

  1. 1
    Write

    You create the C source code in a text editor and save it as a file.

  2. 2
    Submit

    You provide the source file to a compiler.

  3. 3
    Check

    The compiler reads the entire file and checks it for errors.

  4. 4
    Translate

    The compiler translates every statement into machine instructions.

  5. 5
    Save

    The compiler creates a new executable file containing the translated machine language.

Result

The resulting file can be executed later by the operating system.

What an Executable Contains

After compilation, the output file contains machine language. Machine language is made of low-level byte sequences designed for CPU execution rather than human interpretation. It can represent the translated form of high-level constructs such as loops, conditionals, and function calls.

In the real world

If you open an executable file in a text editor, you may see strange symbols, control characters, and unreadable text. This is not necessarily corruption. The file is being viewed as text even though its contents are machine language intended for the CPU.

Windows.exe or .dll suffixMachine languageCPU-executable instructionsLinuxfile permissionsmacOSfile permissionsexecutable file containsexecutable file containsexecutable file contains
How do executable files differ between operating systems, and what characteristics identify each format?
Operating systemHow an executable is identifiedWhat the file contains
Windows.exe or .dll suffixesMachine language
LinuxFile permissionsMachine language
macOSFile permissionsMachine language

The identifying convention differs, but the executable content is machine language.

Compiler Workflow and Interpreter Workflow

A compiler receives the complete source program, translates it, and saves the result before execution. An interpreter instead reads a program and interprets its statements while the program runs. The source describes Python as an interpreted language in this sense.

Source programentire filePython programsource statementsCompilerchecks and translatesInterpreterreads during executionExecutable filemachine languageProgram executionruntime behaviorsubmit before executionsave translated resultprovide at runtimeinterpret statements
How does program execution differ when code is submitted to a compiler first versus an interpreter at runtime?
Compiler workflowInterpreter workflow
The entire source file is submitted to the compiler.The interpreter reads and interprets Python statements while the program runs.
Machine language is saved in an executable file.The program is interpreted during execution.
A compilation error must be fixed before execution.A runtime error can occur after execution has started.

These workflows describe when translation occurs and when errors can appear.

The Compiled Program Behind Python

The Python interpreter is itself a compiled program written in C. Python developers used a C compiler to compile that interpreter. When you type python in a terminal or click the Python application, you launch this compiled C program. That program then reads and interprets Python code.

C source codeinterpreter implementationC compilercompiles oncePython interpretercompiled programPython codeuser programPython executionstatements interpretedsubmit to compilerproducereadsinterprets during run
How does C source code become the Python interpreter, and how does that interpreter then run Python code?

This creates two different translation stages. First, the Python interpreter is created by compiling C source code. Later, when you run Python, that already-compiled interpreter reads and interprets your Python program. Calling Python interpreted does not mean that every part of the Python system was created without compilation.

Mistakes Beginners Make

  • Common mistake

    Assuming that an executable must always end in .exe.

    What it looks like

    A learner sees a runnable file without a suffix on Linux or macOS and concludes that it cannot be executable.

    Why it fails

    Windows uses .exe or .dll suffixes, but Linux and macOS use file permissions instead of suffixes to mark files as runnable.

    Do this instead

    Check the operating system's convention. The absence of a suffix does not by itself mean that a file is not executable.

  • Common mistake

    Expecting machine language to be readable like source code.

    What it looks like

    A learner opens an executable in a text editor and treats the strange symbols as evidence that the file is damaged.

    Why it fails

    Machine language consists of low-level byte sequences designed for CPU execution, not human interpretation.

    Do this instead

    Understand that unreadable characters are expected when machine-language data is displayed as text.

  • Common mistake

    Thinking that Python has no compiled component.

    What it looks like

    A learner assumes that because Python code is interpreted, the Python program used to run it must also be written in Python.

    Why it fails

    The Python interpreter is a compiled program written in C.

    Do this instead

    Separate the compiled C interpreter from the Python code that the interpreter reads and interprets.

  • Common mistake

    Treating compilation errors and runtime errors as the same failure.

    What it looks like

    A learner expects a compiled program to begin running even though its source failed to translate.

    Why it fails

    A compilation error occurs before successful translation, while a runtime error occurs after an interpreted program has started running.

    Do this instead

    First ask whether the failure happened during compilation or during execution.

Check Your Understanding

EASY

Explain the complete path from a C source file to a running program. Include the role of the compiler, the machine-language output, and the executable file.

Hints
  • Start with the source file in a text editor.
  • State that the compiler reads the entire file, checks for errors, and translates every statement.
  • End with the operating system running the saved executable file.
MEDIUM

A learner says, "Python is interpreted, so the Python interpreter cannot be compiled." Explain why this statement is incorrect.

Hints
  • Distinguish the Python interpreter from the Python program.
  • Identify the language in which the interpreter is written.
  • Describe what happens when the interpreter is launched.
MEDIUM

Compare how Windows identifies an executable file with how Linux and macOS identify one. Then explain whether this difference changes the machine-language content of the executable.

Hints
  • Recall the Windows suffixes.
  • Recall the Linux and macOS use of file permissions.
  • Separate file identification from file contents.

Key Takeaways

  1. 1
    A compiler translates an entire high-level program into machine language in one complete pass.
  2. 2
    The compiler saves the machine-language result in an executable file for later execution.
  3. 3
    Windows commonly identifies executable files with .exe or .dll suffixes, while Linux and macOS use file permissions.
  4. 4
    Machine language is made of low-level byte sequences intended for CPU execution and is not designed to be read by humans.
  5. 5
    The Python interpreter is a compiled program written in C that reads and interprets Python code.

At a glance

  • A compiler processes the entire source program, checks it, translates it into machine language, and saves the result in an executable file.
  • Executable identification differs by operating system: Windows commonly uses .exe or .dll suffixes, while Linux and macOS use file permissions.
  • Machine language is intended for CPU execution, so it appears unreadable when opened as text.
  • The Python interpreter is itself a compiled C program that interprets Python code.
  • Compilation happens before execution, while interpretation occurs as the interpreter runs the program.

Related concepts

More concepts starting with P