Introduction of Programming Languages
•Computers have no commonsense and they cannot think.
•Need clear-cut instructions to tell them what to do, how to do and when to do?
•A set of instructions to carry out these functions is called a computer program.
•A set of instructions provides a way to instruct a computer to perform certain operations.
•A programming language is a standardized communication techniques for giving instructions to a computer.
•English is a natural language. It has words, symbols and grammatical rules.
•A programming language also has words, symbols and rules of grammar.
•The grammatical rules are called syntax.
•Each programming language has a different set of syntax rules.
But there is a difference!
•Computer languages lack ambiguity and vagueness. In English sentences such as I saw the man with a telescope (Who had the telescope?) or Take a pinch of salt (How much is a pinch?) Time flies like an arrow ??In a programming language a sentence either means one thing or it means nothing. What is Programming ?
•Programming is a Science:
Because it implement the algorithms describe by mathematics and science.
•Programming is a Skill:
Because it requires design efforts.
•Programming is an Engineering:
Because it requires a tradeoffs between program size, speed, time (required for development and debugging) and maintainability among many solutions.
•Programming is an Art:
It requires creativity and employ imagination.
Broad Classification of Computer Languages
•A programming language is a standardized communication techniques for giving instructions to a computer.
Types of Computer Languages:
•Machine language
•Assembly language
•High-level language
Machine Language:
• It is only language of a computer understood by it without using a translation program.
• Machine Language normally written as strings of binary 1s and 0s.
• Machine Language is written using decimal digits if the circuitry of the computer being used permits this .
OPCODE
(operation code)
OPERAND
(Address/Location)
•OPCODE tells the computer which operation to perform from the instruction set of the computer
•OPERAND tells the address of the data on which the operation is to be performed
A Sample Machine Language Program
001000000000001100111001 10001471
001100000000010000100001 14002041
011000000000011100101110 30003456
101000111111011100101110 50773456
000000000000000000000000 00000000
In Binary In Decimal
(Difficult to read and understand) (Easier to read and understand)
Advantages & Limitations of Machine Language
Advantage of Machine Language
Can be executed very fast
Limitations of Machine Language
• Machine Language is machine Dependent.
• Machine Language difficult to program.
• Machine Language is error prone.
• Machine Language is difficult to modify.
Assembly/ Symbolic Language
•Programming language that overcomes the limitations of machine language programming by:
•Using alphanumeric mnemonic codes instead of numeric codes for the instructions in the instruction set
– e.g. using ADD instead of 1110 (binary) or 14 (decimal) for instruction to add
•Allowing storage locations to be represented in form of alphanumeric addresses instead of numeric addresses
– e.g. representing memory locations 1000, 1001, and 1002 as FRST, SCND, and ANSR respectively
•Providing pseudo-instructions that are used for instructing the system how we want the program to be assembled inside the computer’s memory
– e.g. START PROGRAM AT 0000; SET ASIDE AN ADRESS FOR FRST
Assembler
•Software that translates as assembly language program into an equivalent machine language program of a computer
Assembly Input language program
Assembler
Output Machine
language
program
One-to-one correspondence
(Source Program) (Object Program)
An Example of Assembly Language Program
Mnemonic Opcode Meaning
HLT 00 Halt, used at the end of program to stop
CLA 10 Clear and add into A register
ADD 14 Add to the contents of A register
SUB 15 Subtract from the contents of A register
STA 30 Store A register
A subset of the set of instructions supported by a computer.
An Example of Assembly Language Program
START PROGRAM AT 0000
START DATA AT 1000
SET ASIDE AN ADDRESS FOR FRST
SET ASIDE AN ADDRESS FOR SCND
SET ASIDE AN ADDRESS FOR ANSR
CLA FRST
ADD SCND
STA ANSR
HLT
Sample assembly language program for adding two numbers and storing the result
An Example of Assembly Language Program
Symbolic name Memory location
FRST 1000
SCND 1001
ANSR 1002
Mapping table set up by the assembler for the data items of the assembly language program
An Example of Assembly Language Program
Memory Contents Comments
location
Opcode Address
0000 10 1000 Clear and add the number stored at FRST to A register
0001 14 1001 Add the number stored at SCND to the contents of A register
0002 30 1002 Store the contents of A register into ANSR
0003 00 Halt
1000 Reserved for FRST
1001 Reserved for SCND
1002 Reserved for ANSR
Equivalent machine language program for the assembly program language.
Advantages of Assembly Language Over Machine Language:
It is easier to understand and use.
It is easier to locate and correct errors.
It is easier to modify.
Three is no worry about addresses.
It is easily relocatable.
Its efficiency of machine language.
Limitations of Assembly Language:
It is machine dependent.
It is knowledge of hardware required.
It is machine level coding .
Typical Uses of Assembly Language
Mainly used today to fine-tune important parts of programs written in a high-level language to improve the program’s execution efficiency.
Assembly Languages with Macro-Instructions
Any assembly language instruction that gets translated into several machine language instructions is called a macroinstruction.
Several assembly languages support such macro instructions to speed up the coding process.
Assemblers of such assembly languages are designed to produce multiple machine language instructions for each macro instruction of the assembly language.
FAQ:
1. What is programming language? Compare it with natural language.
2. Classify programming languages into different groups with examples.
3. Explain advantages and limitations of Machine languages.
4. Explain advantages and limitations of Assembly languages.
5. Explain similarities and differences between Machine language and Assembly language.
6. Explain advantages and disadvantages of high level languages.
7. Differentiate between high level languages and low level languages.
Thank You!!!
Deep99Notes