Presentation on theme: "CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR."— Presentation transcript:
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR
Some Fundamentals Outline: Programming Higher-Level Languages Operating Systems Compiling Programs 2
Programming Computers are really very dumb machines indeed because they do only what they are told to do. Most computer systems perform their operations on a very primitive level. For example, most computers know how to add one to a number or how to test whether a number is equal to zero. The basic operations of a computer system is called the computer’s instruction set. To solve a problem using a computer, you must express the solution to the problem in terms of the instructions of the particular computer. A computer program is just a collection of the instructions necessary to solve a specific problem. The approach or method that is used to solve the problem is known as an algorithm. 3
Programming -For example, if you want to develop a program that tests if a number is odd or even, the set of statements that solves the problem becomes the program. The method that is used to test if the number is even or odd is the algorithm. To develop a program to solve a particular problem, First, express the solution to the problem in terms of an algorithm. Then, develop a program that implements that algorithm. So, the algorithm for solving the even/odd problem: Divide the number by two. If the remainder of the division is zero, the number is even; otherwise, the number is odd. After you designed the algorithm, write the instructions necessary to implement this algorithm on a particular computer system. (i.e. Program) -These instructions would be expressed in the statements of a particular computer language, such as Visual Basic, Java, C++, or C. 4
Higher-Level Languages 5 When computers were first developed, the only way they could be programmed was in terms of binary numbers that corresponded directly to specific machine instructions and locations in the computer’s memory. Then the computers were advanced with the development of assembly languages, which enabled the programmer to work with the machine on a slightly higher level. The assembly language permits the programmer to use symbolic names to perform various operations and to refer to specific memory locations. A special program, known as an assembler, translates the assembly language program from its symbolic format into the specific machine instructions of the computer system.
6 Assembly languages are regarded as low-level languages because: 1-The programmer must learn the instruction set of the particular computer system to write a program because of one-to-one correspondence between each assembly language statement and a specific machine instruction. 2-The resulting program is not portable; that is, the program will not run on a different processor type without being rewritten. This is because different processor types have different instruction sets, and assembly language programs are written in terms of these instruction sets (i.e. machine dependent). Higher-Level Languages
7 Then, the higher-level languages were developed. FORTRAN (FORmula TRANslation) language was one of the first higher-level languages. One FORTRAN instruction or statement resulted in many different machine instructions being executed, unlike the one-to-one correspondence in assembly language. Standardization of the syntax of a higher-level language meant that a program could be written in the language to be machine independent. That is, a program could run on any machine that supported the language with few or no changes. In higher-level language, the compiler must be developed. A compiler is a special computer program that translates the statements of the program developed in the higher-level language into a form that the computer can understand ( i.e. the particular instructions of the computer).
Operating Systems 8 Operating system: a program that controls the entire operation of a computer system: -Handles all input and output (I/O) operations that are performed on a computer -Manages the computer system’s resources -Handles the execution of programs (including multitasking or multiuser facilities) Most famous OS families: -Windows -Unix
Compiling Programs 9 A compiler analyzes a program developed in a particular computer language and then translates it into a form that is suitable for execution on your particular computer system. The program that is to be compiled is first typed into a file on the computer system. C programs can typically be given any name provided the last two characters are “.c” ( e.g. prog1.c ). A text editor is usually used to enter the C program into a file. The program that is entered into the file is known as the source program because it represents the original form of the program expressed in the C language. After the source program has been entered into a file, you can then proceed to have it compiled.
10 Typical steps for entering, compiling, and executing C programs from the command line Typical errors reported during compilation might be due to: 1-An expression that has unbalanced parentheses (syntactic error), or 2-The use of a variable that is not “defined” (semantic error). When all the syntactic and semantic errors have been removed from the program, the compiler then proceeds to take each statement of the program and translate it into a “lower” form (assembly language)
Compiling Programs 11 After the program has been translated into an equivalent assembly language program, the next step in the compilation process is to translate the assembly language statements into actual machine instructions (binary format known as object code). After the program has been translated into object code, it is ready to be linked. Linking means If the program uses other programs that were previously processed by the compiler, then during this phase the programs are linked together. The process of compiling and linking a program is often called building. The final linked file, which is in an executable object code format, is stored in another file on the system, ready to be run or executed.