Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Chapter 11-12, Appendix D C Programs Higher Level languages Compilers C programming Converting C to Machine Code C Compiler for LC-3."— 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 #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 Data Types int char double Scope Local Global Variable Initiation Local – not initialized Global – initialized to 0

7 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 }

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


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

Similar presentations


Ads by Google