Introduction to Programming

Slides:



Advertisements
Similar presentations
Credit hours: 4 Contact hours: 50 (30 Theory, 20 Lab) Prerequisite: TB143 Introduction to Personal Computers.
Advertisements

Code Composer Department of Electrical and Computer Engineering
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
SPARC Architecture & Assembly Language
I/O: SPARC Assembly Department of Computer Science Georgia State University Georgia State University Updated Spring 2014.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
C Programming for engineers Teaching assistant: Ben Sandbank Home page:
Chapter 7: Subroutines Lecture notes to accompany the text book SPARC Architecture, Assembly Language Programming, and C, by Richard P. Paul, 2 nd edition,
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
CS101- Lecture 11 CS101 Fall 2004 Course Introduction Professor Douglas Moody –Monday – 12:00-1:40 – – –Web Site: websupport1.citytech.cuny.edu.
CS211 Data Structures Sami Rollins Fall 2004.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Boolean Algebra Discrete Mathematics and Its Applications Baojian Hua
Introduction to a Programming Environment
CS 101 Problem Solving and Structured Programming in C Sami Rollins Spring 2003.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
CS1430: Programming in C++ Section 2 Instructor: Qi Yang 213 Ullrich
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
Introduction CS 104: Applied C++ What is Programming? For some given problem: __________ a solution for it -- identify, organize & store the problem's.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 Agenda Administration Background Our first C program Working environment Exercise Memory and Variables.
ITEC 352 Lecture 18 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Exam –Average 76 Methods for functions in assembly.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 3 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Monday, Jan 6, 2003Kate Gregory with material from Deitel and Deitel CO 204 Object Oriented Programming 2003 Trent University Kate Gregory.
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.
1 CS1430: Programming in C++ Section 2 Instructor: Qi Yang 213 Ullrich
C Fundamentals CGS 3460, Lecture 5 Jan 20, 2006 Hen-I Yang.
CMSC 2021 CMSC 202 Computer Science II for Majors Spring 2001 Sections Ms. Susan Mitchell.
Buffer Overflow Attack- proofing of Code Binaries Ramya Reguramalingam Gopal Gupta Gopal Gupta Department of Computer Science University of Texas at Dallas.
COP3502: Introduction to Computer Science Yashas Shankar Program Translation.
The Hashemite University Computer Engineering Department
Agenda  Take up homework  Loops - Continued –For loops Structure / Example involving a for loop  Storing Characters in variables  Introduction to Functions.
C Fundamentals CGS 3460, Lecture 4 Jan 18, 2006 Hen-I Yang.
Dr. Sajib Datta Jan 15,  Instructor: Sajib Datta ◦ Office Location: ERB 336 ◦ Address: ◦ Web Site:
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
COP3502: Introduction to Computer Science Yashas Shankar Program Translation.
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
ECE Application Programming
C Programming.
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
CSE1320 INTERMEDIATE PROGRAMMING
Lecture2.
Choice of Programming Language
CSE1320 INTERMEDIATE PROGRAMMING
Administrative things
TRANSLATORS AND IDEs Key Revision Points.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Ken D. Nguyen Department of Computer Science Georgia State University
Introduction to CS Your First C Programs
C Programming.
CSCE 206 Lab Structured Programming in C
CDA 3100 Spring 2010.
CSE1320 INTERMEDIATE PROGRAMMING
CSE1320 INTERMEDIATE PROGRAMMING
Microprocessor and Assembly Language
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Ken D. Nguyen Department of Computer Science Georgia State University
EECE.2160 ECE Application Programming
C Programming.
CSCE 206 Lab Structured Programming in C
CS113 Introduction to C Instructor: Hubie Chen Web:
EECE.2160 ECE Application Programming
Introduction to C Programming
Presentation transcript:

Introduction to Programming CGS 3460, Lecture 3 Jan 13, 2006 Hen-I Yang

Previously… Introduction to Computer Writing your own program gives the total control of what your computer can do for you. Introduction to Binary – Decimal – Hex conversions

Administrivia Turn in your questionnaire if you have not done so. Course material is updated on the course web site. My office hour will be temporarily hold in E309, effective today. TA’s office hour schedule will be announced next Wednesday. Comments on your responses to the questionnaire.

Agenda Machine Code – Assembly – C 3 Steps to a runnable program. Software Engineering: Implementing a software that solves the problem. Importance of commenting.

Machine Code 106fc: 9d e3 bf 88 save %sp, -120, %sp 10700: 90 10 20 19 mov 0x19, %o0 10704: 40 00 40 71 call 208c8 <_PROCEDURE_LINKAGE_TABLE_+0x78> 10708: 01 00 00 00 nop 1070c: 82 10 00 08 mov %o0, %g1 10710: c2 27 bf ec st %g1, [ %fp + -20 ] 10714: 03 00 00 41 sethi %hi(0x10400), %g1 10718: 90 10 63 f8 or %g1, 0x3f8, %o0 ! 107f8 <_lib_version+0x8> 1071c: 40 00 40 6e call 208d4 <_PROCEDURE_LINKAGE_TABLE_+0x84> 10720: 01 00 00 00 nop 10724: 03 00 00 42 sethi %hi(0x10800), %g1 10728: 90 10 60 10 or %g1, 0x10, %o0 ! 10810 <_lib_version+0x20> 1072c: d2 07 bf ec ld [ %fp + -20 ], %o1 10730: 40 00 40 6c call 208e0 <_PROCEDURE_LINKAGE_TABLE_+0x90> 10734: 01 00 00 00 nop 10738: 03 00 00 42 sethi %hi(0x10800), %g1 1073c: 90 10 60 18 or %g1, 0x18, %o0 ! 10818 <_lib_version+0x28> 10740: d2 07 bf ec ld [ %fp + -20 ], %o1 10744: 40 00 40 6a call 208ec <_PROCEDURE_LINKAGE_TABLE_+0x9c> 10748: 01 00 00 00 nop 1074c: 82 10 20 00 clr %g1 ! 0 <_START_-0x10000> 10750: b0 10 00 01 mov %g1, %i0 10754: 81 c7 e0 08 ret 10758: 81 e8 00 00 restore 1075c: 81 c3 e0 08 retl 10760: ae 03 c0 17 add %o7, %l7, %l7 1001 1101 1110 0011 Does any one uses Hex? Who uses

Assembly 106fc: 9d e3 bf 88 save %sp, -120, %sp 10700: 90 10 20 19 mov 0x19, %o0 10704: 40 00 40 71 call 208c8 <_PROCEDURE_LINKAGE_TABLE_+0x78> 10708: 01 00 00 00 nop 1070c: 82 10 00 08 mov %o0, %g1 10710: c2 27 bf ec st %g1, [ %fp + -20 ] 10714: 03 00 00 41 sethi %hi(0x10400), %g1 10718: 90 10 63 f8 or %g1, 0x3f8, %o0 ! 107f8 <_lib_version+0x8> 1071c: 40 00 40 6e call 208d4 <_PROCEDURE_LINKAGE_TABLE_+0x84> 10720: 01 00 00 00 nop 10724: 03 00 00 42 sethi %hi(0x10800), %g1 10728: 90 10 60 10 or %g1, 0x10, %o0 ! 10810 <_lib_version+0x20> 1072c: d2 07 bf ec ld [ %fp + -20 ], %o1 10730: 40 00 40 6c call 208e0 <_PROCEDURE_LINKAGE_TABLE_+0x90> 10734: 01 00 00 00 nop 10738: 03 00 00 42 sethi %hi(0x10800), %g1 1073c: 90 10 60 18 or %g1, 0x18, %o0 ! 10818 <_lib_version+0x28> 10740: d2 07 bf ec ld [ %fp + -20 ], %o1 10744: 40 00 40 6a call 208ec <_PROCEDURE_LINKAGE_TABLE_+0x9c> 10748: 01 00 00 00 nop 1074c: 82 10 20 00 clr %g1 ! 0 <_START_-0x10000> 10750: b0 10 00 01 mov %g1, %i0 10754: 81 c7 e0 08 ret 10758: 81 e8 00 00 restore 1075c: 81 c3 e0 08 retl 10760: ae 03 c0 17 add %o7, %l7, %l7

106fc: 9d e3 bf 88 save %sp, -120, %sp 10700: 90 10 20 19 mov 0x19, %o0 10704: 40 00 40 71 call 208c8 <_PROCEDURE_LINKAGE_TABLE_+0x78> 10708: 01 00 00 00 nop 1070c: 82 10 00 08 mov %o0, %g1 10710: c2 27 bf ec st %g1, [ %fp + -20 ] 10714: 03 00 00 41 sethi %hi(0x10400), %g1 10718: 90 10 63 f8 or %g1, 0x3f8, %o0 ! 107f8 <_lib_version+0x8> 1071c: 40 00 40 6e call 208d4 <_PROCEDURE_LINKAGE_TABLE_+0x84> 10720: 01 00 00 00 nop 10724: 03 00 00 42 sethi %hi(0x10800), %g1 10728: 90 10 60 10 or %g1, 0x10, %o0 ! 10810 <_lib_version+0x20> 1072c: d2 07 bf ec ld [ %fp + -20 ], %o1 10730: 40 00 40 6c call 208e0 <_PROCEDURE_LINKAGE_TABLE_+0x90> 10734: 01 00 00 00 nop 10738: 03 00 00 42 sethi %hi(0x10800), %g1 1073c: 90 10 60 18 or %g1, 0x18, %o0 ! 10818 <_lib_version+0x28> 10740: d2 07 bf ec ld [ %fp + -20 ], %o1 10744: 40 00 40 6a call 208ec <_PROCEDURE_LINKAGE_TABLE_+0x9c> 10748: 01 00 00 00 nop 1074c: 82 10 20 00 clr %g1 ! 0 <_START_-0x10000> 10750: b0 10 00 01 mov %g1, %i0 10754: 81 c7 e0 08 ret 10758: 81 e8 00 00 restore 1075c: 81 c3 e0 08 retl 10760: ae 03 c0 17 add %o7, %l7, %l7

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

3 Steps To Runnable Program Source file (.c) Editor: The tool you use to edit your source code. Object file (.o) Compiler + other utilities: The tool computer runs to create object file and executables. Executables The end product that actually delivers what you coded. Demo HD, memory, CPU

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. Compile/Interpret

Greetings 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

#include <stdio.h> /** * 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 <stdio.h> /** * 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; }

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

Assembly 106fc: 9d e3 bf 88 save %sp, -120, %sp 10700: 90 10 20 19 mov 0x19, %o0 10704: 40 00 40 71 call 208c8 <_PROCEDURE_LINKAGE_TABLE_+0x78> 10708: 01 00 00 00 nop 1070c: 82 10 00 08 mov %o0, %g1 10710: c2 27 bf ec st %g1, [ %fp + -20 ] 10714: 03 00 00 41 sethi %hi(0x10400), %g1 10718: 90 10 63 f8 or %g1, 0x3f8, %o0 ! 107f8 <_lib_version+0x8> 1071c: 40 00 40 6e call 208d4 <_PROCEDURE_LINKAGE_TABLE_+0x84> 10720: 01 00 00 00 nop 10724: 03 00 00 42 sethi %hi(0x10800), %g1 10728: 90 10 60 10 or %g1, 0x10, %o0 ! 10810 <_lib_version+0x20> 1072c: d2 07 bf ec ld [ %fp + -20 ], %o1 10730: 40 00 40 6c call 208e0 <_PROCEDURE_LINKAGE_TABLE_+0x90> 10734: 01 00 00 00 nop 10738: 03 00 00 42 sethi %hi(0x10800), %g1 1073c: 90 10 60 18 or %g1, 0x18, %o0 ! 10818 <_lib_version+0x28> 10740: d2 07 bf ec ld [ %fp + -20 ], %o1 10744: 40 00 40 6a call 208ec <_PROCEDURE_LINKAGE_TABLE_+0x9c> 10748: 01 00 00 00 nop 1074c: 82 10 20 00 clr %g1 ! 0 <_START_-0x10000> 10750: b0 10 00 01 mov %g1, %i0 10754: 81 c7 e0 08 ret 10758: 81 e8 00 00 restore 1075c: 81 c3 e0 08 retl 10760: ae 03 c0 17 add %o7, %l7, %l7

Machine Code 106fc: 9d e3 bf 88 save %sp, -120, %sp 10700: 90 10 20 19 mov 0x19, %o0 10704: 40 00 40 71 call 208c8 <_PROCEDURE_LINKAGE_TABLE_+0x78> 10708: 01 00 00 00 nop 1070c: 82 10 00 08 mov %o0, %g1 10710: c2 27 bf ec st %g1, [ %fp + -20 ] 10714: 03 00 00 41 sethi %hi(0x10400), %g1 10718: 90 10 63 f8 or %g1, 0x3f8, %o0 ! 107f8 <_lib_version+0x8> 1071c: 40 00 40 6e call 208d4 <_PROCEDURE_LINKAGE_TABLE_+0x84> 10720: 01 00 00 00 nop 10724: 03 00 00 42 sethi %hi(0x10800), %g1 10728: 90 10 60 10 or %g1, 0x10, %o0 ! 10810 <_lib_version+0x20> 1072c: d2 07 bf ec ld [ %fp + -20 ], %o1 10730: 40 00 40 6c call 208e0 <_PROCEDURE_LINKAGE_TABLE_+0x90> 10734: 01 00 00 00 nop 10738: 03 00 00 42 sethi %hi(0x10800), %g1 1073c: 90 10 60 18 or %g1, 0x18, %o0 ! 10818 <_lib_version+0x28> 10740: d2 07 bf ec ld [ %fp + -20 ], %o1 10744: 40 00 40 6a call 208ec <_PROCEDURE_LINKAGE_TABLE_+0x9c> 10748: 01 00 00 00 nop 1074c: 82 10 20 00 clr %g1 ! 0 <_START_-0x10000> 10750: b0 10 00 01 mov %g1, %i0 10754: 81 c7 e0 08 ret 10758: 81 e8 00 00 restore 1075c: 81 c3 e0 08 retl 10760: ae 03 c0 17 add %o7, %l7, %l7

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 2k, (k = 3, 2, 1, 0) if the quote is 1, put down 1, n = n – 2k If the quote is 0, put down 0 moves on to the next k

Sorting Problem: A stack of graded exam papers, sort them from the highest score to the lowest Pick the one from the top of the pile, put it down Pick the next one, if the score is higher, put it on top Otherwise, flip the paper and see if the score is higher than the next one If it’s higher than insert it to the slot If not, keep flipping through to the next page If it’s to the bottom of the sorted pile, put it down on the back

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

Summary What is a program? Different Formats of a program. 3 steps to a runnable program. 7 steps from analysis of problem to executable. Comments.

Before you go Read Chapter 1 and Section 2.1 – 2.2. Problem: design a software for Gatorade vending machine.