2.Programming Languages
2.Programming Languages
Programming
Topics
Introduction to Programming Languages
Compliers/Interpreters
Major differences between Machine Language and High Level
Language
Major differences between Assembly Language and High
Level Language
Execution of a Program
Compilation Stages
Working of Assembler
Object file format
Symbol table
Linker
Loader
Introduction to Programming Languages
Programming language is a language used for expressing a set of
computer instructions.
It consists of necessary symbols, characters and grammar rules which
allows programmers to communicate with computers.
Programming
Languages
Advantages:
• Can be typed directly and executed
• No translation program is required
Disadvantages:
• Difficult to remember m/c instructions
• Difficult to understand, modify and debug errors
• Difficult to remember addresses of data and instructions
• Lack of portability
Introduction to Programming Languages
Assembly Language:
Characteristics:
• Uses symbolic instructions (mnemonics)
• Second generation programming language
Assembler
Source program Object program
(Assembly Language) (Machine Language)
Advantages:
• Easy to remember opcodes
• Easy to understand program
• Easy to write, modify and debug programs as compared to
machine language
• Need not remember addresses of operands and instruction
locations
Disadvantages:
• Not standardized
• Less efficient than machine language
• Mnemonics are machine dependent
Introduction to Programming Languages
High level language
Characteristics:
• Third generation language
• Machine independent
• Easily understood by programmer
Translator
Source program (Interpreter/Compiler) Object program
(HLL) (Machine Language)
Introduction to Programming Languages
Examples of Specific purpose HLL are:
Advantages:
Easy to understand
Portable
Standardized
m/c independent
Easy to write, modify and debug
Disadvantages:
Less efficient than low level languages
Compiler and Interpreter
Major differences between compiler and interpreter
are tabulated below:
Compiler Interpreter
Takes entire HLL Takes one statement at a
program and translates time as input and
to m/c language translates to m/c language
All errors are listed and Errors are displayed only
displayed for the current statement
Debugging is faster Debugging is slower
Requires more memory Requires less memory
Costlier Cheaper
Major Differences between Machine
Language and High Level Language (HLL)
Machine Language HLL
Uses 0 and 1 Uses English alphabets
Instruction is sequence of 0’s Instruction is English like
and 1’s statement
m/c dependent m/c independent
Not standardized Standardized
Difficult to understand, write, Easy to understand, write,
debug and modify debug and modify
Efficient Less efficient
Code written in m/c language Code written in HLL cannot
can be directly executed be directly executed
Major Differences between Assembly
Language and High Level Language (HLL)
Compiler
Assembler
Object code: m/c language module Object code: Library routine (m/c language)
Linker
Loader
Note: The message Syntax error indicates that the phrase analyzed does not
follow the grammar of the language.
Compilation Stages
The semantic analysis stage
traverses the syntax tree, checking another aspect of program
correctness. The analysis consists principally of type inference,
which if successful, produces the most general type of an
expression or declaration.
Note: Type error messages may occur during this phase. This stage also
detects whether any members of a sequence are not of type unit. Other
warnings may result, including pattern matching analysis (e.g. pattern matching is
not exhaustive, part of pattern matching will not be used).
Identifier Expression
Sum +
Text Segment :
contains m/c instructions
Data Segment :
contains binary representation of data in assembly file
Relocation Information:
identifies instructions and data that depend on absolute addresses
Symbol Table:
Associates addresses with external labels and lists unresolved references
Debugging Information:
to debug the errors
Symbol Table
In a compiler:
a data structure used by the compiler to keep track of identifiers
used in the source program. This is a compile-time data structure.
Not used at run time.
In object files:
a symbol table (mapping var name to address) can be build into
object programs, to be used during linking of different object
programs to resolve reference.
In executables:
a symbol table (again mapping name to address) can be included in
executables, to recover variable names during debugging.
Execution of a program
Source File 1 Source File 2 … Source File n
Linker
Executable Program
File Library
Loader
Memory
Linker
Tools that merges the object files produced by separate
compilation or assembly and creates an executable file
Steps:
• Read executable file’s header to determine the size of text
and data segments
• Creates a new address space for the program
• Copies instructions and data into address space
• Copies arguments passed to the program on the stack
• Initializes the m/c registers including stack pointer
• Jumps to a startup routine that copies the program’s
arguments from the stack to registers and calls the
program’s main routine