C Fundamentals CGS 3460, Lecture 4 Jan 18, 2006 Hen-I Yang.

Slides:



Advertisements
Similar presentations
Code Composer Department of Electrical and Computer Engineering
Advertisements

Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
I/O: SPARC Assembly Department of Computer Science Georgia State University Georgia State University Updated Spring 2014.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Three types of computer languages
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Introduction to a Programming Environment
Guide To UNIX Using Linux Third Edition
CS 101 Problem Solving and Structured Programming in C Sami Rollins Spring 2003.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
C programming Language and Data Structure For DIT Students.
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANCI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
Introduction COMP104: Fundamentals and Methodology.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
COS120 Software Development Using C++ AUBG Fall semester 2010 Ref book: Problem Solving, Abstraction and Design Using C++ Authors: Frank Friedman, Elliot.
Introduction CS 104: Applied C++ What is Programming? For some given problem: __________ a solution for it -- identify, organize & store the problem's.
©Xiaoying Gao, Peter Andreae First Java Program COMP 102 #2 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
First Java Program COMP 102 #2 2015T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
1 CPSC 185 Introduction to Computing The course home page
Lecture 6: Computer Languages. Programming Environments (IDE) COS120 Software Development Using C++ AUBG, COS dept.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
CGS 3460 Course Web Site –Get CISE Account –Submit via Web Ct –Late Policy –50% Per Day –Missubmission policy –Academic Honesty –Class Scheduling.
Monday, Jan 6, 2003Kate Gregory with material from Deitel and Deitel CO 204 Object Oriented Programming 2003 Trent University Kate Gregory.
Iteration Statements CGS 3460, Lecture 17 Feb 17, 2006 Hen-I Yang.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 05, 2005 Lecture Number: 4.
Introduction to Programming CGS 3460, Lecture 2 Jan 11, 2006 Hen-I Yang.
CS Computer Science I. BCPL was developed in 1967 as a language for writing operating systems and software compilers In 1970, the creators of the.
Introduction 1 (Read Chap. 1) What is Programming? For some given problem: design a solution for it -- identify, organize & store the problem's data --
Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving.
Agenda Computer Languages How to Write a Simple C Program
C Fundamentals CGS 3460, Lecture 5 Jan 20, 2006 Hen-I Yang.
CDA 3100 Fall2009. Special Thanks Thanks to Dr. Xiuwen Liu for letting me use his class slides and other materials as a base for this course.
Summary CGS 3460, Lecture 43 April 26, 2006 Hen-I Yang.
COP3502: Introduction to Computer Science Yashas Shankar Program Translation.
Linked List (II) CGS 3460, Lecture 37 Apr 12, 2006 Hen-I Yang.
The Hashemite University Computer Engineering Department
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
小型系統 心情 vs. 古典樂 心情 vs. 古典樂 浪漫求籤系統 美食導航系統 季潔亭雅鈺熒岱芸 美食導航系統 楊氏音樂模擬大會考人瑋 若維 芷萱 伽倩 楊氏音樂模擬大會考 麥當勞熱量計算系統 火星文困擾你嗎 ? 火星文困擾你嗎 ? 歌詞知多少 - 挑戰你的腦容量英琪 日馨 青雪 鈺娟.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
CMSC 104, Version 8/061L16IncrementalProg.ppt Incremental Programming Topics Review of Incremental Programming Example of Incremental Programming Reading.
Foundations of Computer Science C & C++ programming lecture 2
C Programming.
Introduction to Programming
ICS103 Programming in C Lecture 3: Introduction to C (2)
Lecture2.
Choice of Programming Language
Administrative things
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANSI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
TRANSLATORS AND IDEs Key Revision Points.
Ken D. Nguyen Department of Computer Science Georgia State University
C Programming.
CDA 3100 Spring 2010.
Ken D. Nguyen Department of Computer Science Georgia State University
C Programming.
1.3.7 High- and low-level languages and their translators
Presentation transcript:

C Fundamentals CGS 3460, Lecture 4 Jan 18, 2006 Hen-I Yang

Previously… Machine Code – Assembly – C 3 Steps to a runnable program. + Demo Greetings.c Software Engineering: Implementing a software that solves real problems. Importance of commenting

Administrivia Introducing your TAs. TAs Office Hours (E309)  Gang Tu 6 – 9th periods  Zhen M 5—7th, Th 3 – 5th periods  Xiao Li W 7—8 th, F 5—7th periods Info available on the web site. A new Q&A page has been added.

Administrivia (II) Put [CGS3460] in the subject when sending s related to the course. /questions asked during office hours regarding course related materials may be edited, compiled or modified and posted on the web to help other students learn. The compilation and edition will protect students’ privacy. If you strongly against the discussion being edited, modified or posted, please indicate clearly [DO NOT POST] in your .

Agenda Continue Discussion on “Software Engineering: Implementing a software that solves the problem”. Discuss Vending Machine Exercise.

Cold Pizza Software Engineering: Implementing a software that solves the problem. Importance of commenting.

From Analysis to Executable Problem Analysis (Human Perception) Strategy Forming (Pesudo code) Implementation(High Level Language) Compilation(Assembly Language) Debug Execution(Machine Code) Debug/Testing Example: Greeting Program.

Problem: Write a program that greets the user Step 1: Collect User’s Name Step 2: Print Greeting Message On Screen Name  Collect User’s Name Name  Screen Greetings

#include /** * First sample program of CGS 3460, spring 2006 * Author: Hen-I Yang * Date: Jan 10, 2006 * Version: 1.0 * Note: This program greets the user * Revision: **/ int main() { /* Declare a variable called name to store name collected */ /* Allocate Memory to Record User’s Name Collected */ /* Collect User’s Name (Name  Collect User’s Name) */ /* Print a Greeting Message (Name  Screen) */ return 0; }

#include /** * First sample program of CGS 3460, spring 2006 * Author: Hen-I Yang * Date: Jan 10, 2006 * Version: 1.0 * Note: * Revision: **/ int main() { /* Declare a variable called name to store name collected */ char *name; /* Allocate Memory to Record User’s Name Collected */ name = (char *) malloc (25); /* Collect User’s Name (Name  Collect User’s Name) */ puts ("Please enter your name:"); scanf ("%20s", name); /* Print a Greeting Message (Name  Screen) */ printf ("Hello, %s\n", name); return 0; }

#include int main() { char *name; name = (char *) malloc (25); puts ("Please enter your name:"); scanf ("%20s", name); printf ("\nHello, %s\n", name); return 0; } C Source Code

106fc:9d e3 bf 88 save %sp, -120, %sp 10700: mov 0x19, %o : call 208c : nop 1070c: mov %o0, %g :c2 27 bf ec st %g1, [ %fp ] 10714: sethi %hi(0x10400), %g : f8 or %g1, 0x3f8, %o0! 107f8 1071c: e call 208d : nop 10724: sethi %hi(0x10800), %g : or %g1, 0x10, %o0! c:d2 07 bf ec ld [ %fp ], %o : c call 208e : nop 10738: sethi %hi(0x10800), %g1 1073c: or %g1, 0x18, %o0! :d2 07 bf ec ld [ %fp ], %o : a call 208ec 10748: nop 1074c: clr %g1! :b mov %g1, %i :81 c7 e0 08 ret 10758:81 e restore 1075c:81 c3 e0 08 retl 10760:ae 03 c0 17 add %o7, %l7, %l7 Assembly

106fc:9d e3 bf 88 save %sp, -120, %sp 10700: mov 0x19, %o : call 208c : nop 1070c: mov %o0, %g :c2 27 bf ec st %g1, [ %fp ] 10714: sethi %hi(0x10400), %g : f8 or %g1, 0x3f8, %o0! 107f8 1071c: e call 208d : nop 10724: sethi %hi(0x10800), %g : or %g1, 0x10, %o0! c:d2 07 bf ec ld [ %fp ], %o : c call 208e : nop 10738: sethi %hi(0x10800), %g1 1073c: or %g1, 0x18, %o0! :d2 07 bf ec ld [ %fp ], %o : a call 208ec 10748: nop 1074c: clr %g1! :b mov %g1, %i :81 c7 e0 08 ret 10758:81 e restore 1075c:81 c3 e0 08 retl 10760:ae 03 c0 17 add %o7, %l7, %l7 Machine Code

Hex to Binary Conversion Problem: Given a number in hex(adecimal), convert it to binary representation Get a number in Hex, print out a number in binary Convert to Decimal Divide the number n by 2 k, (k = 3, 2, 1, 0)  if the quote is 1, put down 1, n = n – 2 k  If the quote is 0, put down 0  moves on to the next k

Gatorade Vending Machine Problem: Design a software that can handle transactions of vending machine Strategy: Input1: Nickle, Dime, Quarter (Penny not allowed) Input2: Orange, Blue, Green, Pink, Refund Output: Drink and Change keep receiving Input1 until Input2 is received if ΣInput1 > Input2 then return Input + (ΣInput1 - Input2) else return (“insufficient fund”  screen)

Comments on Comments Programs should be readable by both computer and human Remind yourself what the code does Extremely useful when debugging Important for collaboration Readability

History of C Language Developed in early 1970s. By product of UNIX operating system. (DEC PDP-7) Predecessor: Algol, B, NB 1978, The C Programming Langauge (K&R) Widespread to IBM PC in 80s 1983, ANSI-C C++

Strength/Weakness of C Low-level language (Machine Level, computer’s built-in instruction and fast, Socket, etc) Permissive Flexibility Small, efficient, powerful language, execute and develop fast Standard Library Power Portability Integration with UNIX Too close to machine Error-prone Difficult to understand (many advanced features, terse nature, outdated with minimal interactive, programmers are smarter) Difficult to modify (no module, etc)

Why learn C instead of C++ C++ is much harder to learn Still lots of C code around Not everyone is likely to switch to C++ Still the lowest maintenance for small programs Side Effect avoid learning bad habits

Summary 7 steps from analysis of problem to executable. 3 examples of problem analysis Comments. C trivia. (Chapter 1)

Before you go Make sure you finish reading Chapter 2. Read Chapter 3. Exercises 2.11 and 2.12.