Wednesday, July 21, 2010

Assembly Language Tutorial

Assembly Language Tutorial

Programming is an art.

There are plenty of compilers around to program.The famous C,the beautiful Java,the useful HTML,the elusive oracle and the simple .net…

So why assembly language????

Those of you who ever had a go at cracking and all other stuff will have a readymade answer to it.No cracking without a crack at assembly language.

If u are not in the cracking Biz why do you need it?

No programmer is complete without mastery over assembly language..your program ruins slow or there is some deep glitch.you work on it day and night and still the glitch remains a glitch.here comes the assembly language.You analyse the processes and come at a diagnosis…

Assembly language makes you powerful.it is the base on which everything is built.

Without assembly language you will always remain a novice.whatever you build or achieve.

So lets start the learning process.

You must have heard that the—-

• Assembly language is hard to learn and understand

• Its difficult to debug

• It’s a messy outfit

• Why do you want to save a little space using assembly language when you have so much space?

Believe Me, learning assembly language is easier than most high level languages..

Once you learn assembly language everything else comes naturally..

Assembly language has several benefits:

• Speed. Assembly language programs are generally the fastest programs around.

• Space. Assembly language programs are often the smallest.

• Capability. You can do things in assembly which are difficult or impossible in HLLs (High Level Language).

• Knowledge. Your knowledge of assembly language will help you write better programs,

even when using HLLs (High Level Language).

===========================================================

LESSON 1 -

THE REGISTERS AND SEGMENTS

unlike other languages there is no predefined commands like "writeln", "printf",…

assembly language doesnot provide those tools for you

So how does it work>?

Ok.. first they have predefine registers :

/* all of these are the data holders
AX - accumulator index

BX - Base index

CX - Count index

DX - Data index
*/

/* all of these are the pointing and index storage registers
SP - Stack pointer

BP - Base pointer

SI - Source index

DI - Destination index

IP - Instruction pointer
*/

/* all of these are segments holder
CS - Code segment

DS - Data segment

SS - Stack segment

ES - Extra segment
*/

FLAGS - Holds some of the function conditions

now to be more specific:

Data registers:

they are the basic registers for all the computer calcs, and position

each of the registers is 16bit and they are divided into two registers

high and low which are 8 bit :

AX - ah (high), al (lo)

BX - bh (high), bl (lo)

CX - ch (high), cl (lo)

DX - dh (high), dl (lo)

high is MSB - most significent byte

lo is LSB - least significent byte

Pointing registers:

each of these registers has an unique job :

SP - is the offset of the stack (-n-)

BP - a pointer for the stack (-n-)

SI - is the source index, uses as an offset in memory transfers

DI - is the destination index, uses as an offset in memory transfers

IP - is the offset of the current instruction (-n-)

(-n-) means don't change unless you know what your'e doing

Segment registers:

CS - is the segment of the code (-n-)

DS - is the segment (usually) of the data

SS - is the segment for the stack (-n-)

ES - is an extra segment, uses for memory transfers

Flags, will be disscussed later

Assembly language works with segments .each segment has a maximum limit which is 64K,

Now we create a segment.

when we have a segment we have to give it a definition,

For this we need the command "Assume" which gives each one of the segments

registers it's default segment,

Here is a typical segment—-

Sseg segment ; a semicolon (;) is a remark and will not be compiled

db 10 dup (?)

ends ; each segment has a name and the "segment" after it

; when we finished to define stuff in the segment

; we close it with ends (end segment)

Dseg segment

ends

Cseg segment

assume cs:cseg,ds:dseg,ss:sseg

ends

end

know as we saw segment is built as follow :

Name Segment

.

.

.

Ends

know in the dseg all the data will be stored, in the sseg the stack

and in the cseg the code.

Reference:
http://assembly.co.nr/

No comments: