60 likes | 319 Views
C Programming Chapters 11,. C – Compiler Compilation Tracing C programs C Functions C program Stack Structure. Memory map. (Global Data pointer). I/O Devices. C Functions. All C programs begin with the main Function: #include <stdio.h> ; include libraries for compiler
E N D
C ProgrammingChapters 11, . . . • C – Compiler Compilation • Tracing C programs • C Functions • C program Stack Structure
Memory map (Global Data pointer) I/O Devices
C Functions All C programs begin with the main Function: #include <stdio.h> ; include libraries for compiler #define Two = 2 ; “Two” will be replaced in code with 2 int x = 56; ; x is a global variable int main () ; main has an “int” type return value { int y = 47; ; y is a local variable return 0; ; return the value “0” }
C Functions #include <stdio.h> int sum (int r, int s, int t); int main() { z = sum (x,y,z) + 65; } int sum (int A, int B, int C) { int total; ; total is a local variable total = A + B + C); return total; ; return the sum }
C Program int Func1(int x) { return Func2(x) + 1; } int Func2(int x) { return Func3(x) + 1; } int Func3(int x) { return Func4(x) + 1; } int Func4(int x) { return x + 1; } #include <stdio.h> int Func1(int x); int Func2(int x); int Func3(int x); int Func4(int x); int main() { int A = 3; int B = 5; int C; C = A + B; C = Func1(C); C = C + 1; return 2; }
C Program Compilation • Compile the program • Look at the files • Load them into the LC-3 simulator • Execute the program and observe its stack