Saturday, August 2, 2008

Assembley langauge

Introduction :-
An assembly language is a low-level language for programming computers. Assembly language is the most basic programming language available for any processor. Assembly language is also the most powerful computer programming language available, and it gives programmers the insight required to write effective code in high-level languages. Learning assembly language is well worth the time and effort of every serious programmer. With assembly language , a programmer works only with operations implemented directly on physical CPU. Assembly language lacks high-level conveniences such as variables and functions, and it is not portable between various families of processors.
Assembly language is not a single language, but rather a group of languages. Each processor family (and sometimes individual processors within a processor family) has its own assembly language.

Why learn assembly language?
The first reason to work with assembler is that it provides the opportunity of knowing more the operation of your PC, which allows the development of software in a more consistent manner.
The second reason is the total control of the PC which you can have with the use of the assembler.
Another reason is that the assembly programs are quicker, smaller, and have larger capacities than ones created with other languages.
Assembly language allows an ideal optimization in programs, be it on their size or on their execution.

Comparison of Assembly and High level language :-

The assembly language contains more instruction than High level language. In the assembly language program written on one computer can't be used on any other computer. But In high level language the program written on one computer can be used on other computer . In Assembly language program runs faster to produce the desired result as compared to high level language. The computation in high level language program is less than assembly language.
Syntax
Assembly language has two main syntax branches: AT&T syntax and Intel syntax, originally used for the documentation of the x86 platform. The Intel syntax is dominant in the Windows world. In the Unix/Linux world, both are in used .Here is a summarized list of the main differences between Intel syntax and AT&T syntax:
In AT&T syntax, the source comes before the destination, in the opposite style from Intel syntax
In AT&T syntax, the opcodes are suffixed with a letter indicating the size of the operands (e.g. "l" for dword, "w" for word, and "b" for byte)
In AT&T syntax, immediate values must be prefixed with a "$", and registers must be prefixed with a "%".
In AT&T syntax, effective addresses use the general syntax DISP(BASE,INDEX,SCALE), whereas in Intel syntax, effective addresses use variables, and need to be in square brackets; additionally, size keywords like 'byte', 'word' or 'dword' have to be used.

Basic Concepts of Assembly Language
Assembler structure:- In assembly language code lines have two parts, the first one is the name of the instruction which is to be executed, and the second one are the parameters of the command. For example: add ah bh
Here "add" is the command to be executed, in this case an addition, and "ah" as well as "bh" are the parameters.



Information Units :- In order for the PC to process information, it is necessary that this information be in special cells called registers. The registers are groups of 8 or 16 flip-flops. A group of 16 bits is known as word; a word can be divided in groups of 8 bits called bytes, and the groups of 4 bits are called nibbles.
Numeric systems:- The numeric system we use daily is the decimal system, but this system is not convenient for machines since the information is handled codified in the shape of on or off bits.
Converting binary numbers to decimals :-
When working with assembly language we come on the necessity of converting numbers from the binary system, which is used by computers and the decimal system used by people. The binary system is based on only two conditions or states, be it on(1) or off(0), thus its base is two.
For the conversion we can use the positional value formula: For example Binary: 1 1 0 0 1
Decimal: 1*2^0 + 1*2^1 + 0*2^2 + 0*2^3 + 1*2^4 = 1 + 2 + 0 + 0 + 16 = 19
Converting decimal numbers to binary :-
Let us take for example the decimal number of 43.
43/2=21 and its residue is 1
21/2=10 and its residue is 1
10/2=5 and its residue is 0
5/2=2 and its residue is 1
2/2=1 and its residue is 0
1/2=0 and its residue is 1
Building the number from the bottom , we get that the binary result is
101011

Hexadecimal system
On the hexadecimal base we have 16 digits which go from 0 to 9 and from the letter A to the F, these letters represent the numbers from 10 to 15. Thus we count 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E, and F.
The conversion between binary and hexadecimal numbers is easy. The first thing done to do a conversion of a binary number to a hexadecimal is to divide it in groups of 4 bits, beginning from the right to the left. In case the last group, the one most to the left, is under 4 bits, the missing places are filled with zeros.
Use of assembly language:-
Historical perspective
Historically, a large number of programs have been written entirely in assembly language. Operating systems were almost exclusively written in assembly language until the widespread acceptance of C in the 1970s and early 1980s. Many commercial applications were written in assembly language as well, including a large amount of the IBM mainframe software written by large corporations. Most early microcomputers relied on hand-coded assembly language, including most operating systems and large applications. In a more commercial context, the biggest reasons for using assembly language were size (and hence speed), and reliability.

Typical Applications
Hard-coded assembly language is typically used in a system's boot ROM . This low-level code is used , among other things , to initialize and test the system hardware prior to booting the OS, and is stored in ROM . Assembly language is also valuable in reverse engineering , since many programs are distributed only in machine code form , and machine code is usually easy to translate into assembly language and carefully examine in this form, but very difficult to translate into a higher-level language. Tools such as the interaction Disassembler make extensive use of disassembly for such a purpose.

No comments:

Post a Comment