Computer Systems DV1 (1DT151) Operating Systems (1DT020) Cary Laxer, Ph.D. Visiting Lecturer.

Slides:



Advertisements
Similar presentations
CPU Structure and Function
Advertisements

C Intro.
Computer Organization and Architecture
Computer System Overview
Computer Organization and Architecture
Computer Organization and Architecture
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
Lecture 2 Introduction to C Programming
Informationsteknologi Thursday, September 6, 2007Computer Systems/Operating Systems - Class 21 Today’s class Finish computer system overview Review of.
Computer Architecture I (1DT016) Cary Laxer, Ph.D. Visiting Lecturer.
Chapter 1 Computer System Overview Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
COSC 120 Computer Programming
1 Lecture 2: Review of Computer Organization Operating System Spring 2007.
1 CSSE 332 Course Introduction. Roll Call and Introductions Name (nickname) Name (nickname) Hometown Hometown Local Residence Local Residence Major Major.
1 CSSE 332 Preprocessor, Array and Strings. 2 External library files libname.a or libname.so Special functionality is provided in the form of external.
Computer System Overview
1 Computer System Overview OS-1 Course AA
1 CSIT431 Introduction to Operating Systems Welcome to CSIT431 Introduction to Operating Systems In this course we learn about the design and structure.
Computer System Overview
Informationsteknologi Monday, September 10, 2007Computer Systems/Operating Systems - Class 31 Today’s class Review of more C Operating system overview.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Adapted from slides ©2005 Silberschatz, Galvin, and Gagne and Stallings Lecture 2: Computer Systems Overview.
CSSE221: Software Dev. Honors Day 28 Announcements Announcements Simulation grades coming back Simulation grades coming back All C Projects due Friday.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Computer System Overview Chapter 1. Basic computer structure CPU Memory memory bus I/O bus diskNet interface.
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
Chapter 1 Computer System Overview Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
Computer Systems Overview. Page 2 W. Stallings: Operating Systems: Internals and Design, ©2001 Operating System Exploits the hardware resources of one.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Computer System Overview Chapter 1. Operating System Exploits the hardware resources of one or more processors Provides a set of services to system users.
Chapter 1 Computer System Overview Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Operating Systems and Networks AE4B33OSS Introduction.
Programming With C.
Ihr Logo Operating Systems Internals & Design Principles Fifth Edition William Stallings Chapter 1 Computer System Overview.
OPERATING SYSTEMS Goals of the course Definitions of operating systems Operating system goals What is not an operating system Computer architecture O/S.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Operating System Isfahan University of Technology Note: most of the slides used in this course are derived from those of the textbook (see slide 4)
Stored Program A stored-program digital computer is one that keeps its programmed instructions, as well as its data, in read-write,
COMPUTER ORGANIZATION AND ASSEMBLY LANGUAGE Lecture 21 & 22 Processor Organization Register Organization Course Instructor: Engr. Aisha Danish.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Lecture 1: Review of Computer Organization
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
1 Computer Architecture. 2 Basic Elements Processor Main Memory –volatile –referred to as real memory or primary memory I/O modules –secondary memory.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Hello world !!! ASCII representation of hello.c.
Chapter 1 Computer System Overview Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Operating Systems A Biswas, Dept. of Information Technology.
Computer Systems Overview. Lecture 1/Page 2AE4B33OSS W. Stallings: Operating Systems: Internals and Design, ©2001 Operating System Exploits the hardware.
1 Computer System Overview Chapter 1. 2 Operating System Exploits the hardware resources of one or more processors Provides a set of services to system.
Day 01 Introduction to C.
Chapter 1 Computer System Overview
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 - Introduction to C Programming
Day 02 Introduction to C.
Day 01 Introduction to Linux and C
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Programming Fundamentals Lecture #3 Overview of Computer Programming
Chapter 1 Computer System Overview
Computer System Overview
Introduction to C Programming
Presentation transcript:

Computer Systems DV1 (1DT151) Operating Systems (1DT020) Cary Laxer, Ph.D. Visiting Lecturer

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 12 Today’s class Introductions Review of some C Computer system overview

Introductions

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 14 Instructor Cary Laxer Visiting lecturer Home institution is Rose-Hulman Institute of Technology, Terre Haute, Indiana, USA Professor and Head of Computer Science and Software Engineering Bachelor’s degree in computer science and mathematics from New York University Ph.D. in biomedical engineering from Duke University

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 15 Lab instructor John Håkansson Ph.D. student in the department M.Sc. in 2000 Industry experience writing C compilers for embedded systems and as a robot programmer Has assisted teaching this course before

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 16 Course Information is maintained on the course website: lecture meetings and 4 lab meetings Text is Operating Systems: Internals and Design Principles (Fifth Edition) by William Stallings We will cover chapters 1-10, 12, and 16 I will try to have some in-class exercises to help reinforce the material and to break up the long lecture periods

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 17 Introduce yourselves Tell us:  Your name  Your hometown  Your computer background  Something interesting about yourself

Review of C

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 19 Why learn C? The good…  Both a high-level and a low-level language  Better control of low-level mechanisms  Performance better than Java  Java hides many details needed for writing OS code And the bad…  Memory management responsibility is yours  Explicit initialization and error detection  More room for mistakes

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 110 Goals of this review To review (introduce if you are new to C) some basic C concepts to you  so that you can read further details on your own To warn you about common mistakes made by beginners

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 111 Creating an executable Source:

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 112 Types of files C source files (.c) C header files (.h) Object files (.o) Executable files (typically no extension – by default : a.out) Library files (.a or.so)

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 113 Example 1 #include //#include “myheader.h” int main() { printf(“Hello World. \n \t and you ! \n ”); /* print out a message */ return 0; }

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 114 Summarizing the Example #include = include header file stdio.h  No semicolon at end  Small letters only – C is case-sensitive int main(){ … } is the only code executed printf(“ /* message you want printed */ ”); \n = newline \t = tab \ in front of other special characters within printf creates “escape sequences”.  printf(“Have you heard of \”The Rock\” ? \n”);

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 115 Compiling and running >gcc ex1.c (Creates a.out) >./a.out (Runs the executable) >gcc ex1.c –o ex1 (Creates ex1 not a.out) >./ex1

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 116 External library files libname.a or libname.so Special functionality is provided in the form of external libraries of ready-made functions Ready-compiled code that the compiler merges, or links, with a C program during compilation For example, libraries of mathematical functions, string handling functions, and input/output functions Look for the library files under /usr/lib and header files under /usr/include

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 117 External library files libname.a or libname.so To compile, use flag “l” and name i.e. –lname. To compile, use flag “l” and name i.e. –lname. eg. gcc –o test test.c –lm where “m” in “lm” comes from libm.so i.e. the math library..a libraries are static – code is included in the executable program.a libraries are static – code is included in the executable program.so libraries are dynamic – code is not in the executable program; the system copy is used at run time.so libraries are dynamic – code is not in the executable program; the system copy is used at run time

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 118 Using external library files To use the library files, you must always do two things:  link the library with a -l option to gcc  include the library header files

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 119 Pre-processor directives A preprocessor is a program that examines C code before it is compiled and manipulates it in various ways. Two main functions  To include external files using #include  To define macros (names that are expanded by the preprocessor into pieces of text or C code) using #define

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 120 Example of pre-processor directives Example 2: #include #define STRING1 "A macro definition\n" #define STRING2 "must be all on one line!\n" #define EXPRESSION #define EXPRESSION2 EXPRESSION #define ABS(x) ((x) < 0) ? -(x) : (x) #define MAX(a,b) (a < b) ? (b) : (a) #define BIGGEST(a,b,c) (MAX(a,b) < c) ? (c) : (MAX(a,b)) int main () { printf (STRING1); printf (STRING2); printf ("%d\n", EXPRESSION1); printf ("%d\n", EXPRESSION2); printf ("%d\n", ABS(-5)); printf ("Biggest of 1, 2, and 3 is %d\n", BIGGEST(1,2,3)); return 0; }

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 121 #define The expression is NOT evaluated when it replaces the macro in the pre-processing stage. Evaluation takes place only during the execution phase.

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 122 Simple Data Types Data Type # bytes (typical) Shorthand int4%d %i char1%c float4%f double8%lf long4%l short2%i String - %s address - %p(HEX) or %u (unsigned int)

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 123 Example 3 #include int main() { int nstudents = 0; /* Initialization, required */ float age = ; printf(“How many students does Uppsala University have ?”); scanf (“%d”, &nstudents); /* Read input */ printf(“Uppsala University has %d students.\n”, nstudents); printf(“The average age of the students is %3.1f\n”,age); //3.1 => width.precision return 0; } >./ex3 How many students does Uppsala University have ?: 2000 (enter) Uppsala University has 2000 students. The average age of the students is 21.5 >

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 124 If you are familiar with Java… Operators same as Java:  Arithmetic  int i = i+1; i++; i--; i *= 2;  +, -, *, /, %  Relational and Logical , =, ==, !=  &&, ||, &, |, ! Syntax same as in Java:  if ( ) { } else { }  while ( ) { }  do { } while ( );  for (i=1; i <= 100; i++) { }  switch ( ) {case 1: … }  continue; break;

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 125 Example 4 #include #define DANGERLEVEL 5 /* C Preprocessor - - substitution on appearance */ int main() { float level=1; if (level <= DANGERLEVEL){ /*replaced by 5*/ printf(“Low on gas!\n”); } else printf(“On my way !\n”); return 0; }

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 126 One-Dimensional Arrays Example 5: #include int main() { int number[12]; /* 12 numbers*/ int index, sum = 0; /* Always initialize array before use */ for (index = 0; index < 12; index++) { number[index] = index; } /* now, number[index]=index; will cause error:why ?*/ for (index = 0; index < 12; index = index + 1) { sum += number[index]; /* sum array elements */ } return 0; }

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 127 More arrays - Strings char name[10]; //declaration name = {‘A’,’l’,’i’,’c’,’e’,’\0’}; //initialization /* ’\0’= end of string */ char name [] = “Alice”; //declaration and initialization char name [] = {‘A’,’l’,’i’,’c’,’e’,’\0’}; // ditto scanf(“%s”,name); //Initialization // ERROR: scanf(“%s”,&name); printf(“%s”, name); /* print until ‘\0’ *

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 128 Strings continued Functions to operate on strings  strcpy, strncpy, strcmp, strncmp, strcat, strncat, substr, strlen,strtok  #include or at program start CAUTION: C allows strings of any length to be stored. Characters beyond the end of the array will overwrite data in memory following the array.

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 129 Multi-dimensional arrays int points[3][4]; int points[3][4]; points [1][3] = 12; /* NOT points[3,4] */ points [1][3] = 12; /* NOT points[3,4] */ printf(“%d”, points[1][3]); printf(“%d”, points[1][3]);

Computer system overview

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 131 Operating System Exploits the hardware resources of one or more processors Provides a set of services to system users Manages secondary memory and I/O devices

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 132 Basic Elements Processor Main Memory  volatile  referred to as real memory or primary memory I/O modules  secondary memory devices  communications equipment  terminals System bus  communication among processors, memory, and I/O modules

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 133 Processor Two internal registers  Memory address register (MAR)  Specifies the address for the next read or write  Memory buffer register (MBR)  Contains data written into memory or receives data read from memory  I/O address register  I/O buffer register

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 134 Top-Level Components

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 135 Processor Registers User-visible registers  Enable programmer to minimize main- memory references by optimizing register use Control and status registers  Used by processor to control operating of the processor  Used by privileged operating-system routines to control the execution of programs

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 136 User-Visible Registers May be referenced by machine language Available to all programs - application programs and system programs Types of registers  Data  Address  Index  Segment pointer  Stack pointer

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 137 User-Visible Registers Address Registers  Index  Involves adding an index to a base value to get an address  Segment pointer  When memory is divided into segments, memory is referenced by a segment and an offset  Stack pointer  Points to top of stack

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 138 Control and Status Registers Program Counter (PC)  Contains the address of an instruction to be fetched Instruction Register (IR)  Contains the instruction most recently fetched Program Status Word (PSW)  Condition codes  Interrupt enable/disable  Supervisor/user mode

Informationsteknologi Monday, September 3, 2007Computer Systems/Operating Systems - Class 139 Control and Status Registers Condition Codes or Flags  Bits set by the processor hardware as a result of operations  Examples  Positive result  Negative result  Zero  Overflow