Introduction to Programming Language ufiittelkom ac id Programming

  • Slides: 18
Download presentation
Introduction to Programming Language ufi@ittelkom. ac. id

Introduction to Programming Language ufi@ittelkom. ac. id

Programming Languages o Definition: A programming language is a language used to write computer

Programming Languages o Definition: A programming language is a language used to write computer programs, which involve a computer performing some kind of computation[2] or algorithm and possibly control external sevices such as printers, robots, [3] and so on. (wikipedia) • Usage: A programming language provides a structured mechanism for defining pieces of data, and the operations or transformations that may be carried out automatically on that data. A programmer uses the abstractions present in the language to represent the concepts involved in a computation. These concepts are represented as a collection of the simplest elements available (called primitives). [7]

Programming Languages (Contd. ) • The programming language instructions have two parts, as shown

Programming Languages (Contd. ) • The programming language instructions have two parts, as shown in the following figure: Format of a Programming Language Instruction • The two parts of a programming language instruction are: • Operation code (opcode): This part instructs a computer about the operation to be performed and each computer has its own set of opcode • Opcode in the instruction set can perform following operations: Logical operations, Arithmetic operations, Branch Operations, Data movement operations • Operand: This part instructs the computer about the location of the data on which the operation specified by the opcode is to be performed.

Programming Languages (Contd. ) • Programming languages can be classified into two broad categories

Programming Languages (Contd. ) • Programming languages can be classified into two broad categories : • Low Level Language : • • First generation (1 GL) machine code • Second Generation (2 GL) assembly language High-level Language

Introducing Machine Language • • • refers to the "ones and zeroes" that digital

Introducing Machine Language • • • refers to the "ones and zeroes" that digital processors use as instructions. The instruction sets within a CPU family are usually compatible, but not between product lines. • For example, Intel's x 86/Pentium language and Motorola's PPC/Gx language are completely incompatible. Example: A function in 32 -bit x 86 machine code to calculate the nth Fibonacci number: 8 B 542408 83 FA 0077 06 B 80000 C 383 FA 027706 B 8010000 00 C 353 BB 01000000 B 9010000 008 D 0419 83 FA 0376 078 BD 98 B C 84 AEBF 1 5 BC 3

Introducing Machine Language • • Advantage of the machine language: • Programs written in

Introducing Machine Language • • Advantage of the machine language: • Programs written in a machine language execute faster Limitations of the machine language: • Programs are difficult to write • Programs are dependent on the hardware configuration of the machine • Programs are error-prone • Programs are difficult to modify

Introducing Assembly Language • • • The assembly language uses alphanumeric code and symbols

Introducing Assembly Language • • • The assembly language uses alphanumeric code and symbols instead of binary digits to represent instructions and memory addresses. has the advantage that it's also human-readable. . . using a small vocabulary of words with one syllable A translation program called an assembler is needed to interpret an assembly language code into the machine language code. fib: mov edx, [esp+8] cmp edx, 0 ja @f mov eax, 0 ret @@: cmp edx, 2 ja @f mov eax, 1 ret @@: push ebx mov ebx, 1 mov ecx, 1 @@: lea eax, [ebx+ecx] cmp edx, 3 jbe @f mov ebx, ecx mov ecx, eax dec edx jmp @b @@: pop ebx ret

Introducing Assembly Language (Contd. ) • Advantages of the assembly language: • Programs are

Introducing Assembly Language (Contd. ) • Advantages of the assembly language: • Programs are easier to write and understand. • Programmers can easily remember the opcode and alphanumeric names for the addresses of data and instructions. • Programs can be written faster than machine language. • Limitations of the assembly language: • Programs are slower than those created in a machine language. • Programs are dependent on processors.

Introducing High-level Language o high-level programming language is a programming language with strong abstraction

Introducing High-level Language o high-level programming language is a programming language with strong abstraction from the details of the computer. In comparison to lowlevel programming languages, it may use natural language elements, be easier to use, or be more portable across platforms. Such languages hide the details of CPU operations such as memory access models and management of scope. • High-level languages are machine independent. • Advantages of the high-level language: • Programs are easy to understand. • It is easy to read, write, and maintain a program. • Being hardware independent, high-level language provide the feature of portability.

Introducing High-level Language There are three models of execution for modern high-level languages: o

Introducing High-level Language There are three models of execution for modern high-level languages: o Interpreted n o Interpreted languages are read and then executed directly, with no compilation stage. Compiled n n Compiled languages are transformed into an executable form before running. There are two types of compilation: Intermediate representations o When a language is compiled to an intermediate representation, that representation can be optimized or saved for later execution without the need to re-read the source file. When the intermediate representation is saved it is often represented as bytecode. n Machine code generation o Some compilers compile source code directly into machine code. Virtual machines that execute bytecode directly or transform it further into machine code have blurred the once clear distinction between intermediate representations and truly compiled languages. o Translated n A language may be translated into a low-level programming language for which native code compilers are already widely available. The C programming language is a common target for such translators.

Interpreter • • Some high-level languages use a different type of translator program called

Interpreter • • Some high-level languages use a different type of translator program called an interpreter. An interpreter takes a high-level language instruction, converts it to a machine language instruction, executes it and does not save the object code.

Compiler o To execute a program written in a high-level language • A computer

Compiler o To execute a program written in a high-level language • A computer needs translation software called a compiler • A compiler is language-specific, and each high-level language has its own compiler. o The following figure shows how a compiler works:

Compiler (Contd. ) o When a compiler program translates a source program, it checks

Compiler (Contd. ) o When a compiler program translates a source program, it checks the syntax of the statements. • If the compiler finds an error in the source program, it generates a list of errors. • The compiler does not generate the object code until the errors are removed.

Examples of High-level Languages BASIC COBOL ["Beginner's All-purpose Symbolic Instruction Code"] is the first

Examples of High-level Languages BASIC COBOL ["Beginner's All-purpose Symbolic Instruction Code"] is the first language that most early microcomputer users learned. The BASIC interpreters on those machines weren't very sophisticated or fast, largely due to the memory and speed limitations of the hardware, and the language encouraged sloppy coding. As an unknown pundit put it: "BASIC is to computer languages what Roman numerals are to arithmetic" Modern versions of BASIC are more structured and often include compilers for greater speed. Free and commercial tools are available from various sources for DOS, Windows, Mac, and Unix-like systems. ["COmmon Business-Oriented Language"] is the language modern programmers love to hate and ridicule. Although it is nearly as old as commercial computing itself, improperly blamed for Y 2 K issues, and its imminent extinction is frequently predicted, it is still in widespread use due to its usefulness for traditional business uses of processing data and producing reports. A version with object-oriented tools has even been created, with an inexpensive integrated development environment for Linux and Windows available. It is very verbose, designed so that its commands would describe in English exactly what it was doing. e. g. ADD SHIPPING-CHARGE TO INVOICESUBTOTAL

Examples of High-level Languages Pascal FORTRAN [mathematician/philosopher Blaise Pascal] was designed primarily as a

Examples of High-level Languages Pascal FORTRAN [mathematician/philosopher Blaise Pascal] was designed primarily as a tool for teaching good programming skills, but - thanks largely to the availability of Borland's inexpensive Pascal compiler for the early IBM PC - it has become popular outside of the classroom. Unlike many languages, Pascal requires a fairly structured approach, which prevents the kinds of indecipherable "spaghetti code" and easily-overlooked mistakes that plague programmers using languages such as Fortran or C. Free and commercial tools are available from various sources for DOS, Windows, Mac, OS/2, Amiga. OS, and Unix-like systems. The web site editor BBEdit is written in Pascal. ["FORmula TRANslation"] is the oldest language still in general use, dating back to 1957, the year the Space Age began. It excels at the first task computers were called on for: number-crunching. This is the language that literally put a man on the moon, and some of the features it developed in the process of that project (and other less glamorous ones) have yet to be duplicated in other, more "modern" languages.

Examples of High-level Languages C Ada C [successor to the language "B"] offers an

Examples of High-level Languages C Ada C [successor to the language "B"] offers an elegant compromise between the efficiency of coding in assembly language and the convenience and portability of writing in a structured, high-level language. By keeping many of its commands and syntax analagous to those of common machine languages, and with several generations of optimising compilers behind it, C makes it easy to write fast code without necessarily sacrificing readability. But it still tempts you write code that only a machine can follow, which can be a problem when it comes time to debug it or make changes. Free and commercial tools (most of which now also support C++) are available from various sources for just about every operating system. Based largely on Pascal, it was commissioned by the U. S. Dept. of Defense to create a standard language to replace the polyglot they had amassed over the decades. It's commonly accused of being typical of government committee work, but has many strengths, including its error-handling and the ease of maintaining and modifying programs. Furthermore, government studies : ) indicate that it's more cost-effective than C++, Pascal, or Fortran. The current version includes object-oriented features.

Examples of High-level Languages Java LISP is kind of a streamlined version of C++,

Examples of High-level Languages Java LISP is kind of a streamlined version of C++, designed for portability. Its key advantage is that Java programs can be run on any operating system for which a Java "virtual environment" is available. (Programs in most other languages have to be modified and recompiled to go from one OS to another. ) The language is defined by Sun and widely licenced to other companies, making it possible to run Java apps in web browsers, portable phones, desktop computers, web servers, etc. It isn't as fast as applications written in a compiled language like C++, however. Free and commercial tools are available from various sources for most current operating systems. Although Microsoft is removing support for Java from the default setup of new versions of Windows, it can easily be added back in. ["LISt Processing"] is "a programmable programming language", built on the concept of recursion and highly adaptable to vague specifications. Avoid it if you find parentheses unappealing (its syntax tends toward a proliferation of nested parentheses), but its ability to handle problems that other languages cannot is one of the reasons this 40+-year-old language is still in use. There's an entire cross-platform web server written in it.

Selecting a Programming Language o The following factors should be considered when selecting a

Selecting a Programming Language o The following factors should be considered when selecting a programming language: • The first criterion for selecting a language is the type of application that is to be developed. • If multiple languages are suitable for an application, programmers should select a language in which they are proficient. • If the programmer are not familiar with any language, they should select a language that is easy to learn and use.