notes blog about

Computer Science

Ada Lovelace

Computer

Functional view of a computer:

                +------------+
                |  +-----+   |    +---------+
                |  | CPU |   |--->| Output  |
                |  +-----+   |    | Devices |
+---------+     |    | ^     |    +---------+
| Input   |---->|    v |     |
| Devices |     | +--------+ |    +-----------+
+---------+     | | Main   | |--->| Secondary |
                | | Memory | |<---| Memory    |
                | +--------+ |    +-----------+
                +------------+
                

Running a program (HD -> RAM -> CPU):

  1. Instructions that comprise the program are copied (loaded) from secondary to main memory.
  2. CPU starts executing the program, i.e. it does this cycle (really, really fast): fetch, decode, execute

Programming languages

CPU can only understand a very low-level (machine) language. Machine language is created by the designers of the particular CPU. Adding two numbers looks like (instructions and data are really represented in binary notation - sequences of 0s and 1s):

load the number from memory location 2020 into the CPU
load the number from memory location 2021 into the CPU
add the two numbers in the CPU
store the result into location 2023

In high-level (human-oriented) language - like Python - it looks like:

c = a + b

by translation mechanism

There are two ways to translate a high-level language to machine language: to compile it or to interpret it.

Compiled

Source +---> Compiler +---> Machine
Code                        Code
                              +
                              |
                              v
             Inputs +---->  Running +---> Outputs
                            Program

Interpreted

            +--------------+
Source      |              |
Code   +--> |              |
            | Interpreter  | +--> Outputs
            |              |
Inputs +--> |              |
            +--------------+

by program scale

Traditional systems languages (C++, Ada, Java)

Scripting languages (Perl, Python, Bash)

by programming paradigm

Object oriented

Imperative

Sources