CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared.
Published byModified over 6 years ago
Presentation on theme: "CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared."— Presentation transcript:
CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared by Yang Song and Suresh Solaimuthu)
Programming Language How can we ask others to do something? Then how can we deal with computers? A system of communication bridge human and the machine, so that it can pass our data and instruction to the machine for some specific job. Thousands of different programming languages have been created, every year there’ll be new one come out.
Major Types Low level programming languages Machine Language Assembly Language High level programming languages
Low Level Languages That means the closeness to the way in which the machine has been built. They are machine oriented and require extensive knowledge of computer hardware and its configuration. Little or no natural language 1 st generation: Machine Language 2 nd generation: Assembly Language
Machine Language It is a system of instructions and data directly executed by computer’s CPU, it’s written as strings of 1s and 0s: …1001100010110101… Advantage: Fast! Disadvantage: Programmer has to know all the details of hardware Programmer has to remember lots of codes that results in program errors It’s very hard to debug the program
Assembly Language Came out in 1950s, it implements a symbolic representation of the numeric machine codes. This representation is defined by hardware manufacturer and is based on abbreviations First step to improve the programming structures Computer can handle numbers and letter e.g. : mov al, #061h means to move hexadecimal 61 (97) to the register al
Translate into Machine Code Assembly language is not machine readable language “Translator” is needed to convert one language to another language: Assembler
Assembly Language Advantage: Symbolic programming is easier to understand and can save time for programmers. It’s easier to correct errors and modify programs. Same efficiency of execution as the machine language, because it’s one-to-one translation. Disadvantage: A major one: It is machine dependent, computer’s hardware configuration means everything.
High Level Language Assembly language and machine level language require deep knowledge of computer hardware What do we expect? Instructions in English words and logic of the problem irrespective of the type of computer being used Using simple languages that use English and mathematical symbols (+, -, *, /….) for its program construction
Some C++ code example ……………………. int a=3, b=4, c; string out; c = a – b; if (c < 0) out = “a is less than b”; else if (c == 0) out = “a is equal to b”; else out = “a is greater than b”; cout << out; …………………….
Problem Oriented High level languages are problem oriented languages Instructions can be written that are suitable for solving a particular problem to make it more like the language of the problem itself Fortran – FORmula TRANslator COBOL – COmmon Business Oriented Language BASIC – Beginners All-purpose Symbolic Instruction Code Perl – scripting language
How Can Computer Understand High Level Language? In Assembly language we have “translator” named Assembler to convert Assembly language into machine code We have two different types of “translator” for high level language: Compiler Interpreter
Compiler Translates the high level language to machine language or assembly language Scans the ENTIRE program first and then translates it into machine code Syntax/Semantic check, optimize Source Program: written by the programmer in high level language Object Program: the program is converted to machine language
Compiler It can translate only those source programs, which have been written, in that language for which the compiler is meant for C++ compiler doesn’t work for PASCAL Object program from compiler is machine dependent: programs compiler for one type of machine won’t work on another type Every type of machine needs to have its particular compiler for a particular language Machine independence?
Interpreter Translates the high level language to machine language or assembly language Takes one statement of higher level languages, translates it into machine language and immediately execute it Translation and execution are carried out for each statement
Compiler V.S. Interpreter Both translate high level languages into low level languages Entire program V.S. Statement by statement Which one has the fast response to the changes in source program? Which one eliminates the need for a separate compilation after changes to each program? Which one is easier to write and don’t require large memory in computer? Which one is more efficient eventually ?
Advantage and Disadvantage of High Level Language Advantages Easy to learn and use Possible to make machine-independent Disadvantages Slower than low level languages May we make some hybrid version? The famous C