Docsity

Programming the ENIAC - Lecture Slides | CS 4240, Study notes of Computer Science

Partial preview of the text

Download Programming the ENIAC - Lecture Slides | CS 4240 and more Study notes Computer Science in PDF only on Docsity!

CS 4240

Nate Clark

(many slides from Bodik and August)

Class

• Projects: both internet and assembly • 65:35• 4 projects

p

j

  • Lexer– Parser – Semantic check– Optimization

• War

ENIAC (1946, U of Philadelphia)^ • programming done by

i i

th

i t

ti

  • rewiring the interconnections– to set up desired formulas, etc

• Problem: what’s the tedious

part?^ – programming = rewiring– slow, error-prone

• Lesson:

  • store the program in memory!

store the program in memory!

  • birth of von Neuman paradigm

UDSAC (1947, Cambridge University)^ • the first real computer

  • large-scale, fully functional,

stored-program

electronic digital computer (by Maurice Wilkes)

  • this was a von Neuman computer– problem: Wilkes realized:
    • “a good part of the remainder of my life was going

to be spent in finding errors in ... programs”

solution: procedures (1951)

• solution: procedures (1951)

  • reusable software was born

f^

(^

  • procedure: the first (implemented) language

construct

Assembler – the compiler (Manchester, 1952)^ •

it was assembler nearly as we know it, called AutoCode

-^

a loop example, in MIPS, a modern-day assembly code:

p

p

,^

,^

y

y

loop: addi $t3, $t0, -

addi $t4, $t0, -4l

$ 1

h

($ 3)

# G

h^

l

lw $t1, theArray($t3)

# Gets the last

lw $t2, theArray($t4)

#^

two elements

add $t5, $t1, $t

# Adds them together...

sw $t5, theArray($t0)

# ...and stores result

$

,^

y($

)

#

addi $t0, $t0, 4

# Moves to next "element“# of theArray

blt $t0, 160, loop

# If not past the end of

j

$

# th A

t

jr $ra

# theArray, repeat

Assembly programming caught on, but^ • Problem: Software costs exceeded

Problem: Software costs exceededhardware costs!

• John Backus: “Speedcoding”

An interpreter for a high level language

  • An interpreter for a high-level language– Ran 10-20 times slower than hand-written

assemblyassembly

  • way too slow

FORTRAN I (IBM, John Backus, 1954)^ • Example: nested loops in FORTRAN

bi

i^

t^

bl

  • a big improvement over assembler,– but annoying artifacts of assembly remain:
    • labels and rather explicit jumps (CONTINUE)• labels and rather explicit jumps (CONTINUE)• lexical columns: the statement must start in column

7

  • The MIPS loop in FORTRAN:

DO 10 I = 2, 40A[I]

A[I 1]

A[I 2]

A[I] = A[I-1] + A[I-2]

10 CONTINUE

Side note: designing a good language is hard^ •

A good language protects against bugs, but lessons take a while.

-^

An example that cause a failure of a NASA planetary probe:

buggy line:

DO 15 I = 1.

what was intended (a dot had replaced the comma):what was intended (a dot had replaced the comma):

DO 15 I = 1,

because Fortran ignores spaces, compiler read this as:

DO15I = 1 100DO15I

which is an assignment into a variable DO15I, not a loop.

-^

This mistake is harder (if at all possible) to make with the modern

(^

p

)

lexical rules (white space not ignored) and loop syntax

for (i=1; i < 100; i++) { … }

Object-oriented programming (1970s)^ •

The need to express that more than one objectsupports draw() :^ draw(2DElement p) {

switch (p.type) {

SQUARE: … // draw a squareSQUARE: … // draw a square

break;

CIRCLE: … // draw a circle

break;

} }

-^

Problem:^ – unrelated code (drawing of SQUARE and CIRCLE)

mixed in same procedure;

p

;

•^

Solution:^ – Object-oriented programming with inheritance

Object-oriented programming^ • In Java, the same code has the desired

ti

separation:

class Circle extends 2DElement {

void draw() { } } // similar for Square

• the dispatch is now much simpler:

  • p.draw()

p.draw()

Where will languages go from here?^ • The trend is towards higher-level

abstractionsabstractions– express the algorithm concisely!

which means hiding often repeated code

  • which means hiding often repeated code

fragments

  • new language constructs hide more of these

new language constructs hide more of theselow-level details.

• Also, detect more bugs when the program

is compiled

p

  • with stricter type checking

Why software developers need PL^ • New languages will keep coming.

But why

do they?do they?– Understand them, choose the right one.Write code that writes code

When to write

• Write code that writes code. When to write

a codegen?

Be the wizard not the typist

  • Be the wizard, not the typist.

• Develop your own language.

How do I do

that?that?– Are you kidding? No.

• Learn about compilers and interpreters

• Learn about compilers and interpreters.

  • Programmer’s main tools.

Frontend Structure

Source Code

LanguagePreprocessor

Trivial errors

Processing of#include, #defines#ifdef etc#ifdef, etc

Preprocessed source code (foo.i)

Lexical AnalysisSyntax AnalysisSemantic Analysis

Errors

AbstractSyntax Tree

Note: gcc –E foo.c –o foo.ito invoke just thepreprocessorp^

p

Lexical Analysis Process

Preprocessed source

if (b == 0) a = b;

Preprocessed sourcecode, read char by char

Lexical Analysis or Scanner

if^

(^

b^

==

0

)^

a^

=^

b^

;

L^

i^

l^

l^

i

Lexical analysis

  • Transform multi-character input stream to token stream- Reduce length of program representation (remove spaces)-