Intro to CS – Honors I Introduction GEORGIOS PORTOKALIDIS [email protected].

25
Intro to CS – Honors I Introduction GEORGIOS PORTOKALIDIS [email protected]

Transcript of Intro to CS – Honors I Introduction GEORGIOS PORTOKALIDIS [email protected].

Intro to CS – Honors IIntroductionGEORGIOS PORTOKALIDIS

[email protected]

CS181 - INTRO TO CS - HONORS I 2

Today’s Lecture Logistics

◦ Course information◦ Grading

Introduction to computer architecture◦ Software and hardware◦ How do programs run

Programming languages◦ From high-level languages to programs machines understand◦ Java programs

8/26/2013

CS181 - INTRO TO CS - HONORS I 3

Logistics Information about the course can be found in:

◦ The website http://www.cs.stevens.edu/~gportoka/cs181.html◦ Moodle

Schedule◦ Lectures are on Monday and Wednesday 12:00-12:50pm (E229)◦ Lab is on Thursday 12:00-1:40pm (B430)

◦ Teaching assistant Sadia Akhter

◦ Office hours are on Monday 1:00-2:00pm (L213)

Books◦ Java: An Introduction to Problem Solving and Programming, 6/E

W .SavitchAddison-Wesley, 2012ISBN 0132162709 (ISBN-13: 9780132162708)

◦ More in the course’s website

8/26/2013

CS181 - INTRO TO CS - HONORS I 4

Grading Your grade will be determined by:

◦ 2 midterm exams (15% each)◦ The final exam (30%)◦ Assignments given approximately biweekly (40%)

◦ Solutions to the assignments will be discussed in the lab◦ No late submissions

No cheating◦ Stevens honor system

"The Honor System at Stevens [..] insures that work submitted by students can be trusted as their own and was performed in an atmosphere of honesty and fair play."

8/26/2013

CS181 - INTRO TO CS - HONORS I 5

Questions Before emailing anyone search online

Use the mailing list: [email protected]

Then ask the teaching assistant or the instructor

8/26/2013

CS181 - INTRO TO CS - HONORS I 6

A Short Survey

How many of you have done any programming in any language?

How many of you have programmed in Java?

8/26/2013

CS181 - INTRO TO CS - HONORS I 7

Picking the Right Course CS 105

◦ If you were never exposed to programming◦ Basic programming and problem solving concepts◦ Very little coding

CS 115◦ You have a bit of experience◦ Learn the basic of programming using Python

CS 181◦ You have done a little programming◦ Learn the fundamentals using Java◦ Learn object-oriented programming◦ Learn data structures and simple algorithms

8/26/2013

CS181 - INTRO TO CS - HONORS I 8

Do you Like Hacking Learn how things work

Break and fix software and hardware

Participate in capture the flag competitions

Join the hacking club next semester◦ You can also get course credit for your trouble◦ Take the CS 397

◦ Equal to one course if taken for 3 semesters◦ Informal meeting focusing on solving hacking challenges

8/26/2013

CS181 - INTRO TO CS - HONORS I 9

Intro to Computer Architecture

Software Hardware

Computer Systems

PhysicalPrograms

8/26/2013

CS181 - INTRO TO CS - HONORS I 10

HardwareCPU Memory

Peripherals

I/O Bus

Executes simple

instructions

Stores data and

instructions

Input and output devices

8/26/2013

CS181 - INTRO TO CS - HONORS I 11

Software Software consists of instructions and data

Instructions define how a program operates◦ Example: the mathematical operations that need to be performed to calculate the circumference of a

circle

Data can be… ◦ your documents, pictures, videos, etc.◦ but also intrinsic to the program, e.g., the pi (π) constant

8/26/2013

CS181 - INTRO TO CS - HONORS I 12

Computer Representation of Data

The smallest piece of information a computer can store and understand a bit◦ A bit has only two states: 0 or 1◦ Why only two states?

Bits are grouped into bytes◦ 1 byte = 8 bits

Bytes can also be grouped◦ word = 2 bytes◦ double word = 4 bytes◦ quad word = 8 bytes

8/26/2013

double word (or 32-bit word)

word (or 16-bit word)

CS181 - INTRO TO CS - HONORS I 13

Memory Almost all modern computers follow the Von Neumann architecture

◦ Data and instructions share the same memory◦ Memory is RAM (Random Access Memory)

Target data

RAM

Memory access instruction Target data

Sequential Access Memory

Memory access instruction

RAM is also volatile, unlike ROM that is read only!

8/26/2013

CS181 - INTRO TO CS - HONORS I 14

Memory Addressing Memory is split into “slots”

◦ How big is each slot?◦ Typical sizes are 1, 2, 4, and 8 bytes◦ The smallest slot that can be accessed is 1 byte

Each slot has its own numeric address◦ How big can the address space be?◦ Most systems can currently address up to 264

different memory locations

Aligned memory access◦ When reading 2, 4, or 8 bytes some architectures

require that the address is aligned◦ An access is aligned if the address is exactly

divisible by the size of the access

RAM

Instructions

Data

Data

InstructionsData

8/26/2013

CS181 - INTRO TO CS - HONORS I 15

How Do Programs Run?

Instruction 1Instruction 2Instruction 3

…Instruction N

Data

CPU RAM

Our program

Registers

ALU

FPU

Arithmetic Logic Unit The brain!

The CPU’s own very fast memory

Floating Point UnitOther extensions

PC

Program Counter

8/26/2013

CS181 - INTRO TO CS - HONORS I 16

How Do Programs Run?

Instruction 1Instruction 2Instruction 3

…Instruction N

Data

CPU RAM

Our program

Registers

ALU

FPU

PC

The CPU is continuously performing (looping) the following steps:

1. Fetch instruction pointed to by PC2. Execute the instruction3. Increment PC4. Go back to 1

In a sense, the CPU includes its own program!

8/26/2013

CS181 - INTRO TO CS - HONORS I 17

Program Instructions What kind of instructions do you think the CPU executes?

What type of instructions are required for a computer to be useful?

Instructions are very simple

Alan Turing showed that all calculations require only a few instructions

Examples:◦ Load/store data from/to memory to/from registers◦ Perform an arithmetic or logical operation between registers

Simple instructions can be made to execute really fast◦ RISC - Reduced Instruction Set Computer (ARM, SPARC)◦ Operations can only be performed with data in registers

8/26/2013

CS181 - INTRO TO CS - HONORS I 18

Other Instruction Sets CISC – Complex Instruction Set Computer

Do you know any models using this architecture?

Intel CPUs are CISC◦ These days they are built as RISC, supporting CISC instruction sets◦ Operations using data in memory are also supported

8/26/2013

CS181 - INTRO TO CS - HONORS I 19

Memory HierarchiesCPU RAM

Registers

ALU

FPU

PC

Cache

Cache enables fast access of frequently accessed

RAM

8/26/2013

CS181 - INTRO TO CS - HONORS I 20

Multi-level CachesCPU RAM

Registers

ALU

FPU

PC

Cache

8/26/2013

Leve

l 2

Cach

e

Can be placed in various ways

CS181 - INTRO TO CS - HONORS I 21

From Languages to Instructions

Machine Language

Basically structured numbers

High-level languagesEasily understandable by humans.Java, C, C++, Python, Ruby, etc.

Assembly LanguageSymbolic form of machine language.Low-level programming language

What the hardware

understands

What we want to use How do we make the transition?

Source code Binary code

8/26/2013

CS181 - INTRO TO CS - HONORS I 22

Compilers and Interpreters Compilers “A compiler is a program that translates a program written in a high-level

language, such as Java, into a program in a simpler language that the

computer can more or less directly understand.”

◦ Compile once, execute often◦ Program only runs on the particular architecture it was compiled for

Interpreter “An interpreter is a program that alternates the translation and execution

of statements in a program written in a high-level language.”

◦ Program is re-translated every time it is run◦ It can run on any system with a working interpreter

8/26/2013

CS181 - INTRO TO CS - HONORS I 23

Compiling Java Programs The Java compiler does not translate your program to machine language

It translates it to a lower-level language called bytecode

What is bytecode?

“Bytecode is the machine language for a hypothetical computer known as a virtual machine.”

The machine that understands bytecode is the Java Virtual Machine (JVM)◦ Essentially an interpreter for bytecode

Java programs can run in any computer with a JVM

The JVM needs to be ported to new architectures◦ The JVM is simpler than the compiler◦ Need to only write the compiler once

8/26/2013

CS181 - INTRO TO CS - HONORS I 24

Compiling and Running a Java Program

Javaprogram

Data forprogram

Javacompiler

Bytecodeprogram JVM

Machine-language

instructions

ExecutionProgram output

Syntax errors Run-time

errors

8/26/2013

CS181 - INTRO TO CS - HONORS I 25

Summary Computer systems are comprised of software and hardware

◦ Hardware is the physical machine◦ Software refers to all programs on system, including any applications and the operating system

Programs and data are all stored in random access memory

The smallest piece of information addressable in memory is a byte

Each CPU can execute machine-language instructions written in its language

Data need to be frequently moved to CPU registers before operating on them◦ Always on CISC architectures

Compilers are the programs that transform higher-level language programs to lower-level and, eventually, machine instructions

The Java compiler generates bytecode which is understood and executed by the JVM

8/26/2013