Chapter 11-12, Appendix D C Programs Higher Level languages Compilers C programming Converting C to Machine Code C Compiler for LC-3.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
1 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d",
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Chapter 11-14, Appendix D C Programs Higher Level languages Compilers C programming Converting C to Machine Code C Compiler for LC-3 Please return breadboards.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Chapter 11-12, Appendix D C Programs Higher Level languages Compilers C programming Converting C to Machine Code C Compiler for LC-3.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
C Stack Frames / Pointer variables Stack: Local Variables Pass & Return values Frame Ptr linkage (R5) and PC linkage (R7) Pointer Variables: Defining &
Computer Science 210 Computer Organization Pointers.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Computer Science 210 Computer Organization Introduction to C.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Chapter 11 Programming in C Compilation vs. Interpretation Different ways of translating high-level language Compilation translates code into machine.
Programming With C.
Chapter 11 Introduction to Programming in C. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Compilation.
#include int main(void) { printf("Hello, world!\n"); return 0; } entry point called on program start only one main( ) in any program # for preprocessor.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Introduction Chapter 1 1/22/16. Check zyBooks Completion Click on the boxes for each section.
1 CS 416- Fall 2008 Session 02 TA: Tuan Phan (ext 9644) : Just leaving msg( prefer using ,
C Programming Chapters 11, . . .
First Compilation Rudra Dutta CSC Spring 2007, Section 001.
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
CMPE13Cyrus Bazeghi 1 Chapter 11 Introduction to Programming in C.
A.Abhari CPS1251 Topic 2: C Overview C Language Elements Variable Declaration and Data Types Statement Execution C Program Layout Formatting Output Interactive.
POINTERS IN C Pointer Basics, Pointer Arithmetic, Pointer to arrays and Pointer in functions.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
C is a high level language (HLL)
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Hello world !!! ASCII representation of hello.c.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
C Language Elements Preprocessor Directives # (sign for preprocessor directive commands) #include Standard header file (.h) Library.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Introduction To Software Development Environment.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Dynamic memory allocation and Intraprogram Communication.
Basic C programming Convert C program statements to LC-3 Cache (how to bridge the speed gap between memory and CPU) Virtual memory (how to run multiple.
Computer Science 210 Computer Organization
Chapter 1: Introduction to computers and C++ Programming
Computer Science 210 Computer Organization
Chapter 12 Variables and Operators
What's a Computer? Monitor Disk Main mouse Memory Keyboard Network
Chapter 12 Variables and Operators
Chapter 2 Overview of C.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Lecture2.
C programming language
Introduction to C Programming
Visit for more Learning Resources
Computer Science 210 Computer Organization
Chapter 12 Variables and Operators
Chapter 12 Variables and Operators
Computer Science 210 Computer Organization
Computer Organization & Compilation Process
Chapter 11 Introduction to Programming in C
Introduction to C Programming
Chapter 11 Introduction to Programming in C
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 11 Introduction to Programming in C
Introduction to C Topics Compilation Using the gcc Compiler
C Programming Pointers
Chapter 11 Programming in C
Computer Organization & Compilation Process
Introduction to Computing Lecture 09: Functions (Part II)
Scope Rules.
Introduction to Pointers
Chapter 11 Introduction to Programming in C
Presentation transcript:

Chapter 11-12, Appendix D C Programs Higher Level languages Compilers C programming Converting C to Machine Code C Compiler for LC-3

Higher Level Languages High Level Languages give us: Symbolic Names Expressions Libraries of functions/subroutines Abstraction of underlying hardware Readability Structure – help keep nasty bugs out

Translating Higher Level Program Interpreters Translated to machine code as the program runs Compilers Translated into a load module before program runs

Compiling C

Simple Example C Program /* * Program Name : countdown, our first C program * * Description : This program prompts the user to type in * a positive number and counts down from that number to 0, * displaying each number along the way. */ /* The next two lines are preprocessor directives */ #include #define STOP 0 /* Function : main */ /* Description : prompt for input, then display countdown */ int main() { /* Variable declarations */ int counter; /* Holds intermediate count values */ int startPoint; /* Starting point for count down */ /* Prompt the user for input */ printf("===== Countdown Program =====\n"); printf("Enter a positive integer: "); scanf("%d", &startPoint); /* Count down from the input number to 0 */ for (counter = startPoint; counter >= STOP; counter--) { printf("%d\n", counter); } return 0 }

Terms, Etc. Pre processor directives #define #include Header Files Data Types int char double Scope Local Global Variable Initiation Local – not initialized Global – initialized to 0

Scope #include int globalVar = 2; /* This variable is global */ int main() { int localVar = 3; /* This variable is local to main */ printf("Global %d Local %d\n", globalVar, localVar); { int localVar = 4; /* Local to this sub-block */ printf("Global %d Local %d\n", globalVar, localVar); } printf("Global %d Local %d\n", globalVar, localVar); return 0 }

IMPORTANT Pointers - IMPORTANT A pointer is a variable which contains the address in memory of another variable. We can have a pointer to any variable type. The unary or monadic operator & gives the ``address of a variable''. The indirection or dereference operator * gives the ``contents of an object pointed to by a pointer variable''. To declare a pointer to a variable: int *pointer; Note: ip = ip + 1 actually increments ip by 4. Why?