CS 101: Introduction to Coding
Tags: beginners, programming, codenewbie, community
Published: 2022-10-15 15:23:14


## Table Of Contents
[Introduction](#intro)
[Assemblers translate assembly language to machine code](#assembly)
[Grace Hopper](#grace)
[The launch of the high-level language](#launch)
[Compilers and interpreters](#comp)
[The Compiler](#compiler)
[The Interpreter](#interpreter)
[The need for translators](#need)

## Computers need precise instructions <a name="intro"></a>

Computers require precise, clear instructions, yet they can only understand one language: machine language (0s and 1s). The Central Processing Unit of a computer is capable of immediately executing instructions written in machine language (CPU).

Originally, just machine code was used to create programs. Prior to being carried out, each command was manually typed. This was aided by the use of operation code (opcode) tables, although it required a lot of work.

![Assembly](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nowcacpb668j2llhex0.jpeg)
Programmers created an assembly language to make things move more quickly. By combining an operand with a mnemonic to produce an instruction, it made the opcodes simpler to read. It was comparable to one line of machine code for every assembly language word.


![Machine Code Example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bdvgdydnalh69f8jbfyy.jpg)

### Assemblers translate assembly language to machine code <a name="assembly"></a>

This was great for the programmers, but the computers still couldn’t understand the instructions. Assemblers were created to automatically translate the assembly language into machine code. 

Assembly language and machine code are low-level languages. Each line of assembly language is equivalent to one line of machine code. The code is specific to the CPU that it is written for.

### Grace Hopper <a name="grace"></a>


![Grace Hopper](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4fgg61wjr2hduaxsver.png)
Assembly language soon became too time consuming: it was hard to read, debug, and maintain. A plain English language was needed. Grace Hopper said “data processors ought to be able to write their programs in English, and the computers would translate them into machine code.” [ 1 ]

Grace Hopper conceived the idea of creating a compiler that could translate plain English code into machine code. It took three years for her work to be taken seriously because people believed that “computers could only do arithmetic.” [2]

### The launch of the high-level language <a name="launch"></a>

Fortran and COBOL were created as the first high-level languages. They allowed programmers to write programs in formal, structured English. High-level languages made it easier to read, maintain, and debug code. As a result, programming computers became more suited to a wider audience.

```Assembly
mov edx, DWORD PTR [rbp-0x4]
mov edx, DWORD PTR [rbp-0x8]
add eax, edx
mov DWORD PTR [rbp-0xc], eax
```
These high-level languages could write one line of ‘formal, structured English’ code that would then be translated to dozens of lines of machine code. Here is the code from earlier written in the programming language, C
 ```c
int c = a+b;
 ```

 This line of code is four lines long in assembly language, and four lines long in machine code. 

```
100010110101010111111100
100010110100101111111000
111010000
100010010100010111110100
```

## Compilers and interpreters <a name="comp"></a>

High-level languages can be translated using a compiler or an interpreter. A compiler will create a single, executable file that can then be run without the original source code. An interpreter will run the source code one line at a time and doesn’t create an executable file. The interpreter is needed every time you run the code.

Imagine that you have been given a cake recipe that has been written in a language that you don’t understand. To help you follow the recipe, you are going to need to translate the instructions.

### The compiler <a name="compiler"></a>

Your first option is to compile those instructions. This means that you can create a fully translated version of the recipe that you can use whenever you need to.

This might take some time, but once created, you would no longer need the original recipe and it would be much quicker to follow it each time. You could even easily share your translated recipe with other friends who speak the same language. 


![Compiler](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hx0f1pk0polk57n20j0a.png)
### The interpreter <a name="interpreter"></a>

Your second option is to have an interpreter follow the recipe with you. The interpreter would translate each line of the recipe individually whilst you bake your cake. This would be quick to do initially, but you would always need an interpreter when you wanted to follow that recipe. 

Also, if you wanted to share the recipe with your friends, then they would also need an interpreter to follow the recipe.


![Interpreter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cutup90nc1hjwqr0ag3s.png)
Interpreters and compilers are necessary for programmers because they allow us to write programs in formal, structured English and translate them.

## The need for translators <a name="need"></a>

High-level languages only exist because of translators. Without translators, our only option would be to write in machine code. High-level languages made programming more accessible to a wider audience.

**References**:

[1]: Quote from wikipedia. Original quote from: &quot;The Woman Who Spoke to Computers&quot;. *The Attic*. Retrieved July 31, 2019.

[2]: Quote from Wikipedia. Original quote from: "The Wit and Wisdom of Grace Hopper"