software bits and bytes n07/6854660925/sizes/l/in/photostream

24
SOFTWARE Bits and Bytes http://www.flickr.com/photos/75578935@N07/6854660925/sizes/l/in/ photostream/

Upload: lucas-harvey

Post on 12-Jan-2016

219 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

SOFTWARE Bits and Bytes

http://www.flickr.com/photos/75578935@N07/6854660925/sizes/l/in/photostream/

Page 2: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

2

Computer software is an encoding of data and instructions where the instructions are to be executed by the CPU. Software is synonymous with computer program.

Recall that: A CPU is a physical device A CPU can only do “simple” things like add/subtract/multiply/divide two numbers compare two numbers copy data from one storage location to another

SOFTWARE

Page 3: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

3

A computer program must use only instructions that the CPU understands and is able to perform.

Follow these directions to travel for free to Los Angeles.1. Stand at the center of the UW-L football field.2. Turn to face West-South-West3. Run as fast as you can for 20 yards.4. Jump 1960 miles.5. Land safely.

Will this work?

COMPUTER SOFTWARE

Page 4: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

4

Learning to program a computer means Knowing what the computer can actually do Knowing how to use these ‘simple’ commands to perform

more ‘complex’ tasks

A programming language is used to represent the actions that a computer can actually perform. A set of CPU instructions can be rendered in different

programming languages just as one textbook can be rendered in English, Japanese, and Spanish.

Modern programming languages allow a programmer to “say more than” the CPU understands by translating these instructions into the simple language of the CPU.

COMPUTER SOFTWARE

Page 5: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

5

LANGUAGES

High Levelclose to English

LISP, C++, Java, Python

FORTAN, C, PASCAL

ASSEMBLY

MICROCODE

Low Levelclose to the CPU’s native language

add/sub/mul/divide/compare

Page 6: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

6

Machine Language (Pentium III Linux Box)

LOW LEVEL LANGUAGE

01111111 0100010101001100 0100011000000001 0000000100000000 00000000…

Can you understand this program?

Page 7: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

7

Assembly (Pentium III Linux Box)

INTERMEDIATE LEVEL LANGUAGE

Can you understand this program?

.file “hello.c”

.version “01.01”

.section .rodata

.LCO:

.string “Hello World\n”

.text.align 4

.globl main.type main,@function

main:pushl %ebpmovl %esp,%ebppushl $.LCOcall printfaddl $4,%espxorl %eax,%eaxjmp .L1.p2 align 4,,7

.L1:leaveret

Page 8: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

8

C

INTERMEDIATE LEVEL LANGUAGE

#include <stdio.h>

void main() {printf(“Hello World\n”);

}

Can you understand this program?

Page 9: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

9

Python

HIGH LEVEL LANGUAGE

print “Hello World”

Can you understand this program?

Each of these programs mean the same thing. They are just written in different languages!

Page 10: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

10

LANGUAGES AND COMPILATION

Com

piler

• Programmers write at a high level

• The CPU can’t understand the high level and so a translator converts into low level

• The translator is itself a program called a compiler.

• Also note that CPU's speak different CPU languages

print “Hello World” Python (English-level)

01111111 0100010101001100 0100011000000001 0000000100000000 00000000… Microcode (CPU-level)

Page 11: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

11

Examples of CPU's include Intel Core I7, I5, AMD Athlon, MIPS, Xeon, and many others.

In Java, there is a virtual CPU known as the JVM Java Virtual Machine

The JVM is a program that, when run on a real CPU, makes the real CPU act like the ‘Java’ CPU.

A Java compiler converts a Java program into bytecode (the JVM’s microcode)

SOFTWARE: COMPILATION AND THE JVM

Page 12: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

12

SOFTWARE: COMPILATION AND THE JVM

Intel Pentium(Windows)

JVM

PPC(Mac)

JVM

MIPS 32(Unix)

JVM

Java Program

bytecode

Page 13: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

13

A programming language is a language!

All written languages (whether programming or natural)Have rules about syntax

The way the language “looks”. More specifically, what symbols are in the language and how those symbols must be arranged.

Have rules about semanticsWhat the symbols “mean”

IMPORTANT CONCEPTSSYNTAX AND SEMANTICS

Page 14: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

14

A programming language is a language!

All written languages (whether programming or natural) Have rules about syntax The way the language “looks”. More specifically, what

symbols are in the language and how those symbols must be arranged.

Have rules about semantics What the symbols “mean”

PROGRAMMING LANGUAGES

Page 15: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

15

SYNTAX AND SEMANTICS: EXAMPLE

Hiragana Symbols

ぁ あ ぃ い ぅ う ぇ え ぉ お か が き ぎ く

ぐ け げ こ ご さ ざ し じ す ず せ ぜ そ ぞ た

だ ち ぢ っ つ づ て で と ど な に ぬ ね の は

ば ぱ ひ び ぴ ふ ぶ ぷ へ べ ぺ ほ ぼ ぽ ま み

む め も ゃ や ゅ ゆ ょ よ ら り る れ ろ ゎ わ

ゐ ゑ を ん

English Symbols

A,a B,b C,c D,d E,e F,f G,g

H,h I,i J,j K,k L,l M,m N,n

O,o P,p Q,q R,r S,s T,t U,u

V,v W,w X,x Y,y Z,z

Umbrella かさ

Syntax identifies the symbols that can be usedand how they must be arranged to form “words”

Page 16: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

16

Syntax also defines how “words” can be arranged to form “sentences”

Hiragana

いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしえひもせす

English

Even if colors have sweet perfume

eventually they fade away

What in this world

is eternal ?

The deep mountains of vanity

I cross them today

renouncing the superficial dreams

not giving in to their madness any more

SYNTAX AND SEMANTICS: EXAMPLE

Page 17: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

17

Semantics gives meaning to symbols. A device for protection from the weather consisting of a

collapsible, usually circular canopy mounted on a central rod. (From Yahoo’s online dictionary)

Given the fi rst statement below: identify whether the following statements contain changes in SYNTAX or SEMANTICS or BOTH.

SYNTAX AND SEMANTICS: EXAMPLE

Umbrella

The college student ate three large pizzas.

The high-school student made five large pizzas.

The coLLage stoodaent, 8te three larj pissas$

Page 18: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

18

Consider Java A programming language Java has a set of syntax rules Java has a set of semantic rules

SYNTAX AND SEMANTICS: PROGRAMMING

• Syntax Rule Example:– Integer numbers are 1 or more consecutive digits optionally preceded by a ‘+’

or ‘-’ symbol (must not have space(s) between them).

918918 -3-3 +54.21+54.21 0000500005 3 53 5

http://www.flickr.com/photos/7989285@N07/1794265047/sizes/z/in/photostream/

Page 19: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

19

SYNTAX AND SEMANTICS: PROGRAMMING

• Syntax Rule Example:– The symbol ‘<‘ and the symbol ‘>’ can only appear immediately between two

integer numbers. Spaces may separate the numbers from these two symbols.

9<89<8 > 35> 35 3 >13 >1 0 <0 < 10>>510>>5

• Semantic Rule Example:– If a ‘<‘ appears between two numbers, it means the following:

• TRUE if the left number is less than the right number• FALSE if the left number is not less than the right number

9<89<8 0< 350< 35 3 <113 <11 -3 <2-3 <2 10<510<5

Page 20: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

20

A programmer must know the syntax of their programming language know the semantics of their programming language follow these rules to construct software that solves

specific problems.

PROGRAMMING: THE BIG IDEA

if(totalPurchaseAmount < 25) {shippingCost = 7.0;

} else {shippingCost = 0.0;

}

Example Problem: Write software that computes shipping cost for Amazon.com. Amazon is running a special where they give free shipping for any transaction totaling $25 or more. All other transactions are charged a flat fee of $7.00 for shipping.

Page 21: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

21

Software is a sequential set of instructions for the CPU

What qualities does good software have?unambiguous- can’t mean more than one thing

readable – a human can look at it and understand it

correct – doing exactly what it should do all the time

SOFTWARE

Page 22: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

22

Software engineering manages the process of writing software

Three general phases in the process of software development Analysis – learn what the software should do. Write the

requirements document.

Design – decide how to structure the software (classes / objects / variables / methods). Write the design document.

Implementation – Write the software using some language. We will use Java.

SOFTWARE: ENGINEERING

Page 23: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

23

These phases can be completed in various ways. The ‘simplest’ is the ‘waterfall’ cycle. Each phase is completed prior to the next.

SOFTWARE: ENGINEERING

Analysis

Design

Implementation

Testing

Page 24: SOFTWARE Bits and Bytes N07/6854660925/sizes/l/in/photostream

24

PROCESS

24

Text editor(NotePad)

Software Tool Deliverable

Java compiler(javac)

Bytecode file( className.class )

Java Virtual Machine(java)

Source code file( className.java )

Action

Programmer types thesoftware into the computer.

The software is translated into a form that is “understood”by the computer.

The program executes.