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.

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

A Complete Compilation Pass

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

Compiling a C Program

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

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

Submit: You provide the source file to a compiler.

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

Translate: The compiler translates every statement into machine instructions.

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

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.

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.

executable file containsexecutable file containsexecutable file containsWindows.exe or .dll suffixMachine languageCPU-executable instructionsLinuxfile permissionsmacOSfile permissions
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

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.

submit before executionsave translated resultprovide at runtimeinterpret statementsSource programentire filePython programsource statementsCompilerchecks and translatesInterpreterreads during executionExecutable filemachine languageProgram executionruntime behavior
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.

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.

submit to compilerproducereadsinterprets during runC source codeinterpreter implementationC compilercompiles oncePython interpretercompiled programPython codeuser programPython executionstatements interpreted
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

  • Assuming that an executable must always end in .exe.

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

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

  • Expecting machine language to be readable like source code.

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

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

  • Thinking that Python has no compiled component.

    The Python interpreter is a compiled program written in C.

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

  • Treating compilation errors and runtime errors as the same failure.

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

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

Key Takeaways

  • 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.