1 / 8

Chapter 11-12 , Appendix D C Programs

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

azura
Download Presentation

Chapter 11-12 , Appendix D C Programs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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

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

  4. Compiling C

  5. 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 <stdio.h> #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 }

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

  7. Scope #include <stdio.h> 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 }

  8. 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?

More Related