Administrivia - PowerPoint PPT Presentation

About This Presentation
Title:

Administrivia

Description:

Big number bug. On June 4, 1996 an unmanned Ariane 5 rocket launched by the European Space ... The cost of a bug can be very large. There is no Moore's Law for ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 37
Provided by: davidd5
Category:

less

Transcript and Presenter's Notes

Title: Administrivia


1
Administrivia
  • First pieces of assignment 5
  • Comments about assignment 5
  • Assignment 6
  • Labs 5 and 6

2
Some bytes
  • 0000000 5089 474e 0a0d 0a1a 0000 0d00 4849 5244
  • 0000020 0000 9001 0000 2c01 0208 0000 6200 72d5
  • 0000040 0095 2000 4900 4144 7854 ccda 79fd 24d4
  • 0000000 5089 474e 0a0d 0a1a 0000 0d00 4849 5244
  • 0000020 0000 9001 0000 2c01 0208 0000 6200 72d5
  • 0000040 0095 2000 4900 4144 7854 d4da 61fd 648c

3
Object oriented programming
  • Figure out characteristics of your data
  • objects
  • Figure out operations you will want to perform
  • Methods
  • Modern idea in programming.

4
Objects
  • Traffic light at intersection involves
  • Lights in each direction
  • Call them red, yellow and green and not 0,1,2
  • Sensors in each direction
  • Timing (rate of change in each direction)
  • Timings neednt be the same
  • Neighboring Lights
  • May affect change as much as sensors

5
Methods
  • Method of querying color of light
  • Method of changing color of light
  • Method of scheduling a color change later

6
What happens to the program?
  • Compiled or interpreted
  • Eventually it gets translated into machine
    language
  • If compiled
  • Can store executable and run again
  • If interpreted
  • Interpret each time it is executed

7
What does the compiler do?
  • Identifies variables (need space in RAM)
  • Uses stores and loads to get values to registers
  • Parses commands
  • Turns each command into a string of machine
    language commands
  • Sets things up for execution

8
Steps in compilation
  • Lexical analysis
  • Identify all keywords
  • Identify all operators
  • Identify all variables
  • Make everything into tokens
  • Parsing
  • Turn the tokens into operations
  • Build a computation tree
  • Code generation
  • Generate machine code

9
Lexical analysis
  • Keywords
  • If Then .. End If
  • If .. Then .. Else End If
  • Do While Loop
  • Private sub .
  • End sub
  • Dim as Integer
  • Operators
  • (in 2 contexts)
  • If (Light 0)
  • Light 1
  • - /
  • - also in 2 contexts (unary or binary)

10
Simple code fragment
  • Sub print_ftoc(low As Integer, high As Integer)
  • Dim fahrenheit As Double, celsius As Double
  • For fahrenheit low to high
  • celsius 5 / 9 (fahrenheit - 32)
  • print fahrenheit, celsius
  • Next fahrenheit
  • End Sub

11
Simplified code fragment
  • Dim low As Integer, high As Integer
  • Dim fahrenheit As Double, celsius As Double
  • For fahrenheit low to high
  • celsius 5 / 9 (fahrenheit - 32)
  • print fahrenheit, celsius
  • Next fahrenheit
  • End

12
Code fragment (lexed)
  • Dim low As Integer, high As Integer
  • Dim fahrenheit As Double, celsius As Double
  • For fahrenheit low to high
  • celsius 5 / 9 (fahrenheit - 32)
  • print fahrenheit , celsius
  • Next fahrenheit
  • End
  • Keywords, variables, constants, operators,
    functions, separators

13
Code fragment (cont.)
  • Dim lttag1gt As Integer, lttag2gt As Integer
  • Dim lttag3gt As Double, lttag4gt As Double
  • For lttag3gt lttag1gt to lttag2gt
  • lttag4gt 5 / 9 (lttag3gt - 32)
  • print lttag3gt , lttag4gt
  • Next lttag3gt
  • End
  • Replace variables by tags
  • these are really locations in RAM
  • How things are defined determines
  • how much RAM they need
  • how operations on them work

14
Code fragment (cont.)
  • For lttag3gt lttag1gt to lttag2gt
  • lttag4gt 5 / 9 (lttag3gt - 32)
  • print lttag3gt , lttag4gt
  • Next lttag3gt
  • The instructions in the loop must be unwound
  • lttag3gt lttag1gt
  • lttag4gt 5 / 9 (lttag3gt - 32)
  • print lttag3gt , lttag4gt
  • lttag3gt lttag3gt 1
  • If lttag3gt gt lttag2gt go back

15
The unwound loop can be translated into machine
language
Store 32 in R3 Store 5/9 in R4 Store 1 in R5 Load
lttag1gt into R1 Store R1 into lttag3gt Load
lttag3gt into R2 Subtract R3 from R2 and store in
R2 Multiply R4 by R2 and store in R2 Store R2 in
lttag4gt Print R1,R2 Add R5 to R1 and store in
R1 Store R5 in lttag3gt Load lttag2gt into
R6 Subtract R6 from R5 and store in R5 Go back to
if R6 gt 0
  • lttag3gt lttag1gt
  • lttag4gt 5 / 9 (lttag3gt - 32)
  • print lttag3gt , lttag4gt
  • lttag3gt lttag3gt 1
  • If lttag3gt gt lttag2gt go back

16
Parsing
  • Language is defined by a grammar
  • Grammar is defined by production rules
  • Parsing is done by unwinding

17
How do we specify a grammar?
  • 2 aspects to a language
  • Symbols
  • Rewriting rules
  • Simple language for generating numbers
  • Symbols
  • Non-terminals
  • ltnumbergt, ltdigitsgt, ltsigngt, ltdigitgt
  • Terminals
  • - . 1 2 3 4 5 6 7 8 9

18
Simple rewriting rules
  • ltnumbergt ? ltsigngt ltdigitgtltdigitsgt . ltdigitsgt
  • ltsigngt ? -
  • ltdigitsgt ? ltdigitgtltdigitsgt ltdigitgt e
  • ltdigitgt ? 0 1 2 3 4 5 6 7 8 9

19
An example
  • ltnumbergt ? ltsigngt ltdigitgtltdigitsgt . ltdigitsgt
  • ltsigngt ? -
  • ltdigitsgt ? ltdigitgtltdigitsgt ltdigitgt e
  • ltdigitgt ? 0 1 2 3 4 5 6 7 8 9
  • ltnumbergt ?
  • ltsigngtltdigitgtltdigitsgt.ltdigitsgt ?
  • ltsigngtltdigitgtltdigitgtltdigitsgt.ltdigitsgt ?
  • ltsigngtltdigitgtltdigitgt.ltdigitsgt ?
  • ltsigngtltdigitgtltdigitgt.ltdigitgtltdigitgt ?
  • 98.65

20
Simplifying the rules
  • ltnumbergt ? ltsigngt ltdigitgtltdigitsgt . ltdigitsgt
  • ltsigngt ? -
  • ltdigitsgt ? ltdigitgtltdigitsgt ltdigitgt e
  • ltdigitgt ? 0 1 2 3 4 5 6 7 8 9
  • ltnumbergt ? ltsigngtltdigitsgt.ltdigitsgt
    ltsigngtltdigitsgt
  • ltsigngt ? -
  • ltdigitsgt ? ltdigitgtltdigitsgt ltdigitgt
  • ltdigitgt ? 0123456789

21
Parsing
  • ltnumbergt ? ltsigngtltdigitsgt.ltdigitsgt
    ltsigngtltdigitsgt
  • ltsigngt ? -
  • ltdigitsgt ? ltdigitgtltdigitsgt ltdigitgt
  • ltdigitgt ? 0123456789
  • What rules were applied to get 123.45?

22
What about real languages?
  • The complete grammar for C
  • around 400 lines long
  • 58 tokens (based on keywords)
  • 65 basic productions (each with many options)
  • Only a few complex situations

23
Programming language tradeoffs
  • Branching vs. locality
  • Should the program be in blocks or look like
    spaghetti
  • Type declarations
  • If you Dim something as an integer and then try
    to make it hold a double, what should happen?
  • Verification
  • How do you tell if your specification is right?
  • How do you tell if your program meets your
    specification?

24
History of Programming Languages
  • Fortran (1954) for scientific
  • Cobol (1959) for business
  • Algol (1958) more universal Fortran
  • Lisp (1958) string/concept oriented
  • APL (1960) formula oriented

25
History of Programming Languages
  • PL/1 (1964) from Algol Fortran
  • Basic (1964) for everyone to use
  • Simula (1967) combines with Algol to yield
    Smalltalk (1969) object oriented
  • BCPL ? B ? C (1971)
  • Algol ? Pascal (1971) ? Modula 1,2,3,

26
History of Programming Languages
  • C (1983) C with object oriented features
  • Often C is still used
  • Awk (1978) ? Perl (1987) report generators
  • Web programming language
  • Java (1991) object oriented and portable
  • Web applets, devices
  • Visual Basic(1991) macros and programs
  • Core of Microsoft systems

27
What makes a good language
  • Does the task you want
  • Keeps you from making mistakes
  • Supports debugging when you need it
  • Has a strong tool kit

28
Big number bug
On June 4, 1996 an unmanned Ariane 5 rocket
launched by the European Space Agency exploded
just forty seconds after its lift-off from
Kourou, French Guiana. The rocket was on its
first voyage, after a decade of development
costing 7 billion. The destroyed rocket and its
cargo were valued at 500 million. A board of
inquiry investigated the causes of the explosion
and in two weeks issued a report. It turned out
that the cause of the failure was a software
error in the inertial reference system.
Specifically a 64 bit floating point number
relating to the horizontal velocity of the rocket
with respect to the platform was converted to a
16 bit signed integer. The number was larger than
32,768, the largest integer storeable in a 16 bit
signed integer, and thus the conversion failed.
29
Pentium II bug
  • Software bug encoded in hardware
  • Division algorithm uses a lookup table of 1066
    entries
  • Only 1061 of the entries are downloaded to the
    PLA (programmed logic array from which the data
    are used)
  • Intel had to recall all versions of the chip

30
  • NASA Mariner 1 , Venus probe (1992)
  • Intended to be the first US spacecraft to visit
    another planet, it was destroyed by a range
    officer on 22 July 1962 when it behaved
    erratically four minutes after launch.
  • The alleged missing hyphen' was really a missing
    bar'.
  • (period instead of comma in FORTRAN DO-Loop)

31
  • ATT long distance service fails for nine
    hours(Wrong BREAK statement in C-Code, 1990)
  • January 15, 1990
  • 70 million of 138 million long distance customers
    in the US lost long distance service.
  • Cost to ATT was between 75 Million and 100
    Million (plus the loss of good will).

32
  • E-mail buffer overflow (1998)
  • Several E-mail systems suffer from a "buffer
    overflow error", when extremely long e-mail
    addresses are received.  The internal buffers
    receiving the addresses do not check for length
    and allow their buffers to overflow causing the
    applications to crash.  Hostile hackers use this
    fault to trick the computer into running a
    malicious program in its place.

33
Everything has bugs
  • Bug lists

34
Summary
  • Programming is hard
  • Have to thoroughly understand the task
  • Have to anticipate all possibilities
  • Code is written at a fairly primitive level
  • Is impossible to anticipate what users might do
  • Programming languages allow the user to use tools
    to build things
  • The cost of a bug can be very large
  • There is no Moores Law for software.

35
Where are we
  • Weve built a computer
  • Weve looked at operating systems
  • Weve looked at the network
  • Weve built programs
  • And looked under the hood

36
Whats next
  • One more piece of networking
  • Sharing files, sharing cycles, distributed
    computing
  • Algorithms
  • Ideas of how to design processes
  • Complexity theory
  • Undecidable problems
  • Unsolvable (in practice) problems
  • Applications of hard problems
  • Social impacts
  • Digital rights management
  • Artificial intelligence
Write a Comment
User Comments (0)
About PowerShow.com