Introduction to Python Programming – Programming Languages

You can learn about Introduction to Programming Using Python Programs with Outputs helped you to understand the language better.

Introduction to Python Programming – Programming Languages

Programming Languages

A computer can only do what a program can make it do. To perform a particular task, the programmer writes a sequence of instructions called a program.

  • An instruction is a command given to the computer to perform a certain specified operation on given data. A set of programs written to perform a specific task on a computer is called software.

A computer contains a Central Processing Unit (CPU) which interprets each instruction in a pro¬gram serially, sets up an internal route for the flow of data, manipulates data, and stores it in the main memory. Thereafter, it fetches the next instruction. This process continues till the last instruction has been executed.

Basically, a processor is designed to understand a specified set of instruction codes, and each of these instructions is stored in the main memory in the form of binary numbers. Microprocessors have input/output instructions to manipulate characters. Usually, the number and type of instructions for different types of microprocessors are not the same.

Each natural language has a systematic method of using the symbols of that language. In English, the method is given by the rules of grammar. These rules tell us which word to use when and how to use it. Similarly, the symbols of a particular computer language must also be used as per the set of rules which are known as the “syntax rules” of the language. In the case of a natural language, people can use poor or incorrect vocabulary and grammar, and still make themselves understood. However, computers, being machines, can accept only exact vocabulary governed by strict syntax rules of the language being used. Thus, in the case of a computer language, you must adhere to the syntax of the language, if you want it to be understood by the computer. Computer languages can be classified into three broad categories:

a. Machine language
b. Assembly language
c. High-level language

Machine or Low-Level Language

The set of instruction codes, whether in binary or in decimal notation, which can be directly understood by the computer without the help of a translator is called a machine code or machine/Low-Level language program.

The computer understands information composed of only zeros and ones, and hence it uses binary digits for its operation. The computer instructions are therefore coded and stored in the memory in the form of 0’s and l’s. A program written in the form of 0’s and l’s is called a machine language program. There is a specific binary code for each instruction. For example, to add the contents of register A and register B, the binary code is 10000000 for Intel 8085. The binary code (machine code or object code) for a certain operation differs from computer to com¬puter. Each microprocessor has its own instruction set and corresponding machine codes.

Machine code is the fundamental language of a computer and is normally written as strings of l’s and 0’s. However, a machine language program need not necessarily be coded as strings of binary digits (l’s and 0’s). It can also be written using deci¬mal digits if the circuitry of the computer being used permits this.

The circuitry of the computer is wired in such a way that it immediately recognizes the machine language and converts it into the electrical signals needed to run the computer. An instruction prepared in any machine language has a two-part format, as shown in Figure 1.3. The first part is the command or operation, and it tells the computer what function to perform. Every computer has an operation code or opcode for each of its functions. The second part of the instruction is the operand, and it tells the computer where to find or store the data or other instructions that are to be manipulated. Thus, each instruction tells the control unit of the CPU what to do, and the length and location of the data fields that are involved in the operation. Typical operations involve reading, adding, subtracting, writing, and so on.

OPCODE OPERAND
(Operation code) (Address / Location)
  • All computers use binary digits (0’s and 1’s) for performing internal operations.

Hence, most computer machine languages consist of strings of binary numbers. This is the only language that the CPU directly understands. When stored inside the computer, the symbols which make up the machine language program are made up of l’s and 0’s. For example, a typical program instruction to print out a number on the printer might be:

101100111111010011101100
The program to add two numbers in memory and print the result might look like the following:
001000000000001100111001001100000000010000100001
011000000000011100101110101000111111011100101110
000000000000000000000000

  • Machine language is not a very easy language to learn because it is difficult to read and understand, and it is written in a number system with which you are not familiar.

Since programmers are more familiar with the decimal number system and English language, most of them prefer to write the computer instructions in high-level language using decimal numbers.

Advantages and Disadvantages of using Machine Language

Programs written in machine language are executed very fast by the computer. This is mainly because machine instructions are directly understood by the: CPU and no translation of the program is required. However, writing a program in machine language has several disadvantages which are discussed below.

Machine Dependent: Since the internal design of every type of processor is different from that of every other type of processor, each type needs different electrical signals to operate. The machine language is also different from one type of computer to another. It is determined by the actual design or construction of the Arithmetic Logic Unit (ALU), the Control Unit, and the size as well as the word length of the Memory Unit. Hence, it is important to note that after becoming proficient in the machine code of a particular computer, the programmer will be required to learn a new machine code and would; have to write all the existing programs again, in case the computer system is changed.

Difficult to Program: Although machine language is easily understood by the computer, it is very difficult for a human programmer to write a program in this language. It is necessary for the programmer either to memorize many dozens of code numbers for the commands in the machine instruction set or to constantly refer to a reference card. A programmer is also forced to keep track of the storage locations of data and instructions. The machine language programmer must also be an expert who knows about the hardware structure of the computer.

Errorprone: Since the machine language programmer has to remember opcodes and storage locations of data and instructions, it, therefore, becomes very difficult for him to concentrate fully on the logic of the problem. This frequently causes errors in programming.

Difficult to Modify: It is very difficult to debug or modify machine language programs. Checking machine instructions to locate errors is also as tedious as writing them initially. Similarly, modifying a machine language program at a later date is so difficult that many programmers would prefer coding the logic afresh instead of incorporating the necessary modifications in the old program.In short, writing a program in machine language is so difficult and time-consuming that it is rarely used today.

Assembly Language

Programs can easily be written in alphanumeric, symbols instead of 0’s and l’s. Meaningful and eas¬ily rememberable symbols are selected for this purpose. For example, ADD for addition, SUB for subtraction, CMP for comparison, etc. Such symbols are known as mnemonics. A program written in mnemonics is called an assembly language program. The writing of programs in assembly language is easier and faster as compared to the writing of programs in machine language.

Advantages of Assembly Language

The advantage of assembly language over machine language is that the computation time of an assembly language program is less. The assembly language program runs faster to produce the desired result.

Disadvantages of Assembly Language

1) Programming is difficult and time-consuming.

2) Assembly language is machine-dependent. The programmer must have detailed knowledge of the structure of the computer he is using. He must have the knowledge of registers and instruction sets of the computer, connections of ports to the peripherals, etc.

3) The program written in assembly language for one computer cannot be used in any other computer, i.e., the assembly language program is not portable. Each processor has its own instruction sets and hence, its own assembly language.

4) An assembly language program contains more instructions as compared to a high-level language program. Each statement of a program in the high-level language corresponds to many instructions in the assembly language program.

5) In the case of an assembly language, instructions are still written at the machine code level. This means that one assembly language instruction is substituted for one machine code instruction.

High-Level Languages

A language in which each statement is directly translated into a single machine code is known as low-level language. Examples of low-level languages are the assembly languages of various processors. The basic problem of an assembly language is that it is more closely related to the structure of a computer than to the performance of the task which is to be performed. The programmer spends more time manipulating registers and considering instruction sequences than solving the actual problem.

To overcome the difficulties associated with assembly languages, high-level or procedure-oriented languages were developed. High-level languages permit programmers to describe tasks in a form that is problem-oriented rather than computer-oriented. A programmer can formulate problems more efficiently in a high-level language.

The instructions written in a high-level language are called statements. The statements more closely resemble English and mathematics as compared to mnemonics in assembly languages. Examples of lat-est high-level languages are Java, C, C++, C#, Python, Visual Basic, Delphi, Perl, Ruby, PHP, etc.

High-level languages are independent of computer architecture. The same program will run on any other computer which has a compiler for that language. The compiler is machine-dependent but not the language.

Advantages of High-Level Languages

High-level languages have the following advantages over assembly and machine languages:

Machine Independent: High-level languages are machine-independent. It means that a company changing computers – even to the one from a different manufacturer – will not be required to rewrite all the programs that it is currently using. In other words, a program written in a high-level language can be run on many different types of computers with very little or practically no modification.

Easy to Learn and Use: These languages are very similar to the English language used by us. Hence, they are easy to learn and use. The programmer need not worry about how to store the numbers in the computer, where to store them, what to do with them, etc.

Few Errors: The programs written in high-level languages are much less prone to errors since the programmer need not write all the small steps carried out by the computer. Therefore, he is much less likely to make an error. The computer takes care of all the little details and will not introduce any error of its own unless something breaks down. Further¬more, compilers are so designed that they automatically catch and point out the errors made by the programmer. Hence, diagnostic errors, if any, can be easily located and corrected by the programmer.

Lower Program Preparation Cost: Writing programs in high-level languages require less time and effort, which ultimately leads to lower program preparation costs. Generally, the cost of all phases of program preparation (coding, debugging, testing, etc.) is lower with a high-level language than with an assembly language or a machine language.

Better Documentation: A high-level language is designed in such a way that its instructions may be written similar to the language of the problem. Thus, the statements of a program written in a high-level language can easily be understood by a person familiar with the problem. For the documentation of such programs, very few or practically no sepa¬rate comment statements are required.

Python Programming – Introduction to Programming chapter 1 img 4

Easier to Maintain: Programs written in high-level languages are easier to maintain than assembly language or machine language programs. This is mainly because they are easier to understand, and hence it is easier to locate, correct, or modify instructions as and when desired. Insertion or removal of certain instructions from a program is also possible without any complication. Thus, major changes can be incorporated with very little effort.

Disadvantages of High-Level Languages

Lower Efficiency: The programs written in high-level languages take more time to execute and require more computer main memory.

Lack of Flexibility: Since the automatic features of high-level languages are always not under the control of the programmer, the programs written in these languages are less flexible as compared to those written in assembly languages. An assembly language provides programmers access to all the special features of the machine they are using. Certain types of operations, which are easily programmed using the assembly language, are impractical to attempt using a high-level language. This lack of flexibility means that some tasks cannot be done in a high-level language, or can be done only with great difficulty.

Source and Object Language

The language in which a programmer writes programs is called source language. It may be a high-level language or an assembly language. The language in which the computer works is called object language or machine language. Machine codes are also known as object codes. A program written in a source language is called a source program. When a source program is converted into machine code by an assembler or compiler, it is known as an object program. In other words, a machine language pro¬gram ready for execution is called an object program.

Recommended Reading On: Java Program to Find Sum of First and Last Digit of a Number

Leave a Reply

Your email address will not be published. Required fields are marked *