introduction to programming. objectives look at why we write programs describe some things it takes...

46
Introduction to Programming

Upload: melinda-wilkins

Post on 27-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Introduction to Programming

Objectives

Look at why we write programs

Describe some things it takes to learn to be a programmer

Discuss some important programming tools

Investigate how the computer works as it executes a program

Describe the steps involved in creating and running a program

Why would you want to learn to program?

• The sheer joy of making things – being creative • The pride in making something that is useful to other

people• The fascination of solving complex problems• Figuring out how to do something you’ve never done

before• Making a dumb machine do smart things• Earning a lot of money

Comment from a student …

“I want a career, not just a degree”

Jan 8, 2009

statetrendsgraphs.pdf

Robotics

Computer Graphics/Animation

Business/Finance

Engineering

Learning to program requires

• Time• Patience• Good language skills• The ability to think abstractly• Good math skills• The ability to solve problems• Practice – Program, program, program• A sense of curiosity

Learning to Program Takes Time

Researchers have shown that learning to do anything well(playing the piano, painting, playing tennis, etc) takes about 10 years. Learning to be a good programmer is nodifferent.

To become proficient at programming Practice Practice Practice …

The rise of mathematics is heating up the job market for luminary quant's, especially at the Internet powerhouses where new math grads land six-figure salaries and rich stock deals. Tom Leighton, an entrepreneur and applied math professor at Massachusetts Institute of Technology, says: "All of my students have standing offers at Yahoo! and Google. Top mathematicians are becoming a new global elite. It's a force of barely 5,000, by some guesstimates, but every bit as powerful as the armies of Harvard University MBAs who shook up corner suites a generation ago.

Math Skills are Important

Business Week Cover StoryJanuary 23, 2006

What do Programmers Do?

They talk to their customers They talk to their peersThey discuss problemsThey think a lotThey write a lotThey design solutions to problemsThey write codeThey debug codeThey refactor codeThey test codeThey document codeThey fix code. . .

Programming Tools

The computerThe operating systemThe code editorThe compilerThe debugger

IntegratedDevelopmentEnvironment

Problem solving skillsLanguage skills

The Computer

DataSegment

CodeSegment

Stack

Heap

Memory

Program Counter

Instruction Register

General Purpose Registers

Status Registers

Arithmetic andLogic Unit

CPU

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

General Purpose Register

Status Registers

Arithmetic andLogic Unit

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

General Purpose Register

Status Registers

Arithmetic andLogic Unit

Watch how the computer adds two numbers together …

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

60

addressThe program to be executed isstored in the code segment.The data is stored in the datasegment. The program counterpoints to the next instructionto be executed.

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

60

address

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

60

address

ld r1, 24

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

60

address

10

ld r1, 24

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

64

address

10

ld r1, 24

10

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

64

address

10

ld r1, 24

10

ld r2, 28

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

64

address

10

ld r2, 28

10

12

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

68

address

10

ld r2, 28

10

12

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

68

address

10

ld r2, 28

10

12

add r1, r2

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

68

address

10

add r1, r2

10

12

10

12

22

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

68

address

10

add r1, r2

10

12

22

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012--

242832

60646872

72

address

10

ld r1, 24

22

12

sto r1, 32

The Computer

DataSegment

CodeSegment

Stack

Heap

Program Counter

Instruction Register

Register r1

Arithmetic andLogic Unit

ld r1, 24ld r2, 28add r1, r2sto r1, 32

Register r2

1012

242832

60646872

78

address

10

sto r1, 32

22

12

22

The Operating System

Manages the memory in the computerManages how and when programs are executedManages the devices attached to the computer and lots of other stuff …

The code editor provides a way forThe programmer to create and edit thesource code text for his or her program.

Editors provide tools to cut and paste sourceCode text, move between source code files,and do many other editing tasks.

static void Main( ){ int a = 5; int b = 27; . . .

source codecompiler

ld r1, 32ld r2, 56add r1, r2sto …

ld r1, 32ld r2, 56add r1, r2sto …

compiler

object codemachine language

ld r1, 32ld r2, 56add r1, r2sto …

compiler

loadmodule

.exe

reserved foroperating

system

program A

program B

the heapthe heap is left overmemory, not being usedby any program. It ismanaged by the O/S.

code segment

data segment

stack segment

loader

program C

C# actually works a little differently

Visual C# Express generates an intermediate language filethe is loaded into memory along with a run time system (CLR)built by Microsoft, that interprets the intermediatelanguage file as your program executes.