Top Banner
Patrick J. McSweeney [email protected] MW: 5 – 8:30pm
31

Patrick J. McSweeney [email protected] MW: 5 – 8:30pm.

Jan 03, 2016

Download

Documents

Joan Kennedy
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Patrick J. [email protected]

MW: 5 – 8:30pm

Page 2: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.
Page 3: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Computer Person doing Arithmetic• CPU: executes computer

instructions.

• RAM: Short term storage.

• Hard drive: Long-term storage

• I/O: Keyboard, mouse, monitor,

• Brain (minus memories)

• Paper to write on.

• Textbook - has problems.

• Eyes, hands, pencil…

Page 4: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.
Page 5: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Random Access Memory◦ Form of memory◦ Volatile : loss of power wipes away data◦ Short term memory.

To run a program (saved on your hard drive). It must first be copied to RAM, to be ‘fetched’ by the CPU.

Page 6: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Magnetic storage has mechanical components

Non-Volatile: Permanent storage (without power memory remains).

Large (1GB= 1 billion bytes, 1TB = 1 trillion bytes) but slow-er.

Page 7: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Input-Output: Ways to move data into and out-from.

Monitors, keyboard, mouse, network (modem), USB devices, speakers, printer,

Page 8: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Programs are binary, executable files run by the CPU.

A program is a sequence of binary (1/0) instructions that are interpretable by a CPU.

Common program examples: Internet Explorer, Microsoft Word, PowerPoint, Excel; ITunes, etc.

Page 9: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Operating System (Mac OS, Windows, Linux, Unix)

Operating System (Mac OS, Windows, Linux, Unix)

All ProgramsAll Programs

System CallsSystem Calls

HardwareHardware

Page 10: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Operating systems are special programs that have direct access to a computer’s hardware.

Operating Systems are in charge of running programs.

A program being run by the OS that needs to use hardware uses system calls.

Page 11: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Programming Languages can be divided into two different classes:

◦ High Level Language: C (what we will be learning), Java, C++, C#, Cobol, Pascal.

High level languages are designed to be “readable” for humans.

◦ Assembly Language: Binary computer instructions for the CPU.

Assembly level languages are designed to be readable to the machine.

Page 12: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.
Page 13: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

An algorithm is a series of steps which solve a problem or perform a particular task.

Source code is an implementation of an algorithm.

Algorithm for checking my email:1)Turn on my computer2)Login to my computer3)Open an internet browser4)Enter the URL for my online mail5)Hit enter to go there6)Enter my user name and password7)Select OK

Page 14: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Form groups of 2 or 3 and write an algorithm for one of the following tasks:◦ How to make a peanut butter and jelly sandwich.◦ How to tie your shoelaces. ◦ How to write a letter.

• Try to get at least 10 steps. We’ll take 10 – 15 minutes.

Page 15: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

A compiler is a program takes as input a high level language document and outputs assembly level documents.

SourceCode

SourceCode

Assembly Code

Assembly Code

Compiler

Compiler

Page 16: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

A linker is a program that takes assembly documents and combines them into a single executable file.

Assembly

Assembly

Linker

LinkerAssem

blyAssem

bly

Executable

Executable

Page 17: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Syntax Error: An error that breaks our syntax rules is caught during compilation:

“She; was I friend”

Semantics Error: An error that breaks common sense may not be caught until the program runs:

“The pink nose flew to the country.”

Page 18: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Syntax: Defines the structure of a source code document. Is a set of rules that outline what are acceptable combination of symbols.

Semantics: reflects the meaning of programs.

“Jack kicks a red ball.”

Syntax: “Jack” “kicks” “red”Subject verb adjective“ball”.object.

Semantics

Page 19: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Get together with your groups of 2 or three and create sentences which are:◦ Syntactically incorrect.◦ Semantically incorrect, but syntactically correct.

Page 20: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Start

Start

Edit Source

File

Edit Source

FileCompileCompile

Syntax

Errors?

Syntax

Errors?

YesLinkLink

ExecuteExecute

No Correct?

Correct?

DoneDoneYes

No

source.csource.c

source.osource.o

source.exe

source.exe

Page 21: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

#include <stdio.h>int main (void){ //A comment printf(“Welcome to CPS 196! \n”); return 0;}

File: cps196.c

1234567

Page 22: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

1. #include <stdio.h>

This is called a preprocessor directive. stdio.h tells the compiler about the printf command on line 5 in our program.

As the course progresses we will learn about more preprocessors.

Page 23: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

2. int main(void) This marks the opening of our program. It tells the

compiler that what follows between { and } is our code.

All executable programs in C will have an “int main (void)”

The “int” stands for integer. It implies that at the end of this program we will return a whole number.

The void tells the compiler that this program takes no parameters (inputs).

Page 24: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

3. {

This is the opening bracket for our program.

Page 25: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

4. // A comment

Sometimes it is useful to write notes in our programs.

These notes are ignored by the compiler. Usually these notes are for ourselves so we

can remember what we did if we have to come back and look at our source code again.

Page 26: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

5. printf(“Welcome to CPS 196! \n”);

The printf command displays messages to the user of our program.

printf takes a String as a parameter (input). The string is displayed. “\n” is a special character that means put a

new line here.

Page 27: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

6. return 0;

Here we mark the end of our program by returning an integer to the operating system.

0 indicates a successful execution Other integers can be used to indicate

errors that may have arose.

Page 28: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

#include <stdio.h>int main (void){ int value;

printf(“Please enter a number: ”); scanf(“%d”, &value); printf(“You entered a: %d! \n”,

value); return 0;}

File: cps196.c

1234567

Page 29: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

int value;• “int” here again means integer (whole

number).• value is a container called a variable that

can hold an integer. We say that value has type integer.

Page 30: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

scanf(“%d”, &value);• “scanf” is the opposite of “printf()”.• “printf” displays a data to the screen.• “scanf()” gets input from the keyboard.

• “%d” is a special character that tells scanf to try and get an integer from the keyboard.

• &value is a way of saying store the result from the keyboard in variable value.

Page 31: Patrick J. McSweeney pjmcswee@syr.edu MW: 5 – 8:30pm.

Compiler High level language Assembly language Program Operating System CPU RAM Hard drive Input/output

Lecture 1 Terms & Concepts

Linker Syntax & Semantics Algorithm General work flow “int main(void) “printf” Variable