DEV Community

Cover image for CS 101: Introduction to Coding
Blackie
Blackie

Posted on • Updated on

CS 101: Introduction to Coding

Table Of Contents

Introduction
Assemblers translate assembly language to machine code
Grace Hopper
The launch of the high-level language
Compilers and interpreters
The Compiler
The Interpreter
The need for translators

Computers need precise instructions

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

Assemblers translate assembly language to machine code

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

Grace Hopper
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

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.

mov edx, DWORD PTR [rbp-0x4]
mov edx, DWORD PTR [rbp-0x8]
add eax, edx
mov DWORD PTR [rbp-0xc], eax
Enter fullscreen mode Exit fullscreen mode

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

int c = a+b;
Enter fullscreen mode Exit fullscreen mode

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

100010110101010111111100
100010110100101111111000
111010000
100010010100010111110100
Enter fullscreen mode Exit fullscreen mode

Compilers and interpreters

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

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

The interpreter

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

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: "The Woman Who Spoke to Computers". The Attic. Retrieved July 31, 2019.

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

Top comments (0)