250 likes | 346 Views
Intro to CS – Honors I Introduction. Georgios Portokalidis gportoka@stevens.edu. Today’s Lecture. Logistics Course information Grading Introduction to computer architecture Software and hardware How do programs run Programming languages
E N D
Intro to CS – Honors IIntroduction Georgios Portokalidis gportoka@stevens.edu
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 CS181 - Intro to CS - Honors I
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/EW .SavitchAddison-Wesley, 2012ISBN 0132162709 (ISBN-13: 9780132162708) • More in the course’s website CS181 - Intro to CS - Honors I
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." CS181 - Intro to CS - Honors I
Questions • Before emailing anyone search online • Use the mailing list: cs181@lists.stevens.edu • Then ask the teaching assistant or the instructor CS181 - Intro to CS - Honors I
A Short Survey • How many of you have done any programming in any language? • How many of you have programmed in Java? CS181 - Intro to CS - Honors I
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 CS181 - Intro to CS - Honors I
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 CS181 - Intro to CS - Honors I
Intro to Computer Architecture Computer Systems Programs Physical Software Hardware CS181 - Intro to CS - Honors I
Hardware Stores data and instructions CPU Executes simple instructions Memory I/O Bus Peripherals Input and output devices CS181 - Intro to CS - Honors I
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 CS181 - Intro to CS - Honors I
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 double word (or 32-bit word) word (or 16-bit word) CS181 - Intro to CS - Honors I
Memory • Almost all modern computers follow the Von Neumann architecture • Data and instructions share the same memory • Memory is RAM (Random Access Memory) Sequential Access Memory RAM Target data Target data Memory access instruction Memory access instruction RAM is also volatile, unlike ROM that is read only! CS181 - Intro to CS - Honors I
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 Instructions Data CS181 - Intro to CS - Honors I
How Do Programs Run? Arithmetic Logic Unit The brain! RAM CPU ALU Our program Instruction 1 Instruction 2 Instruction 3 … Instruction N Program Counter The CPU’s own very fast memory Registers PC FPU Data Floating Point Unit Other extensions CS181 - Intro to CS - Honors I
The CPU is continuously performing (looping) the following steps: 1. Fetch instruction pointed to by PC 2. Execute the instruction 3. Increment PC 4. Go back to 1 In a sense, the CPU includes its own program! How Do Programs Run? RAM CPU ALU Our program Instruction 1 Instruction 2 Instruction 3 … Instruction N Registers PC FPU Data CS181 - Intro to CS - Honors I
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 CS181 - Intro to CS - Honors I
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 CS181 - Intro to CS - Honors I
Memory Hierarchies RAM CPU ALU Cache Registers PC Cache enables fast access of frequently accessed RAM FPU CS181 - Intro to CS - Honors I
Multi-level Caches Can be placed in various ways RAM CPU Level 2 Cache ALU Cache Registers PC FPU CS181 - Intro to CS - Honors I
From Languages to Instructions High-level languages Easily understandable by humans. Java, C, C++, Python, Ruby, etc. Assembly Language Symbolic form of machine language. Low-level programming language Machine Language Basically structured numbers What the hardware understands What we want to use How do we make the transition? Source code Binary code CS181 - Intro to CS - Honors I
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 CS181 - Intro to CS - Honors I
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 CS181 - Intro to CS - Honors I
Compiling and Running a Java Program Syntax errors Run-time errors Java compiler Bytecode program JVM Machine-language instructions Execution Java program Program output Data for program CS181 - Intro to CS - Honors I
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 CS181 - Intro to CS - Honors I