What s next. Computer Systems A Programmer s Perspective

Similar documents
CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

Great Reality #2: You ve Got to Know Assembly Does not generate random values Arithmetic operations have important mathematical properties

Chris Riesbeck, Fall Introduction to Computer Systems

Computer Systems: A Programmer s Perspec4ve. Have a tour of computer system at first... Chapter 1

Introduction Presentation A

Introduction to Computer Systems

Introduction to Computer Systems

M2 Instruction Set Architecture

Introduction to Computer Systems

EL2310 Scientific Programming

ENCE Computer Organization and Architecture. Chapter 1. Software Perspective

EL2310 Scientific Programming

by Pearson Education, Inc. All Rights Reserved.

Computer Organization - Overview

A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp)

Reviewing gcc, make, gdb, and Linux Editors 1

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

#include <stdio.h> int main() { printf ("hello class\n"); return 0; }

CS Programming In C

CS354 gdb Tutorial Written by Chris Feilbach

ABSTRACTION ISN T THE ENTIRE STORY

UNIX Makefile. C Project Library Distribution and Installation.

Notes By: Shailesh Bdr. Pandey, TA, Computer Engineering Department, Nepal Engineering College

LC-3 Assembly Language

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Computer Systems Organization

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

PRINCIPLES OF OPERATING SYSTEMS

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

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

CS Basics 15) Compiling a C prog.

Introduction to Computer Systems

Introduction to Computer Systems

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

Topic 6: A Quick Intro To C

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

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

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

A Fast Review of C Essentials Part II

independent compilation and Make

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

Bilgisayar Sistemlerine Genel Bakış

We first learn one useful option of gcc. Copy the following C source file to your

Computers and Computation. The Modern Computer. The Operating System. The Operating System

CMPSC 311- Introduction to Systems Programming Module: Build Processing

INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE

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

CSC 2400: Computer Systems. Key to Success

Introduction to Linux

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

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

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

Course Information and Introduction

Lecture 1: Course Overview

Programming 1. Lecture 1 COP 3014 Fall August 28, 2017

Maemo Diablo GNU Make and makefiles Training Material

C: Program Structure. Department of Computer Science College of Engineering Boise State University. September 11, /13

CSCI341. Lecture 22, MIPS Programming: Directives, Linkers, Loaders, Memory

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Definition: An operating system is the software that manages resources

CS11001/CS11002 Programming and Data Structures Autumn/Spring Semesters. Introduction

CptS 360 (System Programming) Unit 1: Introduction to System Programming

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

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science

Lab 1 Introduction to UNIX and C

CSCI2467: Systems Programming Concepts

13-2 EE 4770 Lecture Transparency. Formatted 8:18, 13 March 1998 from lsli

Have examined process Creating program Have developed program Written in C Source code

Programming. Data Structure

CS 1713 Introduction to Computer Programming II Ch 0 Overview - Problem solving

CptS 360 (System Programming) Unit 2: Introduction to UNIX and Linux

Problem Set 1: Unix Commands 1

2 Compiling a C program

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

A Tour of Computer Systems

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

CMPSC 311- Introduction to Systems Programming Module: Build Processing

Debugging. ICS312 Machine-Level and Systems Programming. Henri Casanova

CSC258: Computer Organization. Functions and the Compiler Tool Chain

CS11002 Programming and Data Structures Spring Introduction

Introduction to C Programming

PROGRAMMAZIONE I A.A. 2017/2018

Chapter 11 Introduction to Programming in C

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

CS19001/CS19002 Programming and Data Structures Lab Autumn/Spring Semester. Introduction. Abhijit Das. January 4, 2015

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

Intermediate Programming, Spring Misha Kazhdan

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Programming Languages: Part 1. Robert M. Dondero, Ph.D. Princeton University

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

Compilation, Disassembly, and Profiling (in Linux)

Computer System: An Overview

CSCI 2132 Software Development. Lecture 8: Introduction to C

Programming 1 - Honors

Systems Programming. Fatih Kesgin &Yusuf Yaslan Istanbul Technical University Computer Engineering Department 18/10/2005

Laboratory 1 Semester 1 11/12

CMPE-013/L. Introduction to C Programming

Chapter 11 Introduction to Programming in C

Lecture 2: C Programm

CSE 4/521 Introduction to Operating Systems

Transcription:

What s next Computer Systems A Programmer s Perspective 198

The role of the operating system Protect the computer from misuse Provide an abstraction for using the hardware so that programs can be written for a variety of different hardware Manage the resources to allow for reasonable use by all users and programs on a computer 199

The UNIX Operating System Developed in 1970s at Bell Labs Kernel written in C, also developed at the same time C was developed for the purpose of writing UNIX and systems programming We are using a variant of UNIX named Linux Other UNIX variants exist, such as Solaris, and the various BSDs (OpenBSD, NetBSD, FreeBSD, OSX) 200

Text/Ascii A file is a sequence of bytes - not a magical container holding the bytes, but the bytes themselves How this information is treated depends on the context the same sequence of bits can be used to represent a character, or an integer, or a floatingpoint number, or an instruction, or... It's all a matter of interpretation % emacs hellob.c & 201

Why assembly language? Instruction based execution Each program on a computer is a sequence of instructions written in machine language Processor executes one instruction at a time in a program, then executes the next one in turn To study code in this form, it's helpful to use assembly language rather than machine language code gcc S hellob.c 202

Assembly language really?! Chances are, you ll never write programs in assembly Compilers are much better & more patient than you are But: Understanding assembly is key to machine-level execution model Behavior of programs in presence of bugs High-level language models break down Tuning program performance Understand optimizations done / not done by the compiler Understanding sources of program inefficiency Implementing system software Compiler has machine code as target Operating systems must manage process state Creating / fighting malware x86 assembly is the language of choice! 203

Declarations and the Preprocessor #include provides ability to include declarations from other files usually have the file name extension.h generally only include function prototypes, and type and variable declarations actual code is kept in a different file, usually with the extension.c files with code are compiled individually to object code and then linked together to create a file with executable code Two ways to use #include #include <stdio.h> for standard system files #include "swap.h for user-written files Very rarely/never #include a.c file 204

The compilation system revisited hello.c %gcc -o hello hello.c Type in program using an editor of your choice (file.c); plain text.c +.h =.i which is the ultimate source code? i.e. # includes expanded and #defines replaced.i.s which is assembler source code.s.o which is an object file; fragments of machine code with unresolved symbols i.e. some addresses not yet known (vars/subrs). hello.o + library links a.out (default name); resolves symbols, generates an executable. %hello 205

Compiling a C program C programs must be compiled to be executed Use the gcc program to build your programs invocation: gcc options source-files common options -ansi enforces the ansi standards -g enable debugging -Wall warn about common things that may be problems -Werror treat warnings as errors -o filename place output in filename -c only compile to object file, don't link (.o file created) -S generate assembly code, don t link (.s file created) a very simple compilation command gcc file.c a simple compilation command gcc -g -Wall Werror ansi -o prog1 prog1.c tools.c executable is run in UNIX by just typing its name (sometimes preceded by "./", like this:./prog1) 206

Compilation stages Preprocessor used to make sure the program parts see declarations they need (and other purposes too, e.g., macros) directives begin with a # (pound sign) do not end in a ; like C statements do Translation makes sure individual parts are consistent within themselves creates an object (.o) file Linking joins one or more compiled object files together includes matching function call to callee across separate files and matching global variable use to where it s defined makes sure caller/callee consistent with each other creates an executable file (the convention in Unix is no filename extension is used for executable files, although sometimes.x or.exe are used) 207

Hardware Organization (big picture) Register File hellob executable stored on disk* PC ALU System bus Memory bus Expansion slots for other devices such as network adapters, video cards, etc. Bus Interface I/O bridge Main memory I/O bus USB controller Mouse Keyboard Graphics adapter Display Disk Controller Disk* 208