Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1Learning Outcomes

This section is included as bonus content and is not tested. If you are curious about these concepts, take CS 164: Compilers and Programming Languages!

2Language Execution Continuum

Interpretation and translation are two ways to running a program written in a specific source language.

In general, we interpret a high-level language when efficiency is not critical. We translate to a lower-level language to increase performance. The latter is what we typically do with C code; we translate it into machine code and store it as an executable.

Consider Figure 1. On the left are higher-level languages; on the right are lower-level languages.

"TODO"

Figure 1:Language execution continuum.

2.1Interpretation

You may be familiar with Python, which is a high-level interpreted language. The Python interpreter is just a program that reads a Python program foo.py and performs the functions of that Python program, generating output as needed.

"TODO"

Figure 2:Python interpreter.

Why would you ever interpret machine code in software? C programs and even RISC-V are also interpreted under specific circumstances.

One reason is simulation; for example, in Venus, we have a RISC-V simulator where you can take assembly and interpret it to get much more debugging information. The Venus simulator helps us learn RISC-V because we can step through the machine code.

Another reason is conversion of a program from one ISA to another ISA. Consider the Apple Macintosh ISA conversion back in the day. Apple moved from 680x0 ISA to PowerPC, then to x86 (and now to ARM). Instead of requiring all programs to be re-translated from a high-level languages, instead the designers let executables contain old and/or new machine code, then emulate–by interpreting the old code in software if necessary. This slower process supported backward compatibility by using software to interpret the old ISA onto the new hardware.

In 2020, Apple moved again onto an ARM-based Apple silicon. To support this transition, Apple released Rosetta, an app that runs Intel-based apps on Apple chips. The link in the previous sentence uses the word “translation” quite liberally; we know now that this process is actually interpretatoni.

3Interpretation vs. Translation

From the point of view of the program, it doesn’t know—and doesn’t care—whether it is running on an interpreter (software) or raw silicon (hardware). When you give it an “add” instruction, it does the add. Nevertheless, there are a pros and cons to choosing interpretation vs. translation: