Tuesday, July 5, 2011

TRANSLATION SEQUENCE

THE PROGRAM TRANSLATION SEQUENCE
In developing a software program to accomplish a particular task, the program developer chooses an appropriate language, develops the algorithm (a sequence of steps, which when carried out in the order prescribed, achieve the desired result), implements this algorithm in the chosen language (coding), then tests and debugs the final result. There is also a probable maintenance phase.
When you write a program in a source language such as Pascal or C, the program statements (in the source text file) needs to be converted into the binary bit-patterns which make sense to the target processor (the processor on which the software will be run). This process of conversion is called translation.


ASSEMBLERS
Assemblers are programs that generate machine code instructions from a source code program written in assembly language. The features provided by an assembler are,
  • allows the programmer to use mnemonics when writing source code programs.
  • variables are represented by symbolic names, not as memory locations
  • symbolic code is easier to read and follow
  • error checking is provided
  • changes can be quickly and easily incorporated with a re-assembly
  • programming aids are included for relocation and expression evaluation.
What is an assembler mnemonic?
A mnemonic is an abbreviation for a machine code statement. During the translation phase, each mnemonic is translated to an equivalent machine code instruction.
MOV AX, 0ffh
is translated to the binary bit patterns
10111000 (this means MOV AX)
11111111 (this is ff hexadecimal)
00000000 (this is 0)

What are assembler pseudo-ops?
Assemblers also provide keywords called pseudo-ops. These keywords provide directions (hence they are also called assembler directives) to the assembler. Pseudo-ops do not generate machine instructions. The following pseudo-op
DB 'ab'
allocates and initializes a byte of storage for each character of the string, thus two bytes will be allocated, one initialized to the character 'a' whilst the other byte would be initialized to the character 'b'.

What type of code does an assembler generate?
The assembler does not normally generate executable code. An assembler produces an object code file that must be further processed (linked) in order to generate a file that can be executed directly.
An example assembly language program
; H means hexadecimal values
  ORG 0100H ;This program starts at address 0100 hex
STATUS:  DFB 23H  ;This byte is identified as STATUS, and is
    ;initialized to a value of 23 hex
CODE:  LDAA STATUS ;The label called CODE is identified as a
    ;machine code instruction which loads the
    ;A accumulator with the contents of the
    ;memory location associated with the label
    ;STATUS, ie, the value 23
  JMP CODE ;Jump to the address associated with CODE

WHAT IS A HIGH LEVEL LANGUAGE?
In a HLL, one English type statement represents a sequence of machine code statements. Examples of a high level language are Pascal, Basic and C. High level languages are useful in developing complex software, as they support complex data structures, and increase programmer productivity (the number of lines of code generated per hour). Unlike assembly language, it also means that the programmer does not need to learn the instruction set of each computer being worked with.
All HLL statements must be converted to machine code in order for a processor to run them. There are two ways in which high level language statements are converted into machine code, either at runtime (interpreted) or before runtime (compiled).

WHAT IS AN INTERPRETER?
The source code program is run through a program called an interpreter. Each line of the program is sent to the interpreter that converts it into equivalent machine code instructions. These machine code instructions are then executed. The next source line is then fetched from memory, converted and executed. This process is repeated till the entire program has been executed.
Examples of interpreted languages are BASIC (Beginners All Purpose Symbolic Instruction Code) and Java.
An example BASIC program
10 REM Program by ..................
 20 REM Initialize variables
 30 Time = 6
 40 Speed = 500
 50 Distance = Time * Speed
 60 PRINT Distance
 70 END

WHAT DOES A COMPILER DO?
Compilers accept source programs written in a high level language and produce object code programs that are then linked with standard libraries to produce an executable file. Compilers generate code that is reasonably fast, but is target specific (it only runs on a particular computer system).
The source program is written using an editor. Most compiled languages do not use line numbers.The example on the right is a C program.  
#include 
main {
 printf("Hello world\n');
 return 1;
}
Once the program has been written using the appropriate source statements, it is then passed to a compiler that converts the entire program into object code. The object code cannot be run on the computer system, so the object code file is then sent to a linker that combines it with libraries (other object code) to create an executable program. Because the entire program is converted to machine code, it runs very quickly.

WHAT DOES A LINKER DO?
The BASIC interpreter already has its own libraries for Input and Output (I/O), so BASIC programs don't need linking. The source program is converted directly into executable code.
Compiled languages (as well as assembled) need both linking and loading. The output of compilers and assemblers are stored in an intermediate format called object code. This is stored as a file on disk. The object code must be combined with other object code files or libraries (special object code files) before execution.
The linker combines the programs object code with the runtime object code files (for handling files, screen output, the keyboard etc) into an executable format.
The types of files that exist at each phase of the program translation sequence are,
myprog.c source code program
myprog.obj object code produced by compiler
myprog.exe executable file produced by linker

No comments:

Post a Comment

This is Good Computer Information Blog.they will give
best information about computer.