Copyright © 2010 K-Tutorials.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

The contents are updated or revised periodically; the document version will be changed based on the update or revision of the contents.

Document version: 1.0

Thursday, October 27, 2011

Programming Fundamentals

Programming

Programming is a process of writing instructions in a language that can be understood by the computer so that a desired task can be performed.The computer can understand only machine language and programming in machine language is very difficult job or tedious.

Programming Languages

A programming language is an artificial language designed to express computations that can be performed by a machine particularly a computer. Programming languages can be used to create programs that control the behavior of a machine. Many programming languages have same form of written specification of their Syntax (form or format) and Semantics (meanings).

A programming language is a notation for writing programs, which are specifications of a computation or algorithm.

All programming languages have some primitive building blocks for the description of data and processes or transformations applied to them. Theses primitives are defined by syntactic and sematic rules which describe their structure and meaning respectively.

Categories of Programming Languages
  • Machine Language
  • Low-Level Language
  • High-Level Language

Machine Language

This is the basic language understood by a computer. This language made up of ‘0’s and ‘1’s (that is actually represents the two signal voltages; because computer is a digital electronic device; any digital electronic device uses only two state of signals or voltage levels for their operations; and these devices are operated by digital signal processing (DSP)). A combination of these two digits represents characters, numbers and/or instructions. Machine language is also referred to as binary language. All instructions’ are encoded in binary and they can be executed by the computer directly.

E.g. For machine language representation in binary form is.


1001101010100011001110110011011110110101011111100110

Low-Level Programming Languages

Low-level language is a programming language that provides little or no abstraction from a computer’s instruction set architecture. A low-level language does not need a compiler or interpreter (these are translators used for converting high-level language programs into machine language) to run; the processor for which language was written is able to run the code without using either of these. Assembly language (low-level language) is one step higher than the machine language. Here every machine language instruction is given a symbolic name so the program can be written easily using these names instead of binary instructions.

E.g. Low-level Assembly language instructions

MOV B, C

ADD B

High-Level Programming Languages

A high-level programming language is a programming language with strong abstraction from the details of the computer. A high-level language isolates the execution semantics of computer architecture from the specification of the program, making the process of developing a program simpler and more understandable with respect to low-level language.

E.g. Examples of High-level programming languages are C, C++, JAVA .etc.

System Software

System software assists in the functioning of a computer system and includes the “Operating System (OS)”, Assembler, Interpreter, Compiler, Linker and Loader.

The Operating System is the interface between the user application and system hardware (or Interface between the user and the computer). The Operating System performs important functions like memory management, protection and security.

Translators in Programming Languages

Translators are special type of programs used in converting programs written in various programming languages (low-level and high-level languages) into machine language. There are basically three deferent types of translators; they are:

a. Assembler

The “Assembler” is a translator that converts assembly language code into machine language.

b. Interpreter

The “Interpreter” is a translator that converts source language (high-level language) code or instructions (programs) into executable code (machine language) in a step by step manner. An instruction converted by the interpreter is executed and then the next instruction is taken up for processing.

c. Compiler

The “Compiler” is a translator that coverts the source language (high-level language) code or instructions (programs) into executable code (machine language). The deference between the compiler and the interpreter is that the compiler converts the entire program at once whereas the interpreter does so in parts (one by one). The compiler output is either an assembly program (low-level program) to be run through the assembler or it is in the form of directly executable “Object Code” (in machine code). The object code generated could either be stored as an object module or then loaded for the execution when needed, or it can be loaded directly for immediate execution.

Hence, both interpreter and compilers are used to convert high-level languages into machine language.

Linker

A “Linker” is special type of program sequence performs the important task of linking together several object module. The need for a linker arises when a particular program is made up of several object modules. The original source program may be in any high-level language. Once they are converted into machine code, they must be linked together to be executed as a single program. This task is performed by the linker. The linker has to resolve external references made in the individual modules. The final object module thus created has to be loaded into memory to be executed by the processor.

Loader

The task of loading the linked object modules is performed by the “Loader”. Loader is special type of program sequence that loads the linked object modules by the linker for execution. There are two types of loaders depending on the way the loading is performed: “Absolute Loaders and Relocating Loaders”. Absolute loaders load the executable code (object code or machine code) into memory location specified in the object module. Relocating loaders on the other hand, load the executable code (object code or machine code) into memory locations which are decided at load time. The relocating loaders are performed as they permit the executable to be loaded in any location in the memory. However, they require additional information to be stored in the object module. This is obvious, since the information regarding the relative addresses of the memory locations being accessed in the module has to be stored within it.

Steps Involved In Writing a Program
  1. Write a problem statement for what you want to do
  2. Write an outline, if it is complex
  3. Write up a section in pseudo-code (English instructions)
  4. Write the section in the computer language of your choice (this is called things like source code or a program or a sub-program)
  5. Compile the program. This means use a program called a compiler to translate your program into something the computer can understand (special numbers, often called machine code or assembly language).
  6. Run your program and see if it makes the computer do what you wanted.
  7. If not, fix the program, and compile and run it again.

Software Life Cycle

Software Engineering is defined as a streamlined approach to design and maintenance of computer program using tools that help manage their size and complexity. A collection of related programs are known as the Software.

1. Problem Statement:

The problem statement should be clear and unambiguous. If the statement is not precise and clear, the design and implementation will be erroneous.

2. Problem Analysis and Design:

This is the most crucial step in writing a program. The problem should be analyzed to find the most efficient way in which it can be solved. An “Algorithm” to solve the problem is developed based on the analysis. The algorithm may be expresses as a “Flowchart” or in the form of “pseudocode” (an outline of a program written in a form that can easily be converted into real programming statements). The design specifies the types of data structures used and defines the relationship among the variables.

3. Analysis of Algorithm:

The algorithm should be analyzed to check if it performs the desired action using a reasonable amount of time and memory.

4. Coding:

This step involves coding the algorithm using an appropriate programming language to form a program. The choice of a programming language depends on several factors. Some of them are the availability of efficient translators, programming constructs required by the algorithm, portability constraints, and proficiency of the programmer in the programming language .etc.

5. Documentation:

Documentation is essential to make the program easy to understand. It informs the reader about the working of the program, the mode of interaction and purpose of variables used. A person who reads the program should be able to understand and modify the program using the documentation.

6. Testing:

The program should be tested thoroughly using all possible types of inputs. Testing detects inconsistencies (if any) in the program.

7. Maintenance:

The program may require changes depending on its application. The changes and updates required are performed during maintenance

Some details about programs and their creation process

As we already seen that the steps involved in writing a program. Writing a program in any programming language typically depends on the availability of efficient translators, programming constructs required by the algorithm, portability constraints, and proficiency of the programmer in the programming language .etc.

After selecting a suitable programming language to produce the program….

Source Code >> Object Code >> Executable Code (EXE)

No comments:

Post a Comment