mechanization a little bit of history mechanization the old dream...
TRANSCRIPT
A little bit of history
Jordi Cortadella
Department of Computer Science
Mechanization
Introduction to Programming © Dept. CS, UPC 2
Mechanization
Introduction to Programming © Dept. CS, UPC 3
The old dream of mechanical computing
Introduction to Programming © Dept. CS, UPC 4
Calculating-Table by Gregor Reisch:
Margarita Philosophica, 1503.
Roman Abacus
18th-century calculating machine
The first mechanical computer
Introduction to Programming © Dept. CS, UPC 5
• Charles Babbage (1791-1871), English mathematician, philosopher, inventor and mechanical engineer.
• Invented the difference engine (never finished).
• Useful to tabulate polynomial functions.
ENIAC (1945)• The first electronic general-purpose computer, designed
to calculate artillery firing tables.
• Also used in 1950 to create the first weather forecastsby solving mathematical models of the atmosphere andthe oceans.
• 167 m2, 27 tons, it couldsolve 5000 additions and385 multiplications in 1 sec.
• Programmable with switches and cables.
• Programming an algorithmcould take several weeks.
Introduction to Programming © Dept. CS, UPC 6
Programmable digital computers
• Alan Turing (1912-1954), the father ofmodern digital computers.
• During 2nd World War, he broke Germanciphers generated by the Enigma machine.The war in Europe was shortened by atleast two years.
• The bombe was the electromechanical machinecreated to break Enigma.
• It could perform chains oflogical deductions for eachsetting of the rotors.
Introduction to Programming © Dept. CS, UPC 7 Introduction to Programming © Dept. CS, UPC 8
Introduction to Programming © Dept. CS, UPC 9
Turing machine
• A universal machine: theoretical model for computability.
• It can simulate any computer algorithm.
• Useful to understand the limits of mechanical computations.
• Turing machines were the inspiration for modern CPUs.
Introduction to Programming © Dept. CS, UPC 10
1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1• • • • • •
Control
Read/write headInfinite tape
Modern digital computers
• John von Neumann (1903-1957).
• Inspired by Turing’s work,he proposed the architecture ofmodern digital computers.
• Essential innovation:programs stored in memory.
• Most computers today arebased on von Neumann’sarchitecture.
Introduction to Programming © Dept. CS, UPC 11
Von Neumann’s architecture
Introduction to Programming © Dept. CS, UPC 12
0110010111001001000011010011110011100011011001010101000111101100011011000100110100100111111011110110010001001100
01110100001011001100010111101101000000000101100100101100100101001110010001110001110011000110100101011101
MemoryLocation 0Location 1Location 2Location 3Location 4
•••
•••
•••
Program
Data
ControlUnitRead
instruction
Program counter
ArithmeticLogic Unit
Read data
Write data
Input
Output
registers
CPU
Why digital?
• Binary digit (bit): minimum unit of information
yes/no, on/off, true/false, am/pm, open/close, …
• Binary representations are very convenient for physical (electrical) implementations.
• Electronic computers use voltage levels to represent bits, e.g., 0 (0 volts) and 1 (3.3 volts)
Introduction to Programming © Dept. CS, UPC 13
0: 1:
Representing information with bits1 bit 2 states (0, 1)
2 bits 4 states (00, 01, 10, 11)
3 bits 8 states (000, 001, 010, 011, 100, 101, 110, 111)
n bits 2n states
Introduction to Programming © Dept. CS, UPC 14
R G B Color Name
00000000 11111111 00000000 Green
00000000 00000000 00000000 Black
11111111 11111111 11111111 White
11111111 00000000 11111111 Magenta
01000000 11100000 11010000 Turquoise
01111011 00111111 00000000 Chocolate
Example: RGB model for colors
Any color can be generated by adding the three
components with different intensity. 24 bits 16,777,216 colors
Representing information with bits
Introduction to Programming © Dept. CS, UPC 15
Representing numbers with bits
Introduction to Programming © Dept. CS, UPC 16
10011010
Arithmetic operations
10011010 (154)
+ 00110011 (51)
11001101 (205)
Introduction to Programming © Dept. CS, UPC 17
01001 (9)
x 10011 (19)
01001
01001
00000
00000
01001
010101011 (171)
Conventional computers work with
32- or 64-bit representations.
Not all the results can be represented
(not enough bits).
Logic circuits and chips
Introduction to Programming © Dept. CS, UPC 18
The evolution of technology
Introduction to Programming © Dept. CS, UPC 19
Core i5-8600 - Intel (2018)
1.49 cm2, 6 cores
95 W of power
20 billion additions / sec
> 2 billion transistors (14nm)
ENIAC (1945)
167 m2, 270 tons
150 kW of power
5,000 additions / sec
17,468 vacuum tubes
7,200 crystal diodes, 1,500 relays
70,000 resistors, 10,000 capacitors
The fascinating world of technology
Introduction to Programming © Dept. CS, UPC 20
Back to von Neumann’s architecture
Introduction to Programming © Dept. CS, UPC 21
0110010111001001000011010011110011100011011001010101000111101100011011000100110100100111111011110110010001001100
01110100001011001100010111101101000000000101100100101100100101001110010001110001110011000110100101011101
MemoryLocation 0Location 1Location 2Location 3Location 4
•••
•••
•••
Program
Data
ControlUnitRead
instruction
Program counter
ArithmeticLogic Unit
Read data
Write data
Input
Output
registers
Machine codeMIPS architecture (32 bits):
000000 00001 00010 00110 00000 100000arith R1 R2 R6 add
R6 R1 + R2
100011 00011 01000 00000 00001 000100load R3 R8 68
R8 Memory [R3 + 68]
000010 00000 00000 00000 10000 000000jump 1024
PC PC + 1024
Introduction to Programming © Dept. CS, UPC 22
Assembly language
fact:bne $a0, $zero, genori $v0, $zero, 1jr $ra
gen:
addiu $sp, $sp, -8sw $ra, 4($sp)sw $a0, 0($sp)addiu $a0, $a0, -1jal factlw $a0, 0($sp)lw $ra, 4($sp)addiu $sp, $sp, 8mul $v0, $v0, $a0jr $ra
Introduction to Programming © Dept. CS, UPC 23
operation operands
MIPS assembly language
Every line corresponds to
an instruction of machine code
Function that calculates
the factorial of a number (n!)
addiu $a0 $a0 -1
00100100100001001111111111111111
High-level programming languages
Introduction to Programming © Dept. CS, UPC 24
C AREA OF A TRIANGLE - HERON'S FORMULAC INPUT - CARD READER UNIT 5, INTEGER INPUTC OUTPUT - LINE PRINTER UNIT 6, REAL OUTPUTC INPUT ERROR DISPLAY ERROR OUTPUT CODE 1 IN JOB CONTROL LISTING
INTEGER A,B,CREAD(5,501) A,B,C
501 FORMAT(3I5)IF(A.EQ.0 .OR. B.EQ.0 .OR. C.EQ.0) STOP 1S = (A + B + C) / 2.0AREA = SQRT( S * (S - A) * (S - B) * (S - C))WRITE(6,601) A,B,C,AREA
601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE UNITS)STOPEND
High-level programming languages• Programming in assembly language is a tedious and
unpleasant task.
• High-level languages:– Independent from the computer– Higher levels of abstraction– Closer to natural language (if-then, while-do, …)
• The first high-level language: FORTRAN (IBM, 1957).
• Today, there are thousands of programming languages:– Basic, Cobol, Java, C++, Go, Python, Ruby, Lisp, Haskell, ML,
Prolog, Perl, Excel, Pascal, Javascript, PHP, C#, R, Matlab, SQL, Smalltalk, Eiffel, Scratch, …
Introduction to Programming © Dept. CS, UPC 25
High-level programming languages
Introduction to Programming © Dept. CS, UPC 26
Function to calculate n!:
factorial n =if n == 0 then 1else nfactorial(n - 1)
Haskell
int factorial(int n) {if (n == 0) return 1;return nfactorial(n - 1);
}
C++
def factorial(n):if n == 0: return 1else: return nfactorial(n - 1)
Python
MIPS assembly language
fact:bne $a0, $zero, genori $v0, $zero, 1jr $ra
gen:
addiu $sp, $sp, -8sw $ra, 4($sp)sw $a0, 0($sp)addiu $a0, $a0, -1jal factlw $a0, 0($sp)lw $ra, 4($sp)addiu $sp, $sp, 8mul $v0, $v0, $a0jr $ra
Introduction to Programming © Dept. CS, UPC 27
The top 25
programming
languages
http://spectrum.ieee.org/static/
interactive-the-top-programming-languages-2018
IEEE Spectrum
July 31, 2018
Compilers
Introduction to Programming © Dept. CS, UPC 28
int factorial(int n) {if (n == 0) return 1;return nfactorial(n - 1);
}
001100101111001010001011000101101101010100011100101001010010100110010101001000101110101010101001101001010100010101010101101010000010101000100101110100011000100110010100101000100101011101101010
. . .
Compilers translate programs
written in high-level languages
into machine codeCompiler
Introduction to Programming © Dept. CS, UPC 29
Our challenge in this course
Design a program that solvesa difficult Sudoku in one second!
Introduction to Programming © Dept. CS, UPC 30
Introduction to Programming © Dept. CS, UPC 31 Introduction to Programming © Dept. CS, UPC 32