EE 209: Programming Structures for Electrical Engineering

Similar documents
EE 209: Programming Structures for Electrical Engineering. (Many Slides Borrowed from Princeton COS 217)

COS 217: Introduction to Programming Systems

COS 217: Introduction to Programming Systems!

COS 217: Introduction to Programming Systems. Goals for Todayʼs Class. Introductions

COS 217: Introduction to Programming Systems!

Fall, $ cat welcome.c #include <stdio.h>

Princeton University Computer Science 217: Introduction to Programming Systems. Agenda. COS 217: Introduction to Programming Systems.

CSC 2400: Computing Systems!

COS 217: Introduction to Programming Systems

CSC 2400: Computing Systems

Programming in C and C++

Introduction to Programming Systems

Welcome to... CS113: Introduction to C

Two s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011

EL2310 Scientific Programming

Class Information ANNOUCEMENTS

Syllabus of ENPM 691: Secure Programming in C

EL2310 Scientific Programming

CS 241 Data Organization. August 21, 2018

6.S096 Lecture 1 Introduction to C

Princeton University Computer Science 217: Introduction to Programming Systems The Design of C

Programming in C. What is C?... What is C?

Motivation was to facilitate development of systems software, especially OS development.

Motivation was to facilitate development of systems software, especially OS development.

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

PRINCIPLES OF OPERATING SYSTEMS

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

Programming in C UVic SEng 265

Programming in C. What is C?... What is C?

Introduction to C. Sean Ogden. Cornell CS 4411, August 30, Geared toward programmers

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

CS 61C: Great Ideas in Computer Architecture Introduction to C

Lec 3. Compilers, Debugging, Hello World, and Variables

Debugging (Part 1) The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 5

Software Project. Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

Topic 6: A Quick Intro To C

Introduction to C. Ayush Dubey. Cornell CS 4411, August 31, Geared toward programmers

Introduction to Computer Systems

C Introduction. Comparison w/ Java, Memory Model, and Pointers

CS 113: Introduction to

Chris Riesbeck, Fall Introduction to Computer Systems

Programming in C and C++

Introduction to C. Zhiyuan Teo. Cornell CS 4411, August 26, Geared toward programmers

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

EECS2031 Software Tools

Princeton University Computer Science 217: Introduction to Programming Systems The C Programming Language Part 1

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

C Programming for Engineers Introduction

Structure of this course. C and C++ Past Exam Questions. Text books

TTh 9.25 AM AM Strain 322

Introduction to Computer Systems

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CSE 303 Lecture 8. Intro to C programming

2/12/17. Goals of this Lecture. Historical context Princeton University Computer Science 217: Introduction to Programming Systems

CS240: Programming in C

Problem Set 1: Unix Commands 1

Continued from previous lecture

CS 211 Programming I for Engineers

Introduction to Computer Systems

CS 314 Principles of Programming Languages. Lecture 9

CS 126 Lecture S1: Introduction to Java

(heavily based on last year s notes (Andrew Moore) with thanks to Alastair R. Beresford. 1. Types Variables Expressions & Statements 2/23

CSC231 C Tutorial Fall 2018 Introduction to C

Operating Systems (ECS 150) Spring 2011

COMP1917: Computing 1 1. Introduction

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry

CS 240 Fall 2015 Section 004. Alvin Chao, Professor

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers

EMBEDDED SYSTEMS PROGRAMMING Language Basics

1. Introduction. Course Web Site. COMP1917: Computing 1. Textbook. Occupational Health and Safety (OHS)

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C

Your Instructor. CSE Content. Notes. Notes. Notes. Summer May 4, 2010

The C language. Introductory course #1

CS 253: Intro to Systems Programming 1/21

introduction week 1 Ritsumeikan University College of Information Science and Engineering Ian Piumarta 1 / 20 imperative programming about the course

CMSC 246 Systems Programming

CMPE-013/L. Introduction to C Programming

COMP1917: Computing 1 1. Introduction

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world

CS 0449 Intro to Systems Software Fall Term: 2181

The Design of C: A Rational Reconstruction: Part 2

Princeton University COS 333: Advanced Programming Techniques A Subset of C90

C - Basics, Bitwise Operator. Zhaoguo Wang

CS 61C: Great Ideas in Computer Architecture Lecture 2: Introduction to C, Part I

Beijing Jiaotong University CS-23: C++ Programming Summer, 2019 Course Syllabus

last time in cs recitations. computer commands. today s topics.

EMBEDDED SYSTEMS PROGRAMMING Language Basics

TDDB68 Concurrent Programming and Operating Systems. Lecture 2: Introduction to C programming

CS Programming In C

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Arrays and Pointers. CSC209: Software Tools and Systems Programming (Winter 2019) Furkan Alaca & Paul Vrbik. University of Toronto Mississauga

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

Course Information and Introduction

CS133 C Programming. Instructor: Jialiang Lu Office: Information Center 703

Introduction to C Programming

ECE 122 Engineering Problem Solving with Java

Transcription:

EE 209: Programming Structures for Electrical Engineering 1

Goals for Today s Class Course overview Introductions Course goals Resources Grading Policies Getting started with C C programming language overview 2

Introductions Lecturer: KyoungSoo Park, Ph.D. TAs Asim Jamshed (ajamshed@ndsl.kaist.edu) Kabseok Go (ksko@cnr.kaist.ac.kr) Hansung Leem (hsleem@cnr.kaist.ac.kr) Chulmin Kim (cmkim@core.kaist.ac.kr) Modeled around Princeton COS 217 Slides and programming assignments borrowed and adapted from Princeton COS 217 Got permission to use the material 3

Course Goal 1: Programming in the Large Goal 1: Programming in the large How to write large computer programs Abstraction; Interfaces and implementations Specifically, help you learn how to: Write modular code Hide information Manage resources Handle errors Write portable code Test and debug your code Improve your code s performance (and when to do so) Use tools to support those activities 4

Course Goal 2: Under the Hood Goal 2: Look under the hood Help you learn what happens under the hood of computer systems Specifically, two downward tours C Language Assembly Language language levels tour Application Program Operating System service levels tour Machine Language Hardware Goal 2 supports Goal 1 Reveals many examples of effective abstractions 5

Course Goals: Why C? Q: Why C? A: C supports Goal 1 better C is a lower-level language C provides more opportunities to create abstractions C has some flaws C s flaws motivate discussions of software engineering principles A: C supports Goal 2 better C facilitates language levels tour C is closely related to assembly language C facilitates service levels tour Linux is written in C 6

Course Goals: Why Linux? Q: Why Linux instead of Microsoft Windows? A: Linux is good for education and research Linux is open-source and well-specified A: Linux is good for programming Linux is a variant of Unix Unix has GNU, a rich open-source programming environment 7

Lectures and Precepts Lectures Describe concepts at a high level Slides available online at course Web site Precepts Support lectures by describing concepts at a lower level Support your work on assignments Divided into A and B Check your class (A or B) at the course homepage 8

Website and Mailing List Course Website http://www.ndsl.kaist.edu/~kyoungsoo/ee209/ Accessible from KAIST IP block (143.248.*) Course mailing list ee209@list.ndsl.kaist.edu Subscription is required (look at course website) Urgent announcements (e.g., cancelling class) Course Moodle Used to submit your programming assignments Linked to course website 9

Textbooks Required book C Programming: A Modern Approach (Second Edition), King, 2008. Covers the C programming language and standard libraries First edition is not quite so good, but is sufficient Computer Systems: A Programmer's Perspective, Bryant and O'Hallaron, 2010. Covers under the hood Highly recommended books The C Programming Language, Kernighan and Ritchie, 1988. Covers the C programming language The Practice of Programming, Kernighan and Pike, 1999. Covers programming in the large Programming with GNU Software, Loukides and Oram, 1997. Covers tools All books are on reserve in the Library 10

Manuals Manuals (for reference only, available online) Intel Architecture Software Developer's Manual, Volumes 1-3 Tool Interface Standard & Executable and Linking Format Using as, the GNU Assembler See also Linux man command man is short for manual For more help, type man man 11

Programming Environment Lab machines Your PC/Mac/Linux Computer Linux GNU SSH Your Pgm fez fedora 12

Programming Environment Other options Use your own PC/Mac/Linux computer; run GNU tools locally; run your programs locally (e.g., VMWare Player on Windows) Use your own PC/Mac/Linux computer; run a non-gnu development environment locally; run your programs locally (e.g., Visual C++) Etc. Notes Other options cannot be used for some assignments (esp. timing studies) Instructors cannot promise support of other options My recommendation: use local environment for development and lab environment for testing & debugging First precept provides setup instructions 13

Grading Six programming assignments (50%) Working code Clean, readable, maintainable code On time (penalties for late submission) Final assignment counts more (12.5%) Exams (40%) Midterm (20%) Final (20%) Class participation (10%) Attendance + random quiz(?) Lecture and recitation attendance is mandatory 14

Programming Assignments Tentative programming assignments 1. A de-comment program 2. A regular expression module 3. A symbol table module 4. IA-32 assembly language programs 5. A heap manager module 6. A Unix shell Key part of the course Due (typically) Sundays at 9:00PM First assignment is available now Advice: Start early to allow time for debugging 15

Why Debugging is Necessary 16

Course Policy Study the course Policy web page!!! Especially the assignment and exam Policy Violation is automatic failure (F) of this course. We ll use MOSS to check plagiarism Some highlights: Don t view anyone else s work during, before, or after the assignment time period Don t allow anyone to view your work during, before, or after the assignment time period In your assignment readme file, acknowledge all resources used Ask your preceptor for clarifications if necessary 17

Tentatively Course Schedule Weeks Lectures Precepts 1-2 Intro to C (conceptual) Intro to Linux/GNU Intro to C (mechanical) 3-6 Pgmming in the Large Advanced C 7 Midterm Exam 8-14 Under the Hood Assembly Language Pgmming Assignments 15 Final Exam See course Schedule web page for details 18

Any questions before we start? 19

C : History We will use Not yet popular; our compiler supports only partially 1960 1970 1972 1978 1989 1999 BCPL B C K&R C ANSI C89 ISO C90 ISO/ANSI C99 LISP Smalltalk C++ Java 20

C vs. Java: Design Goals C design goals Support structured programming Support development of the Unix OS and Unix tools As Unix became popular, so did C Implications for C Good for system-level programming But often used for application-level programming sometimes inappropriately Low-level Close to assembly language; close to machine language; close to hardware Efficiency over portability Efficiency over security Flexibility over security 21

C vs. Java: Design Goals Java design goals Support object-oriented programming Allow same program to be executed on multiple operating systems Support using computer networks Execute code from remote sources securely Adopt the good parts of other languages (esp. C and C++) Implications for Java Good for application-level programming High-level Virtual machine insulates programmer from underlying assembly language, machine language, hardware Portability over efficiency Security over efficiency Security over flexibility 22

C vs. Java: Design Goals Differences in design goals explain many differences between the languages C s design goal explains many of its eccentricities We ll see examples throughout the course 23

C vs. Java: Overview Dennis Ritchie on the nature of C: C has always been a language that never attempts to tie a programmer down. C has always appealed to systems programmers who like the terse, concise manner in which powerful expressions can be coded. C allowed programmers to (while sacrificing portability) have direct access to many machine-level features that would otherwise require the use of assembly language. C is quirky, flawed, and an enormous success. While accidents of history surely helped, it evidently satisfied a need for a system implementation language efficient enough to displace assembly language, yet sufficiently abstract and fluent to describe algorithms and interactions in a wide variety of environments. 24

C vs. Java: Overview (cont.) Bad things you can do in C that you can t do in Java Shoot yourself in the foot (safety) Shoot others in the foot (security) Ignore wounds (error handling) Dangerous things you must do in C that you don t in Java Explicitly manage memory via malloc() and free() Good things you can do in C, but (more or less) must do in Java Program using the object-oriented style Good things you can t do in C but can do in Java Write completely portable code 25

C vs. Java: Details Remaining slides provide some details Suggestion: Use for future reference Slides covered briefly now, as time allows 26

C vs. Java: Details (cont.) Overall Program Structure Building Hello.java: Java public class Hello { public static void main(string[] args) { System.out.println( "Hello, world"); } } % javac Hello.java % ls Hello.class Hello.java % hello.c: #include <stdio.h> C int main(void) { printf("hello, world\n"); return 0; } % gcc209 hello.c % ls a.out hello.c % Running % java Hello Hello, world % % a.out Hello, world % 27

C vs. Java: Details (cont.) Java C Character type char // 16-bit unicode char /* 8 bits */ Integral types Floating point types Logical type Generic pointer type byte short int long float double boolean // 8 bits // 16 bits // 32 bits // 64 bits // 32 bits // 64 bits // no equivalent void* Constants final int MAX = 1000; (unsigned) char (unsigned) short (unsigned) int (unsigned) long float double long double /* no equivalent */ /* use integral type */ #define MAX 1000 const int MAX = 1000; enum {MAX = 1000}; 28

C vs. Java: Details (cont.) Java C Arrays Array bound checking Pointer type Record type int [] a = new int [10]; float [][] b = new float [5][20]; int a[10]; float b[5][20]; // run-time check /* no run-time check */ // Object reference is an // implicit pointer class Mine { int x; float y; } int *p; struct Mine { int x; float y; } 29

C vs. Java: Details (cont.) Java C Strings String concatenation String s1 = "Hello"; String s2 = new String("hello"); s1 + s2 s1 += s2 Logical ops &&,,! &&,,! char *s1 = "Hello"; char s2[6]; strcpy(s2, "hello"); #include <string.h> strcat(s1, s2); Relational ops =,!=, >, <, >=, <= =,!=, >, <, >=, <= Arithmetic ops +, -, *, /, %, unary - +, -, *, /, %, unary - Bitwise ops >>, <<, >>>, &,, ^ >>, <<, &,, ^ Assignment ops =, *=, /=, +=, -=, <<=, >>=, >>>=, =, ^=, =, %= =, *=, /=, +=, -=, <<=, >>=, =, ^=, =, %= 30

C vs. Java: Details (cont.) if stmt switch stmt Java if (i < 0) statement1; else statement2; switch (i) { case 1:... break; case 2:... break; default:... } C if (i < 0) statement1; else statement2; switch (i) { case 1:... break; case 2:... break; default:... } goto stmt // no equivalent goto SomeLabel; 31

C vs. Java: Details (cont.) Java C for stmt while stmt do-while stmt for (int i=0; i<10; i++) statement; while (i < 0) statement; do { statement; } while (i < 0) int i; for (i=0; i<10; i++) statement; while (i < 0) statement; do { statement; } while (i < 0) continue stmt continue; continue; labeled continue stmt continue SomeLabel; /* no equivalent */ break stmt break; break; labeled break stmt break SomeLabel; /* no equivalent */ 32

C vs. Java: Details (cont.) Java C return stmt return 5; return; return 5; return; Compound stmt (alias block) { } statement1; statement2; { } statement1; statement2; Exceptions throw, try-catch-finally /* no equivalent */ Comments Method / function call /* comment */ // another kind f(x, y, z); someobject.f(x, y, z); SomeClass.f(x, y, z); /* comment */ f(x, y, z); 33

Example C Program #include <stdio.h> #include <stdlib.h> const double KMETERS_PER_MILE = 1.609; int main(void) { int miles; double kmeters; printf("miles: "); if (scanf("%d", &miles)!= 1) { fprintf(stderr, "Error: Expect a number.\n"); exit(exit_failure); } kmeters = miles * KMETERS_PER_MILE; printf("%d miles is %f kilometers.\n", miles, kmeters); return 0; } 34

Summary Course overview Goals Goal 1: Learn programming in the large Goal 2: Look under the hood Goal 2 supports Goal 1 Use of C and Linux supports both goals Learning resources Lectures, precepts, programming environment, course mailing list, textbooks Course Web site: access via http://www.ndsl.kaist.edu/~kyoungsoo/ee209/ 35

Summary Getting started with C C was designed for system programming Differences in design goals of Java and C explain many differences between the languages Knowing C design goals explains many of its eccentricities Knowing Java gives you a head start at learning C C is not object-oriented, but many aspects are similar 36

Getting Started Check out course Web site soon Study Policy page First assignment is available Establish a reasonable computing environment soon Instructions given in first precept 37