CSC 2400: Computing Systems

Size: px
Start display at page:

Download "CSC 2400: Computing Systems"

Transcription

1 CSC 2400: Computing Systems Professor Mirela Damian 1 Introductions Mirela Damian (professor) Room 167A in the Mendel Science Building mirela.damian@villanova.edu Rusul Alsalihi (teaching assistant) Room 159 in the Mendel Science Building ralsalih@villanova.edu Programming assistants Room 292 in the Mendel Science Building 2

2 What do Computers Do? Do a survey on campus Numerous correct answers Computers Execute Instructions. That s all! 3 What Kind of Instructions? Strictly speaking, computers only understand machine language (binary machine code). 4

3 Hierarchy of Computer Languages Click an icon Press a key Verbal command Oracle / SQL MS Access Human interface languages Database languages SGML/ XML HTML Lisp / ML Shells / scripts Python Basic/ V Basic Java Pascal/Fortran ADA C++ C Mark up languages Interpreted languages High level compiled languages Assembly Low level el languages ages Machine Code 5 Course Goals: Look under the hood Help you learn what happens under the hood of computer systems Specifically, two downward tours Language levels tour High-level language (C) assembly language machine language g (IA-32) Service levels tour High-level language (C) standard libraries operating system (Linux) Reveal how abstractions are created 6

4 Course Goals: Why C? Q: Why C instead of Java? A: C facilitates language levels tour C is a lower-level language C is closely related to assembly language A: C facilitates service levels tour Linux is written in C 7 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 8

5 Course Goals: Summary Help you to become a Power Programmer!!! 9 Resources: Books Textbook System Programming with C and Unix, Adam Hoover. Covers both language-level and system-level tours Some topics will be covered in more depth in class Lectures based on textbook and online material The textbook is mandatory Homework assignments are based on textbook and in class lectures. All homework due at start of class; not at the end of class. Additional materials posted on the class web site. 10

6 Resources: Programming Environment One Linux machine named felix. felix.csc.villanova.edu Any lab, or your own PC/MAC/Linux computer. Linux GNU Your Pgm felix SSH 11 Resources: Programming Environment Several Unix machines: degas, cezanne, tanner, picasso, rodin, cassatt, gauguin, g matisse. tanner.csc.villanova.edu Any lab, or your own PC/Mac/Linux Computer Unix GNU Your Pgm tanner rodin matisse SSH 12

7 Try to Log In Now Locate and invoke Secure Shell Client from the Start menu Click on the Quick Connect tab In the Host Name textbox, type in tanner.csc.villanova.edu In the User Name textbox, type in your username (the one the system administrator ed you) Click on Connect A text window with the shell prompt will be opened for you. This is a command line interface. You will interact with the Unix operating system by typing in commands at the shell prompt.try for example hostname The name of the machine (tanner) will be displayed. 13 Workload Distribution To use our Unix resources efficiently, from tanner connect arbitrarily to rodin or degas by typing in either ssh rodin ssh degas Too many students t working on one same machine can slow it down considerably. To log off, simply type in exit 14

8 Grading Assignments (45%) Pencil and paper p Clean, readable, working code On time (no late submission) First assignment is available now Exams (45%) Midterm Comprehensive final exam Class Participation (10%) No makeup assignments or exams Lecture attendance is mandatory 15 Programming g Assignments Start early to allow time for debugging. 16

9 Course Schedule Very generally Weeks Lectures 1-2 Introduction to C and Unix 3-7 Advanced C 7 Midterm exam Recess 8-11 Under the hood assembly language Thanksgiving Recess Under the hood Unix processes Dec. 19 Final exam, 6:00 8:30 pm See course web site for details 17 Any questions before we start? 18

10 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 19 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 20

11 C vs. Java: Design Goals Differences in design goals explain many differences between the languages C s Cs design goal explains many of its eccentricities We ll see examples throughout the course 21 C vs. Java: Overview Dennis Ritchie on the nature of C: 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. 22

12 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 objected-oriented style Good things that you can t do in C but can do in Java Write completely portable code 23 C vs. Java: Details Remaining slides provide some details Suggestion: Use for future reference Slides covered briefly now 24

13 C vs. Java: Details (cont.) Overall Program Structure Java Hello.java: hello.c: public class Hello public static void #include <stdio.h> main(string[] args) int main(void) System.out.println( printf("hello Hello, world\n"); "Hello, world"); return 0; C Building % javac Hello.java % ls Hello.class Hello.java % % gcc hello.c % ls a.out hello.c % Running % java Hello Hello, world % %./a.out Hello, world % 25 C vs. Java: Details (cont.) Java C Character type char // 16-bit unicode char /* 8 bits */ Integral types byte short int long // 8 bits // 16 bits // 32 bits // 64 bits Floating gpoint float // 32 bits types double // 64 bits Logical type Generic pointer type boolean // 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; 26

14 C vs. Java: Details (cont.) Arrays Java int [] a = new int [10]; float [][] b = new float [5][20]; C int a[10]; float b[5][20]; Array bound checking Pointer type Record type // 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; 27 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 i ops >>, <<, >>>, &,, ^ >>, <<, &,, ^ Assignment ops =, *=, /=, +=, -=, <<=, >>=, >>>=, =, ^=, =, %= =, *=, /=, +=, -=, <<=, >>=, =, ^=, =, %= 28

15 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 t // no equivalent goto SomeLabel; 29 C vs. Java: Details (cont.) Java C for stmt while stmt do-while stmt t for (int i=0; i<10; i++) statement; int i; for (i=0; i<10; i++) statement; while (i < 0) while (i < 0) statement; statement; do statement; ; while (i < 0) 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 */ 30

16 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); 31 Example C Program File circle.c: #include <stdio.h> int main(void) /* Read a circle's radius from stdin, and compute and write its diameter and circumference to stdout. Return 0. */ int radius; int diam; double circum; printf("enter the circle's radius:\n"); scanf("%d", &radius); diam = 2 * radius; circum = * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; 32

17 Building and Running To build (preprocess, compile, assemble, and link): $ gcc circle.c o circle To run: $./circle Enter the circle's radius: 5 A circle with radius 5 has diameter 10 and circumference Typed by user 33 Steps in the Build Process To build one step at a time: Preprocess: circle.c circle.i Compile: circle.i circle.s Assemble: circle.s circle.o $ gcc E circle.c > circle.i $ gcc S circle.i $ gcc c circle.s $ gcc circle.o o circle Link: circle.o circle Why build one step at a time? Helpful for learning how to interpret error messages Permits partial builds (described later in course) 34

18 The Preprocessor s View File circle.c: #include <stdio.h> int main(void) Preprocessor directive Preprocessor replaces with contents of file /usr/include/stdio.h /* Read a circle's radius from stdin, and compute and write its diameter and circumference to stdout. Return 0. */ int radius; int diam; double circum; printf("enter the circle's radius:\n"); scanf("%d", &radius); diam = 2 * radius; circum = * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; Comment Preprocessor removes 35 Results of Preprocessing File circle.i: Declarations of printf(), scanf(), and other functions; compiler will have enough information to check subsequent function calls int printf(char*, ); int scanf(char*, ); int main(void) int radius; int diam; double circum; printf("enter the circle's radius:\n"); scanf("%d", &radius); diam = 2 * radius; circum = * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; Where are the DEFINITIONS of printf() and scanf()? 36

19 What is Wrong? #include <stdio.h> int SomeFunction(x); int main() int result; result = SomeFunction(5); return rn 0; int SomeFunction(int x) return x * x; 37 The Compiler s View File circle.i: int printf(char*, ); int scanf(char*, ); int main(void) int radius; int diam; double circum; printf("enter the circle's radius:\n"); scanf("%d", &radius); diam = 2 * radius; circum = * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; Function declarations Compiler notes return types and parameter types so it can check your function calls Function definition Compound statement alias block Return type of main() should be int 38

20 The Compiler s View (cont.) File circle.i: Declaration statements Must appear before any other kind of statement in block; variables must be declared int printf(char*, ); int scanf(char*, ); int main(void) int radius; before use int diam; double circum; printf("enter the circle's radius:\n"); scanf("%d", &radius); diam = 2 * radius; circum = * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; String constants Function call statements & ( address of ) operator Explained later in course, with pointers 39 What is Wrong? #include <stdio.h> int main() int sum; int i; for(int i = 1; i <= 10; i++) sum = sum + i; int fact; for(i = 1; i <= 10; i++) fact = fact * i; return 0; 40

21 The Compiler s View (cont.) File circle.i: int printf(char*, ); int scanf(char*, ); int main(void) Constant of type int Constant of type double int radius; int diam; double circum; printf("enter the circle's radius:\n"); scanf("%d", &radius); diam = 2 * radius; circum = * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; Expression statements Cast operator Unnecessary here, but good style to avoid mixed-type expressions 41 The Compiler s View (cont.) File circle.i: int printf(char*, ); int scanf(char*, ); int main(void) int radius; int diam; double circum; printf("enter the circle's radius:\n"); scanf("%d", &radius); Function call statements printf() can be called with 1 or more actual parameters diam = 2 * radius; circum = * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; Return statement Convention: 0 returned from main() means success; non-0 means failure 42

22 Results of Compiling File circle.s:.lc0:.lc1: main:.section.rodata.string "Enter the circle's radius:\n".string "%d".section.text.globl main.type pushl movl pushl call addl subl leal pushl pushl call %ebp %esp, %ebp $.LC0 printf $16, %esp $8, %esp -4(%ebp), %eax %eax $.LC1 scanf Assembly language Still missing definitions of printf() and scanf() 43 The Assembler s View File circle.s:.lc0:.lc1: main:.section.rodata.string "Enter the circle's radius:\n".string "%d".section.text.globl main.type pushl %ebp movl %esp, %ebp pushl $.LC0 call printf addl $16, %esp subl $8, %esp leal -4(%ebp), %eax pushl %eax pushl $.LC1 call scanf Assembly language Assembler translates assembly language into machine language Details provided in 2nd half of course 44

23 Results of Assembling File circle.o: Listing omitted Not human-readable Machine language Object file Still missing definitions of printf() and scanf() 45 The Linker s View File circle.o: Listing omitted Not human-readable Machine language The linker: Observes that Code in circle.o calls printf() and scanf() Code in circle.o does not define printf() or scanf() Fetches machine language definitions of printf() and scanf() from standard C library (/usr/lib/libc.a on your machine) Merges those definitions with circle.o to create 46

24 Results of Linking File circle: Listing omitted Not human-readable Machine language Complete executable binary file Run-Time View At run-time, memory devoted to program is divided into sections: TEXT RODATA DATA BSS HEAP TEXT (read-only) Stores machine language instructions RODATA(read-only) Stores read-only data (esp. strings) STACK(read/write) Stores local variables STACK Other sections described later in course 48

25 Run-Time View: Startup At program startup: TEXT contains machine language code defining main(), printf(), scanf(), etc. STACK is empty TEXT STACK RODATA main printf scanf RODATA contains every string ti constant tused in program; each is an array of characters, terminated with the null character ( \0 ) \0) Enter the circle s radius\n\0 %d\0 A circle with radius %d has diameter %d\n\0 and circumference %f.\n\0 49 Run-Time View: Declarations int radius; int diam; double circum; Computer allocates memory onto STACK for each local variable: 4 bytes for int, 8 bytes for double TEXT STACK RODATA main printf scanf circum diam radius Enter the circle s radius\n\0 %d\0 A circle with radius %d has diameter %d\n\0 and circumference %f.\n\0 50

26 Run-Time View: Writing a String printf("enter the circle's radius:\n"); Computer passes address containing E to printf(); printf() prints characters until it encounters \0 TEXT STACK RODATA main printf scanf circum diam radius Enter the circle s radius\n\0 %d\0 A circle with radius %d has diameter %d\n\0 and circumference %f.\n\0 51 Run-Time View: Reading an int scanf("%d", &radius); Computer passes address containing % to scanf(). scanf() waits for user input; user types 5; scanf() reads character(s), converts to decimal (d) constant, assigns to radius TEXT STACK RODATA main printf scanf circum diam radius 5 Enter the circle s radius\n\0 %d\0 A circle with radius %d has diameter %d\n\0 and circumference %f.\n\0 52

27 Run-Time View: Computing Results diam = 2 * radius; circum = * (double)diam; Computer uses radius to compute diam and circum TEXT STACK RODATA main printf scanf circum diam radius Enter the circle s radius\n\0 %d\0 A circle with radius %d has diameter %d\n\0 and circumference %f.\n\0 53 Run-Time View: Writing an int printf("a circle with radius %d has diameter %d\n", radius, diam); Computer passes address of A, value of radius, and value of diam to printf(). printf() prints until \0, replacing 1 st %d with character comprising 5, 2 nd %d with characters comprising 10 characters comprising 10 TEXT STACK RODATA main printf scanf circum diam radius Enter the circle s radius\n\0 %d\0 A circle with radius %d has diameter %d\n\0 and circumference %f.\n\0 54

28 Run-Time View: Writing a double printf("and circumference %f.\n", circum); TEXT STACK RODATA Computer passes address of a and value of circum to printf(). printf() prints until \0, replacing %f with characters comprising main printf scanf circum diam radius Enter the circle s radius\n\0 %d\0 A circle with radius %d has diameter %d\n\0 and circumference %f.\n\0 55 Run-Time View: Exiting return 0; Computer reclaims memory used by program; sections cease to exist 56

29 What Goes Where? int fact(n) int i, result=1; for(i = 1; i<=n; i++) result = result * i; return result; int main() int n; printf( Enter a value\n ); scanf( %d, &n); printf( The factorial of %d is %d, n, fact(n)); return 0; 57 What Goes Where? int fact(n) int i, ret=1; for(i = 1; i<=n; i++) ret = ret * i; return ret; TEXT STACK RODATA int main() int n; printf( Enter a value\n ); scanf( %d, &n); printf( The factorial of %d is %d, n,fact(n)); return 0; 58

30 Circle Program File circle.c: #include <stdio.h> int main(void) /* Read a circle's radius from stdin, and compute and write its diameter and circumference to stdout. Return 0. */ int radius; int diam; double circum; printf("enter the circle's radius:\n"); scanf("%d", &radius); diam = 2 * radius; circum = * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; 59 Toward Version 2 Problem (stylistic flaw): is a magic number Should give it a symbolic name to Increase code clarity Thereby increase code maintainability Solution: (In Java: final fields, final variables) In C: three approaches 60

31 Symbolic Constants: #define Approach 1: #define Preprocessor directive: replace START_STATE with 0 void f(void) #define START_ STATE 0 #define POSSIBLE_COMMENT_STATE 1 #define COMMENT_STATE 2 int state; state = START_STATE; state = COMMENT_STATE; Preprocessor replaces with 0 Preprocessor replaces with 2 61 Symbolic Constants: #define Approach 1 strengths Preprocessor does substitutions only for tokens int mystart_state; /* No replacement */ Preprocessor does not do substitutions within string constants printf("what is the START_STATE?\n"); /* No replacement */ Simple textual replacement; works for any type of data #define PI

32 Version 2 using #define #include <stdio.h> #define PI int main(void) /* Read a circle's radius from stdin, and compute and write its diameter and circumference to stdout. Return 0. */ int radius; int diam; double circum; printf("enter the circle's radius:\n"); scanf("%d", &radius); diam = 2 * radius; circum = PI * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; 63 Symbolic Constants: #define Approach 1 weaknesses Preprocessor does not respect context void f(void) #define MAX 1000 int MAX = 2000; Preprocessor replaces with 1000!!! Preprocessor does not respect scope void f(void) #define MAX 1000 void g(void) int MAX = 2000; Conventions: Use all uppercase for constants -- and only for constants Place #defines at beginning of file, not within function definitions 64

33 Symbolic Constants: const Approach 2: constant variables (oxymoron!!!) void f(void) const int START_STATE = 0; const int POSSIBLE_COMMENT_STATE STATE = 1; const int COMMENT_STATE = 2; int state; t state = START_STATE; state = COMMENT_STATE; Compiler does not allow value of START_STATE to change 65 Version 2 using const #include <stdio.h> const double PI = ; int main(void) /* Read a circle's radius from stdin, and compute and write its diameter and circumference to stdout. Return 0. */ int radius; int diam; double circum; printf("enter the circle's radius:\n"); scanf("%d", &radius); diam = 2 * radius; circum = PI * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; 66

34 Symbolic Constants: const Approach 2 strengths Works for any type of data const double PI = ; Handled by compiler, not preprocessor; p compiler respects context and scope Approach 2 weaknesses Does not work for array lengths (unlike C++) const int ARRAY_LENGTH = 10; int a[array_length]; /* Compiletime error */ 67 Symbolic Constants: enum Approach 3: Enumerations void f(void) enum State START_STATE, POSSIBLE_COMMENT_STATE, COMMENT_STATE, ; enum State state; state = START_STATE; state = COMMENT_STATE; Defines a variable named state to be of type enum State Defines a new type named enum State The constants of type enum State are START_STATE, 68

35 Symbolic Constants: enum Approach 3 note Enumerated constants are interchangeable with ints START_STATE is the same as 0 POSSIBLE_COMMENT_STATE is the same as 1 Etc. state = 0; /* Can assign int to enum. */ i = START_STATE; /* Can assign enum to int. */ 69 Symbolic Constants: enum Approach 3 strengths Can explicitly specify values for names enum State START_STATE = 5, POSSIBLE_COMMENT_STATE = 3, COMMENT_STATE = 4, ; Can omit type name, thus effectively giving names to int literals enum MAX_VALUE = 9999; int i = MAX_VALUE; Works when specifying array lengths enum ARRAY_LENGTH = 10; int a[array_length]; 70

36 Symbolic Constants: enum Approach 3 weakness Does not work for non-integral data types enum PI = ; /* Compiletime error */ 71 Symbolic Constant Style Rules In summary of symbolic constants Style rules: 1. Use enumerations to give symbolic names to integral constants 2. Use const variables to give symbolic names to non-integral constants 3. Use #define with all uppercase at beginning of file 72

37 Circle Program (Version 2) File circle.c (version 2): #include <stdio.h> int main(void) /* Read a circle's radius from stdin, and compute and write its diameter and circumference to stdout. Return 0. */ const double PI = ; int radius; int diam; double circum; printf("enter the circle's radius:\n"); scanf("%d", &radius); diam = 2 * radius; circum = PI * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; 73 Toward Version 3 Problem: Program does not handle bad user input $ circle Enter the circle's radius: abc User enters a non-number. How can the program detect that? What should the program do? 74

38 scanf 75 Detecting Bad User Input Solution Part 1: Detecting bad user input scanf() returns number of values successfully read Example: int returnvalue; returnvalue = scanf("%d", &i); if (returnvalue!= 1) /* Error */ Or, more succinctly: if (scanf("%d", &i)!= 1) /* Error */ Or, for more than one variable: if (scanf("%d%d", &i, &j)!= 2) /* Error */ 76

39 Reporting Failure to User Solution Part 2: Reporting failure to the user Stream Default Binding Purpose C Functions stdin Keyboard Normal input scanf( ); fscanf(stdin, ); stdout stderr Video screen Video screen Normal output Abnormal output printf( ); fprintf(stdout, ); fprintf(stderr, ); To report failure to user, should write a message to stderr 77 Reporting Failure to OS Solution Part 3: Reporting failure to the operating system Nature of Program Status Code that Program Completion Should Return to OS Successful 0 EXIT_SUCCESS (#defined in stdlib.h as 0) Unsuccessful EXIT_FAILURE (#defined in stdlib.h as???) To generate status code x, program should: Execute return x statement to return from main() function, or Call exit(x) to abort program System-dependent; Shell can examine status code on tanner, 1 Note: In main() function, return statement and exit() function have same effect In other functions, they have different effects 78

40 Circle Program (Version 3) #include <stdio.h> #include <stdlib.h> int main(void) /* Read a circle's radius from stdin, and compute and write its diameter and circumference to stdout. Return 0 if successful. */ const double PI = ; int radius; int diam; double circum; printf("enter the circle's radius:\n"); if (scanf("%d", &radius)!= 1) fprintf(stderr, "Error: Not a number\n"); exit(exit_failure); /* or: return EXIT_FAILURE; */ diam = 2 * radius; circum = PI * (double)diam; printf("a circle with radius %d has diameter %d\n", radius, diam); printf("and circumference %f.\n", circum); return 0; 79 Summary Simple C programs Program structure Defining symbolic constants #define, constant variables, enumerations Detecting and reporting failure The stderr stream The exit() function Functionality of the gcc command Preprocessor, compiler, assembler, linker Memory layout of a Linux process TEXT, RODATA, STACK sections (More sections DATA, BSS, HEAP later in the course) 80

41 Getting Started Check out course web site now Explore your computing environment Assignment posted on the website Reading Required: Chapters 2, 6.1, from the textbook Optional: Chapter 1 81

Program Building. Goals for this Lecture. Help you learn about: Program structure. Detecting and reporting failure

Program Building. Goals for this Lecture. Help you learn about: Program structure. Detecting and reporting failure Simple C Program Building 1 Goals for this Lecture Help you learn about: Simple C programs Program structure Defining symbolic constants Detecting and reporting failure Functionality of the gcc command

More information

CSC 2400: Computing Systems!

CSC 2400: Computing Systems! CSC 2400: Computing Systems! Professor Mirela Damian! http://www.csc.villanova.edu/~mdamian/! 1 Introductions! Mirela Damian (professor)! Room 167A in the Mendel Science Building! mirela.damian@villanova.edu!!

More information

C Fundamentals! C vs. Java: Design Goals. q Java design goals! q Implications for Java! language, machine language, hardware!

C Fundamentals! C vs. Java: Design Goals. q Java design goals! q Implications for Java! language, machine language, hardware! C Fundamentals C vs. Java: Design Goals q Java design goals q Support object-oriented programming q Allow program to be executed on multiple operating systems q Support using computer networks q Execute

More information

EE 209: Programming Structures for Electrical Engineering

EE 209: Programming Structures for Electrical Engineering 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

More information

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

EE 209: Programming Structures for Electrical Engineering. (Many Slides Borrowed from Princeton COS 217) EE 209: Programming Structures for Electrical Engineering (Many Slides Borrowed from Princeton COS 217) 1 Goals for Today s Class Course overview Introduction Course goals Resources Grading Policies Getting

More information

COS 217: Introduction to Programming Systems

COS 217: Introduction to Programming Systems COS 217: Introduction to Programming Systems 1 Goals for Todayʼs Class Course overview Introductions Course goals Resources Grading Policies Getting started with C C programming language overview 2 1 Introductions

More information

COS 217: Introduction to Programming Systems!

COS 217: Introduction to Programming Systems! COS 217: Introduction to Programming Systems! 1 Goals for Today s Class! Course overview" Introductions" Course goals" Resources" Grading" Policies" Getting started with C" C programming language overview"

More information

COS 217: Introduction to Programming Systems!

COS 217: Introduction to Programming Systems! COS 217: Introduction to Programming Systems! 1 Goals for Today s Class! Course overview" Introductions" Course goals" Resources" Grading" Policies" Getting started with C" C programming language overview"

More information

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

COS 217: Introduction to Programming Systems. Goals for Todayʼs Class. Introductions COS 217: Introduction to Programming Systems 1 Goals for Todayʼs Class Course overview Introductions Course goals Resources Grading Policies Getting started with C C programming language overview 2 Introductions

More information

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

Fall, $ cat welcome.c #include <stdio.h> $ cat welcome.c #include int main(int argc, char *argv[]) { printf( COS 217\n ); printf( Introduction to Programming Systems\n\n ); } printf( Fall, 2018\n ); return 0; $ gcc217 welcome.c o welcome

More information

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

Princeton University Computer Science 217: Introduction to Programming Systems. Agenda. COS 217: Introduction to Programming Systems. Princeton University omputer Science 217: Introduction to Programming Systems OS 217: Introduction to Programming Systems 1 2 Introductions Professor Aarti Gupta aartig@cs.princeton.edu Lead Preceptors

More information

Towards the Hardware"

Towards the Hardware CSC 2400: Computer Systems Towards the Hardware Chapter 2 Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32) 1 High-Level Language Make programming

More information

COS 217: Introduction to Programming Systems

COS 217: Introduction to Programming Systems COS 217: Introduction to Programming Systems Fall 2006 (TTh 10:00-10:50 in CS 104) Prof. David I. August Preceptors: Bob Dondero, Changhoon Kim, Guilherme Ottoni http://www.cs.princeton.edu/courses/archive/fall06/cos217/

More information

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

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify

More information

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

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006 C Compilation Model Comp-206 : Introduction to Software Systems Lecture 9 Alexandre Denault Computer Science McGill University Fall 2006 Midterm Date: Thursday, October 19th, 2006 Time: from 16h00 to 17h30

More information

Goals of this Lecture

Goals of this Lecture A Taste of C C 1 Goals of this Lecture Help you learn about: The basics of C Deterministic finite state automata (DFA) Expectations for programming assignments Why? Help you get started with Assignment

More information

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

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

More information

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

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

More information

CSC 1600 Memory Layout for Unix Processes"

CSC 1600 Memory Layout for Unix Processes CSC 16 Memory Layout for Unix Processes" 1 Lecture Goals" Behind the scenes of running a program" Code, executable, and process" Memory layout for UNIX processes, and relationship to C" : code and constant

More information

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

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static

More information

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

C Introduction. Comparison w/ Java, Memory Model, and Pointers CS 261 Fall 2018 Mike Lam, Professor C Introduction Comparison w/ Java, Memory Model, and Pointers Please go to socrative.com on your phone or laptop, choose student login and join room LAMJMU The C Language

More information

Class Information ANNOUCEMENTS

Class Information ANNOUCEMENTS Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to

More information

CSCI 2132 Software Development. Lecture 8: Introduction to C

CSCI 2132 Software Development. Lecture 8: Introduction to C CSCI 2132 Software Development Lecture 8: Introduction to C Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 21-Sep-2018 (8) CSCI 2132 1 Previous Lecture Filename substitution

More information

The C language. Introductory course #1

The C language. Introductory course #1 The C language Introductory course #1 History of C Born at AT&T Bell Laboratory of USA in 1972. Written by Dennis Ritchie C language was created for designing the UNIX operating system Quickly adopted

More information

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

Princeton University Computer Science 217: Introduction to Programming Systems The Design of C Princeton University Computer Science 217: Introduction to Programming Systems The Design of C C is quirky, flawed, and an enormous success. While accidents of history surely helped, it evidently satisfied

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

Topic 6: A Quick Intro To C

Topic 6: A Quick Intro To C Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

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

CS 61C: Great Ideas in Computer Architecture Introduction to C CS 61C: Great Ideas in Computer Architecture Introduction to C Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda C vs. Java vs. Python Quick Start Introduction

More information

CSC 2400: Computer Systems. Key to Success

CSC 2400: Computer Systems. Key to Success CSC 2400: Computer Systems Week 1 Goals and Introduction Dr. Mirela Damian Key to Success q Start early to allow +me for debugging 1 Policy: Write your own code q Programming in an individual creative

More information

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. A Taste of C. Agenda.

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. A Taste of C. Agenda. Princeton University Computer Science 217: Introduction to Programming Systems Goals of this Lecture A Taste of C C Help you learn about: The basics of C Deterministic finite-state automata (DFA) Expectations

More information

C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017

C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017 C Concepts - I/O Lecture 19 COP 3014 Fall 2017 November 29, 2017 C vs. C++: Some important differences C has been around since around 1970 (or before) C++ was based on the C language While C is not actually

More information

Draft. Chapter 1 Program Structure. 1.1 Introduction. 1.2 The 0s and the 1s. 1.3 Bits and Bytes. 1.4 Representation of Numbers in Memory

Draft. Chapter 1 Program Structure. 1.1 Introduction. 1.2 The 0s and the 1s. 1.3 Bits and Bytes. 1.4 Representation of Numbers in Memory Chapter 1 Program Structure In the beginning there were 0s and 1s. GRR 1.1 Introduction In this chapter we will talk about memory: bits, bytes and how data is represented in the computer. We will also

More information

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

Software Project. Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva Software Project Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva Emails: (canetti/benriva)@post.tau.ac.il nathan.manor@gmail.com gideon@mta.ac.il http://www.cs.tau.ac.il/~roded/courses/soft-project10.html

More information

CSE 303 Lecture 8. Intro to C programming

CSE 303 Lecture 8. Intro to C programming CSE 303 Lecture 8 Intro to C programming read C Reference Manual pp. Ch. 1, 2.2-2.4, 2.6, 3.1, 5.1, 7.1-7.2, 7.5.1-7.5.4, 7.6-7.9, Ch. 8; Programming in C Ch. 1-6 slides created by Marty Stepp http://www.cs.washington.edu/303/

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5. Iulian Năstac Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

More information

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming. Zeyneb KURT BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

More information

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

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers Introduction to C Geared toward programmers Robert Escriva Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Cornell CS 4411, August 30, 2010 1 Why C? 2 A Quick Example 3 Programmer s Responsibilities

More information

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Introduction to C. Winter 2019

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Introduction to C. Winter 2019 CSCI 2132: Software Development Introduction to C Norbert Zeh Faculty of Computer Science Dalhousie University Winter 2019 The C Programming Language Originally invented for writing OS and other system

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

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

Introduction to C. Sean Ogden. Cornell CS 4411, August 30, Geared toward programmers Introduction to C Geared toward programmers Sean Ogden Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Robert Escriva Zhiyuan Teo Ayush Dubey Cornell CS 4411, August 30, 2013 Administrative Information

More information

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

Two s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011 Two s Complement Review CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part I) Instructor: Michael Greenbaum http://inst.eecs.berkeley.edu/~cs61c/su11 Suppose we had

More information

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

Introduction to C. Ayush Dubey. Cornell CS 4411, August 31, Geared toward programmers Introduction to C Geared toward programmers Ayush Dubey Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Robert Escriva Zhiyuan Teo Cornell CS 4411, August 31, 2012 Administrative Information Outline

More information

Continued from previous lecture

Continued from previous lecture The Design of C: A Rational Reconstruction: Part 2 Jennifer Rexford Continued from previous lecture 2 Agenda Data Types Statements What kinds of operators should C have? Should handle typical operations

More information

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut mith College CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 2 Hours D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard

More information

Introduction Presentation A

Introduction Presentation A CSE 2421/5042: Systems I Low-Level Programming and Computer Organization Introduction Presentation A Read carefully: Bryant Chapter 1 Study: Reek Chapter 2 Skim: Reek Chapter 1 08/22/2018 Gojko Babić Some

More information

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

Topic 6: A Quick Intro To C. Reading. goto Considered Harmful History Topic 6: A Quick Intro To C Reading Assumption: All of you know basic Java. Much of C syntax is the same. Also: Some of you have used C or C++. Goal for this topic: you can write & run a simple C program

More information

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p.

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p. Lecture 10 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 10: Formatted Input and Output 27-Sep-2017 Location: Goldberg CS 127 Time: 14:35 15:25 Instructor:

More information

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CprE 288 Introduction to Embedded Systems Exam 1 Review.  1 CprE 288 Introduction to Embedded Systems Exam 1 Review http://class.ece.iastate.edu/cpre288 1 Overview of Today s Lecture Announcements Exam 1 Review http://class.ece.iastate.edu/cpre288 2 Announcements

More information

Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance. John Edgar 2

Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance. John Edgar 2 CMPT 125 Running a C program Compilation Python and C Variables and types Data and addresses Functions Performance John Edgar 2 Edit or write your program Using a text editor like gedit Save program with

More information

EL2310 Scientific Programming

EL2310 Scientific Programming (yaseminb@kth.se) Overview Overview Roots of C Getting started with C Closer look at Hello World Programming Environment Discussion Basic Datatypes and printf Schedule Introduction to C - main part of

More information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C C: A High-Level Language Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University! Gives

More information

CSC231 C Tutorial Fall 2018 Introduction to C

CSC231 C Tutorial Fall 2018 Introduction to C mith College CSC231 C Tutorial Fall 2018 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 4 Installments! Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard

More information

Programming in C and C++

Programming in C and C++ Programming in C and C++ Types, Variables, Expressions and Statements Neel Krishnaswami and Alan Mycroft Course Structure Basics of C: Types, variables, expressions and statements Functions, compilation

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Welcome to... CS113: Introduction to C

Welcome to... CS113: Introduction to C Welcome to... CS113: Introduction to C Instructor: Erik Sherwood E-mail: wes28@cs.cornell.edu Course Website: http://www.cs.cornell.edu/courses/cs113/2005fa/ The website is linked to from the courses page

More information

BSM540 Basics of C Language

BSM540 Basics of C Language BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()

More information

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

Your Instructor. CSE Content. Notes. Notes. Notes. Summer May 4, 2010 Tools - Tools - Summer 2010 Department of Computer Science and Engineering York University Toronto May 4, 2010 1 / 45 Tools - Your Instructor (Pshemo) Lectures: Tuesday 6.00-8.00pm in CSE1006 Lab: Tuesday

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

CS 241 Data Organization. August 21, 2018

CS 241 Data Organization. August 21, 2018 CS 241 Data Organization August 21, 2018 Contact Info Instructor: Dr. Marie Vasek Contact: Private message me on the course Piazza page. Office: Room 2120 of Farris Web site: www.cs.unm.edu/~vasek/cs241/

More information

EECS2031 Software Tools

EECS2031 Software Tools EECS2031 Software Tools SU 2014-2015 The Course EECS2031 Software Tools Lecture: R N203. Tuesdays 18:00 20:00 Labs: LAS (CSEB) 1006 Lab 01 Tuesdays 16:00 18: 00 Lab 02 Wednesdays 17:00 19:00 Course website:

More information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( )

Tutorial 1: Introduction to C Computer Architecture and Systems Programming ( ) Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough

More information

SWEN-250 Personal SE. Introduction to C

SWEN-250 Personal SE. Introduction to C SWEN-250 Personal SE Introduction to C A Bit of History Developed in the early to mid 70s Dennis Ritchie as a systems programming language. Adopted by Ken Thompson to write Unix on a the PDP-11. At the

More information

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

Introduction to C. Zhiyuan Teo. Cornell CS 4411, August 26, Geared toward programmers Introduction to C Geared toward programmers Zhiyuan Teo Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Robert Escriva Cornell CS 4411, August 26, 2011 1 Administrative Information 2 Why C? 3

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

Final exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Dec 20, Student's name: Student ID:

Final exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Dec 20, Student's name: Student ID: Fall term 2012 KAIST EE209 Programming Structures for EE Final exam Thursday Dec 20, 2012 Student's name: Student ID: The exam is closed book and notes. Read the questions carefully and focus your answers

More information

Assembly Language Programming - III

Assembly Language Programming - III Assembly Language Programming - III GDB Debugger Please refer to the handout New GDB commands (power.s) info registers (prints all register values) print/d $eax (prints individual register value. Note

More information

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz CS 61C: Great Ideas in Computer Architecture Lecture 2: Numbers & C Language Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Numbers wrap-up This is not on the exam! Break C Primer Administrivia,

More information

are all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.

are all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable. CMPS 12M Introduction to Data Structures Lab Lab Assignment 3 The purpose of this lab assignment is to introduce the C programming language, including standard input-output functions, command line arguments,

More information

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion CS 61C: Great Ideas in Computer Architecture Lecture 2: Numbers & C Language Krste Asanović & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Numbers wrap-up This is not on the exam! Break C Primer Administrivia,

More information

CMPE-013/L. Introduction to C Programming

CMPE-013/L. Introduction to C Programming CMPE-013/L Introduction to C Programming Bryant Wenborg Mairs Spring 2014 What we will cover in 13/L Embedded C on a microcontroller Specific issues with microcontrollers Peripheral usage Reading documentation

More information

Lecture 3: C Programm

Lecture 3: C Programm 0 3 E CS 1 Lecture 3: C Programm ing Reading Quiz Note the intimidating red border! 2 A variable is: A. an area in memory that is reserved at run time to hold a value of particular type B. an area in memory

More information

Lecture 2: C Programming Basic

Lecture 2: C Programming Basic ECE342 Introduction to Embedded Systems Lecture 2: C Programming Basic Ying Tang Electrical and Computer Engineering Rowan University 1 Facts about C C was developed in 1972 in order to write the UNIX

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified by Chris Wilcox, Yashwant Malaiya Colorado State University C: A High-Level Language

More information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University C: A High-Level Language! Gives

More information

Course Outline Introduction to C-Programming

Course Outline Introduction to C-Programming ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,

More information

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Autumn 2015 Lecture 3, Simple C programming M. Eriksson (with contributions from A. Maki and

More information

Programming and Data Structure

Programming and Data Structure Programming and Data Structure Sujoy Ghose Sudeshna Sarkar Jayanta Mukhopadhyay Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Spring Semester 2012 Programming and Data

More information

EC 413 Computer Organization

EC 413 Computer Organization EC 413 Computer Organization C/C++ Language Review Prof. Michel A. Kinsy Programming Languages There are many programming languages available: Pascal, C, C++, Java, Ada, Perl and Python All of these languages

More information

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes

More information

Programming in C and C++

Programming in C and C++ Programming in C and C++ 1. Types Variables Expressions & Statements Dr. Anil Madhavapeddy University of Cambridge (based on previous years thanks to Alan Mycroft, Alastair Beresford and Andrew Moore)

More information

Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics

More information

CSE 351 Spring 2017 Final Exam (7 June 2017)

CSE 351 Spring 2017 Final Exam (7 June 2017) CSE 351 Spring 2017 Final Exam (7 June 2017) Please read through the entire examination first! You have 110 minutes for this exam. Don t spend too much time on any one problem! The last page is a reference

More information

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

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger. CS 110 Computer Architecture Lecture 2: Introduction to C, Part I Instructor: Sören Schwertfeger http://shtech.org/courses/ca/ School of Information Science and Technology SIST ShanghaiTech University

More information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don t need to know which register or memory location Provides abstraction of underlying hardware operations

More information

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu Physics 2660: Fundamentals of Scientific Computing Lecture 3 Instructor: Prof. Chris Neu (chris.neu@virginia.edu) Announcements Weekly readings will be assigned and available through the class wiki home

More information

C Programming Review CSC 4320/6320

C Programming Review CSC 4320/6320 C Programming Review CSC 4320/6320 Overview Introduction C program Structure Keywords & C Types Input & Output Arrays Functions Pointers Structures LinkedList Dynamic Memory Allocation Macro Compile &

More information

ET156 Introduction to C Programming

ET156 Introduction to C Programming ET156 Introduction to C Programming Unit 1 INTRODUCTION TO C PROGRAMMING: THE C COMPILER, VARIABLES, MEMORY, INPUT, AND OUTPUT Instructor : Stan Kong Email : skong@itt tech.edutech.edu Figure 1.3 Components

More information

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Announcements Exam 1 (20%): Feb. 27 (Tuesday) Tentative Proposal Deadline:

More information

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

Debugging (Part 1) The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 5 Debugging (Part 1) The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 5 1 For Your Amusement When debugging, novices insert corrective code; experts

More information

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

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with

More information

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4 Beyond this course Readings: CP:AMA 2.1, 15.4 CS 136 Spring 2018 13: Beyond 1 Machine code In Section 04 we briefly discussed compiling: converting source code into machine code so it can be run or executed.

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

C - Basics, Bitwise Operator. Zhaoguo Wang

C - Basics, Bitwise Operator. Zhaoguo Wang C - Basics, Bitwise Operator Zhaoguo Wang Java is the best language!!! NO! C is the best!!!! Languages C Java Python 1972 1995 2000 (2.0) Procedure Object oriented Procedure & object oriented Compiled

More information

Goals of C "" The Goals of C (cont.) "" Goals of this Lecture"" The Design of C: A Rational Reconstruction"

Goals of C  The Goals of C (cont.)  Goals of this Lecture The Design of C: A Rational Reconstruction Goals of this Lecture The Design of C: A Rational Reconstruction Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C Why? Learning

More information