A programming language is a set of symbols, grammars and rules with the help of which one is
able to translate algorithms to programs that will be executed by the computer. The programmer communicates with a machine using programming languages. Most of the programs have a highly structured set of rules.com
The primary classifications of programming languages are: Machine Languages. Assembly Languages. High level Languages.
Machine language is a collection of binary digits or bits that the computer reads and interprets. Machine language is the only language a computer is capable of understanding. Machine level language is a language that supports the machine side of the programming or does not provide human side of the programming. It consists of (binary) zeros and ones. Each instruction in a program is represented by a numeric code, and numerical addresses are used throughout the program to refer to memory locations in the computer’s memory. Microcode allows for the expression of some of the more powerful machine level instructions in terms of a set of basic machine instructions.com
Assembly language is easier to use than machine language. An assembler is useful for detecting programming errors. Programmers do not have the absolute address of data items. Assembly language encourage modular programming.com
High level language is a language that supports the human and the application sides of the programming. A language is a machine independent way to specify the sequence of operations necessary to accomplish a task. A line in a high level language can execute powerful operations, and correspond to tens, or hundreds, of instructions at the machine level. Consequently more programming is now done in high level languages. Examples of high level languages are BASIC, FORTRAN etc.com
The compiler program translates the instructions of a high level language to a machine level language. A separate compiler is required for every high level language. High level language is simply a programmer’s convenience and cannot be executed in their source. The actual high - level program is called a source program. It is compiled (translated) to machine level language program called object program for that machine by the compiler. Such compilers are called self- resident compilers. Compiler compiles the full program and reports the errors at the end.com
The compilation and execution process of C can be divided in to multiple steps:
· Preprocessing Using a Preprocessor program to convert C source code in expanded source code. "#include" and "#define" statements will be processed and replaced actually source codes in this step.
· Compilation Using a Compiler program to convert C expanded source to assembly source code.
· Assembly Using a Assembler program to convert assembly source code to object code.
· Linking Using a Linker program to convert object code to executable code. Multiple units of object codes are linked to together in this step.
· Loading Using a Loader program to load the executable code into CPU for execution. Compilation
· After all of the files are compiled, they must be "merged together" to produce a single executable file that the user use to run the program.
· In C, most compiled programs produce results only with the help of some standard programs, known as library files that reside in the computer. This process is called linking.
· The result obtained after linking is called the executable file.com
· The linker′s primary function is to bind symbolic names to memory addresses.
· To do this, it first scans the files and concatenates the related file sections to form one large file. Then, it makes a second pass on the resulting file to bind symbol names to real memory addresses.
· Loading is loading the executable into memory prior to execution.
· There are two types of linking: Static linking. Dynamic linking.
· Static linking occurs at compilation time; hence it occurs prior to loading a program. With static linking the external symbols that are used by the program (e.g. function names) are resolved at compile time.
· Dynamic linking occurs at run time, so it occurs after or at the time of the loading of a program. With dynamic linking the symbols are resolved either at loading time, or at run time when the symbol is accessed (lazy binding).
· After the files are compiled and linked the executable file is loaded in the computer′s memory for executing by the loader. This process is called Loading.
· Program loading is basically copying a program from secondary storage into main memory so it ′s ready to run.
· In some cases, loading us just not copying the data from disk to memory, but also setting protection bits, or arranging for virtual memory map virtual addresses to disk pages.
Programing languages / Coding language
Language Description
Ada Ada was created in the 1970s, primarily for applications used by the U.S. Department of Defense. The language is named in honor of Countess Ada Lovelace, an influential and historic figure in the field of computing.com
BASIC Beginners All-purpose Symbolic Instruction Code is a general-purpose language that was originally designed in the early 1960s to be simple enough for begin- ners to learn. Today, there are many different versions of BASIC.com
FORTRAN FORmula TRANslator was the first high-level programming language. It was designed in the 1950s for performing complex mathematical calculations.in
COBOL Common Business-Oriented Language was created in the 1950s, and was designed for business applications.
Pascal Pascal was created in 1970, and was originally designed for teaching program- ming. The language was named in honor of the mathematician, physicist, and philosopher Blaise Pascal.com
C and C++ C and C++ (pronounced “c plus plus”) are powerful, general-purpose lan- guages developed at Bell Laboratories. The C language was created in 1972 and the C++ language was created in 1983.
C# Pronounced “c sharp.” This language was created by Microsoft around the year 2000 for developing applications based on the Microsoft .NET platform.com
Java Java was created by Sun Microsystems in the early 1990s. It can be used to develop programs that run on a single computer or over the Internet from a web server.com
JavaScript JavaScript, created in the 1990s, can be used in web pages. Despite its name, JavaScript is not related to Java.
Python Python, the language we use in this book, is a general-purpose language created in the early 1990s. It has become popular in business and academic applications.com
Ruby Ruby is a general-purpose language that was created in the 1990s. It is increas- ingly becoming a popular language for programs that run on web servers.
Visual Basic Visual Basic (commonly known as VB) is a Microsoft programming language and software development environment that allows programmers to create Windows- based applications quickly. VB was originally created in the early 1990s.
How a Program Works
CONCEPT: A computer’s CPU can only understand instructions that are written in machine language. Because people find it very difficult to write entire programs in machine language, other programming languages have been invented.
Earlier, we stated that the CPU is the most important component in a computer because it is the part of the computer that runs programs. Sometimes the CPU is called the “computer’s brain,” and is described as being “smart.” Although these are common metaphors, you should understand that the CPU is not a brain, and it is not smart. The CPU is an electronic device that is designed to do specific things. In particular, the CPU is designed to perform operations such as the following:
• Reading a piece of data from main memory
• Adding two numbers
• Subtracting one number from another number
• Multiplying two numbers
• Dividing one number by another number
• Moving a piece of data from one memory location to another
• Determining whether one value is equal to another value
As you can see from this list, the CPU performs simple operations on pieces of data. The CPU does nothing on its own, however. It has to be told what to do, and that’s the purpose of a program. A program is nothing more than a list of instructions that cause the CPU to perform operations.
Each instruction in a program is a command that tells the CPU to perform a specific oper- ation. Here’s an example of an instruction that might appear in a program:
10110000
To you and me, this is only a series of 0s and 1s. To a CPU, however, this is an instruction to perform an operation.1 It is written in 0s and 1s because CPUs only understand instructions that are written in machine language, and machine language instructions always have an underlying binary structure.
A machine language instruction exists for each operation that a CPU is capable of perform- ing. For example, there is an instruction for adding numbers, there is an instruction for sub- tracting one number from another, and so forth. The entire set of instructions that a CPU can execute is known as the CPU’s instruction set.
The machine language instruction that was previously shown is an example of only one instruction. It takes a lot more than one instruction, however, for the computer to do anything meaningful. Because the operations that a CPU knows how to perform are so basic in nature, a meaningful task can be accomplished only if the CPU performs many operations. For example, if you want your computer to calculate the amount of inter- est that you will earn from your savings account this year, the CPU will have to perform a large number of instructions, carried out in the proper sequence. It is not unusual for a program to contain thousands or even millions of machine language instructions.
Programs are usually stored on a secondary storage device such as a disk drive. When you install a program on your computer, the program is typically copied to your computer’s disk drive from a CD-ROM, or perhaps downloaded from a website.
Although a program can be stored on a secondary storage device such as a disk drive, it has to be copied into main memory, or RAM, each time the CPU executes it. For example, suppose you have a word processing program on your computer’s disk. To execute the program you use the mouse to double-click the program’s icon. This causes the program to be copied from the disk into main memory. Then, the computer’s CPU executes the copy of the program that is in main memory. This process is illustrated in Figure 1-16.
When a CPU executes the instructions in a program, it is engaged in a process that is known as the fetch-decode-execute cycle. This cycle, which consists of three steps, is repeated for each instruction in the program. The steps are:
1. Fetch A program is a long sequence of machine language instructions. The first step of the cycle is to fetch, or read, the next instruction from memory into the CPU.
2. Decode A machine language instruction is a binary number that represents a com- mand that tells the CPU to perform an operation. In this step the CPU decodes the instruction that was just fetched from memory, to determine which operation it should perform.
3. Execute The last step in the cycle is to execute, or perform, the operation. Figure 1-17 illustrates these steps.
From Machine Language to Assembly Language
Computers can only execute programs that are written in machine language. As previously mentioned, a program can have thousands or even millions of binary instructions, and writing such a program would be very tedious and time consuming. Programming in machine language would also be very difficult because putting a 0 or a 1 in the wrong place will cause an error.
Although a computer’s CPU only understands machine language, it is impractical for people to write programs in machine language. For this reason, assembly language was created in the early days of computing2 as an alternative to machine language. Instead of using binary num- bers for instructions, assembly language uses short words that are known as mnemonics. For example, in assembly language, the mnemonic add typically means to add numbers, mul typ- ically means to multiply numbers, and mov typically means to move a value to a location in memory. When a programmer uses assembly language to write a program, he or she can write short mnemonics instead of binary numbers.
Assembly language programs cannot be executed by the CPU, however. The CPU only understands machine language, so a special program known as an assembler is used to translate an assembly language program to a machine language program. This process is shown in Figure 1-18. The machine language program that is created by the assembler can then be executed by the CPU.
Although assembly language makes it unnecessary to write binary machine language instructions, it is not without difficulties. Assembly language is primarily a direct substitute for machine language, and like machine language, it requires that you know a lot about the CPU. Assembly language also requires that you write a large number of instructions for even the simplest program. Because assembly language is so close in nature to machine lan- guage, it is referred to as a low-level language.
In the 1950s, a new generation of programming languages known as high-level languages began to appear. A high-level language allows you to create powerful and complex programs without knowing how the CPU works, and without writing large numbers of low-level instructions. In addition, most high-level languages use words that are easy to understand. For example, if a programmer were using COBOL (which was one of the early high-level
2 The first assembly language was most likely that developed in the 1940s at Cambridge University for use with a historic computer known as the EDSAC. languages created in the 1950s), he or she would write the following instruction to display the message Hello world on the computer screen:
DISPLAY "Hello world"
Python is a modern, high-level programming language that we will use in this book. In Python you would display the message Hello world with the following instruction:
print 'Hello world'
Doing the same thing in assembly language would require several instructions, and an intimate knowledge of how the CPU interacts with the computer’s output device. As you can see from this example, high-level languages allow programmers to concentrate on the tasks they want to per- form with their programs rather than the details of how the CPU will execute those programs.
Since the 1950s, thousands of high-level languages have been created. Table 1-1 lists several of the more well-known languages.