CS 161 Introduction to Programming and Problem Solving Chapter 6 Programming Development Environment Herbert G. Mayer, PSU Status 10/20/2014.

Slides:



Advertisements
Similar presentations
Overview of Programming and Problem Solving ROBERT REAVES.
Advertisements

Processor System Architecture
COSC 120 Computer Programming
Introduction to Computers and Programming - Class 1 1 Introduction to Computers and Programming Professor Avi Rosenfeld.
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Chapter 4 Processor Technology and Architecture. Chapter goals Describe CPU instruction and execution cycles Explain how primitive CPU instructions are.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Topic 1: Introduction to Computers and Programming
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
CS102 Introduction to Computer Programming
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
BLOCK DIAGRAM OF COMPUTER
Chapter 1: Introduction to Visual Basic.NET: Background and Perspective Visual Basic.NET Programming: From Problem Analysis to Program Design.
The Computer Systems By : Prabir Nandi Computer Instructor KV Lumding.
CS 1308 Computer Literacy and the Internet Computer Systems Organization.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
CISC105 General Computer Science Class 1 – 6/5/2006.
Computer Systems Organization CS 1428 Foundations of Computer Science.
1 Overview of Programming and Problem Solving Chapter 1.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Introduction Lecture 01.
Microcode Source: Digital Computer Electronics (Malvino and Brown)
ECE 103 Engineering Programming Chapter 5 Programming Languages Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103.
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
Computer Architecture Memory, Math and Logic. Basic Building Blocks Seen: – Memory – Logic & Math.
1 Text Reference: Warford. 2 Computer Architecture: The design of those aspects of a computer which are visible to the programmer. Architecture Organization.
Electronic Analog Computer Dr. Amin Danial Asham by.
Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving.
Chapter 1 : Overview of Computer and Programming By Suraya Alias
A.Abhari CPS1251 Topic 1: Introduction to Computers Computer Hardware Computer components Connecting Computers Computer Software Operating System (OS)
Computer Systems. Bits Computers represent information as patterns of bits A bit (binary digit) is either 0 or 1 –binary  “two states” true and false,
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
1 Overview of Programming Principles of Computers.
ECE 103 Engineering Programming Chapter 7 Compiling C Programs Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material.
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Computer Operation. Binary Codes CPU operates in binary codes Representation of values in binary codes Instructions to CPU in binary codes Addresses in.
Hello world !!! ASCII representation of hello.c.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
ECE 101 Exploring Electrical Engineering Chapter 9 Programming Development Environment Herbert G. Mayer, PSU Status 3/1/2016.
Operating Systems A Biswas, Dept. of Information Technology.
1 Chapter 1 Basic Structures Of Computers. Computer : Introduction A computer is an electronic machine,devised for performing calculations and controlling.
Chapter 1 Introduction 2nd Semester H
BASIC PROGRAMMING C SCP1103 (02)
The Machine Model Memory
ECE 103 Engineering Programming Chapter 5 Programming Languages
BASIC PROGRAMMING C SCP1103 (02)
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Computer Architecture
IB Computer Science Topic 2.1.1
Introduction to Computers
Compiler Construction
Computer Science I CSC 135.
CSCE Fall 2013 Prof. Jennifer L. Welch.
CSCE 121: Simple Computer Model Spring 2015
Introduction to Computers
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
CSCE Fall 2012 Prof. Jennifer L. Welch.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Introduction to Computer Programming
Introduction to Computer Systems
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

CS 161 Introduction to Programming and Problem Solving Chapter 6 Programming Development Environment Herbert G. Mayer, PSU Status 10/20/2014

Syllabus What is a Program? What is a Computer? Holding Data Programming Languages Machine Language Sample Compiler Linker Loader Debugger Quick Excursion to C++ While Loops in C++

Acknowledgments Numerous graphs and pictures used here have been copied as-is from ECE 103 teaching material developed by professor Phillip Wong at PSU

What is a Program A computer program is a sequence of executable machine instructions, reading information (input), computing new data, and generating output, according to the steps of an algorithm An algorithm is a finite sequence of instructions, reading information (input), computing new data, and generating output The two are almost synonymous, except that the program executes (AKA runs) on a computer, the algorithm is just an abstraction in our mind or written on paper The algorithm coded in a programming language becomes your program

What is a Computer A computer is a physical device that can read input, compute, and produce corresponding output It “understands” a small set of machine instructions, which it can execute, one at a time (for a uni-processor) It is possible, but very tedious, to write a program in such machine instructions An Assembler eases this tediousness by allowing users to write abstract data and symbolic instructions, which the assembler then translates into machine code A compiler (similar: an interpreter) reads higher-level programs and maps them into assembly code; or sometimes into machine code directly

What is a Computer Main Memory (RAM, ROM) Auxiliary Storage (e.g., disk drives) Input (e.g., keyboard, mouse) Output (e.g., monitor, printer) Processor (CPU)

What is a Computer’s Processor? Registers (fast storage) Memory Interface Instruction Decoder To main memory The ALU (Arithmetic Logic Unit) performs basic arithmetic, logic, and comparison operations. ALU

Holding Data A computer holds a good amount of data in memory The size of such a memory (AKA primary storage) is defined by the architecture’s address range E.g. on a 32-bit architecture, memory can be as large as 2 32 different addressable units Often such units are bytes, i.e. 8-bit addressable, contiguous units; other architectures use 60-bit words Large amounts of data are stored on secondary storage devices, such as rotating disks or SSDs Access to data in memory is slow, about times slower than executing one instruction Access to data on disk is even 10,000s of times slower

Holding Data Getting data from memory into the processor (usually a machine register) is called a load operation Moving data from a register to memory is called a store operation Such transport proceeds on a bus; the width of the bus and its speed are critical for the overall execution speed of the machine and thus of your programs

Programming Languages Even writing assembly source code is highly tedious Since the 1960s, higher-level programming languages have been developed Some of these are machine-independent; others highly machine-dependent (AKA architecture- dependent) A machine-independent language allows writing of source programs (code) that can be executed on different machines, provided a compiler is available on each This is referred to a portability of source programs, quite a desirable property!

Programming Language Milestones

1969 to 1973 – C (Bell Labs initial development) 1978 – K&R C (Kernighan and Ritchie) 1989 – C89 (ANSI) 1990 – C90 (ISO) 1995 – C90 Normative Amendment 1 → "C95” 1999 – C99 (ISO) 2011 – C11 (ISO) C Language Milestones

Machine Language Sample 600: A9 5ALDA #$5A; Load accumulator with number 602: 18CLC; Clear carry flag 603: 69 20ADC #$20; Add $20 to accumulator w/carry 605: 8D 00 10STA $1000; Store accumulator at $1000 Assembler translates an assembly program to machine language Assembly language still requires a high level of programmer expertise

Compiler Compiler is a special-purpose system program that reads source programs, written in the source language and translates them into machine language Mapping into machine language (AKA object code) sometimes involves an intermediate step: Creating assembly source first, and then using the assembler to generate machine code A compiler generally understands just one input language; exceptions are some C++ compilers that also read C source Compilers emit error messages when certain violations are detected

Compiler Source files contain the C++ program code .cpp extension (file is in text format); also.c Header files can contain prototypes, macros, data type declarations, or code .h extension (file is in text format) Object files contain intermediate compiled code .o -or-.obj extension Executable files contain runnable binary code .out -or-.exe -or- no extension

Compiler preprocessor → handles preprocessor directives and expands macro definitions compiler → takes preprocessed source code files and translates them to intermediate code; for beginners it is convenient to view the other system programs as part of the compiler assembler → takes intermediate code files and translates them to binary object code linker → resolves references among the object files and the libraries. It puts all the parts together to create the final executable file

16 prog_1.c prog_2.c prog_3.c etc. Source files prog_1.o prog_2.o prog_3.o etc. Object files prog Executable file stdio stdlib math etc. Library files Compiler PreprocessorLinker prog_1.h prog_2.h prog_3.h etc. User Header files stdio.h stdlib.h math.h etc. Library Header files Assembler Compiler

Linker Often programs are composed of multiple source programs For example, some projects are too large to have a single programmer develop all code in sequence Also system function, such as input, output, heap acquisitions etc. are provided in the PDE, and do need to be coded by the programmer All such elements are linked together into a single, executable object program That is the work of the system’s linker For C on Unix the link step is frequently hidden, i.e. not visible to the programmer

Loader When a program has been linked, it is still not executable Instead, it is just a binary file, residing on some disk, as an object file To run such object code, it must be loaded into memory and be granted processor execution time That is the purpose of the system laoder

19 Example: Vintage CPU (1975) MOS 6502 Single core 8-bit data Memory  64 KB main  Registers: Accumulator (A) Index (X, Y) Processor Status (P) Stack Pointer (S) Program Counter (PC) Speed: 1 to 2 MHz Process: 8  m # of transistors: ~3500 Die Shot Pin-out

20 Example: Modern CPU (2013) Intel i Haswell Four cores 64-bit data Memory  4x256 KB L2 cache  8 MB L3 cache  32 GB main (3.2x10 7 KB)  Registers: 8 32-bit bit Integrated GPU Speed: 3.4 GHz (3400 MHz) Process: 22 nm (0.022  m) # of transistors: ~1.4 billion Die Shot Package

Quick Excursion to C++ You now know C++ arrays The type of an array element may be any legal C++ type, including array, in which case you declare multi- dimensional arrays To manipulate arrays, generally you need loops Loops are syntactic constructs that allow the programmer to do steps repetitively We also call this: iteratively Loops iterate over a so called iteration space C++ has while, for, and do loops Here we discuss while loops

While Loop in C++ Formally, there are no while statements, just expressions in C++, we ignore this language politics for the moment A while statement consists of 3 parts: 1. Reserved keyword while 2. A parenthesized expression, interpreted as boolean 3. And 1 statement (formally an expression) Example: while( i < MAX_SIZE ) { process_vector( i++ ): } // end while The single statement may, of course, be a compound statement

While Loop in C++ A while statement executes, as long as the boolean expression in the pair of ( and ) yields true When the expression is false, the while statement ends, and the operation after the while is executed next Usually, some operation in the body of the while –inside the single statement, which may be a compound statement-- must ensure that the boolean condition is false eventually Else you constructed an infinite loop Note that the boolean condition could be false at the start, in which case the wile is empty, i.e. executed 0 times

While Loop in C++ // declaration of some array #define TEN 10 char digits[ TEN ]; // loop to initialize digits[] int i = 0; while ( i < TEN ) { digits[ i ] = ‘0’ + i++; } //end while // no compound needed, but is a good habit

While Loop in C++ // declaration of some array #define TEN 10 char digits[ TEN ]; // loop to print digits[] int i = 0; while ( i < TEN ) { cout<< “digits[“ << i << “]= “ << digits[ i ] << endl; i++; } //end while // no compound needed, but is a good habit