2 The Art of Assembly Language Programming
2 The Art of Assembly Language Programming
Assembly language programming tools :Software tools are used for editing, assembling, linking,
and debugging assembly language programming. These tools are briefly explained below.
Editor :
1. It is software which allows you to type and edit assembly language program statements.
2. It enables you to create, edit, save ,copy and make modification in the source file.
3. The file created in editor is an ASCII format and is known as source file.
4. You can use NotePad , Norton editor,Dos editor (EDIT) any other editor that produces plain ASCII text
files. You can also use the ConTEXT editor.
Assembler :
1. It is a programming tool used to convert assembly program to machine code.
2. It accepts source file .asm
3. it generates the object file. .OBJ
4. It also creates list file (.LST) AND cross refernce file (.CRF).
5. These include MASM (Macro Assembler from Microsoft), TASM (Turbo Assembler from Borland),
NASM (Netwide Assembler for both Windows and Linux), and GNU assembler distributed by the
free software foundation
Linker :
1. It is a programming tool used to convert object code into executable code.
2. It requires input as object code.
3. It combines more than one separated assembled modules into one executable module such as two more
assembly program or an assembly language with a c program.
4. It generates .EXE file.
Debugger:
1. It is programming tool.
2. It is used for tracing/locating and correcting errors.
3. It allows the execution of .EXE program in single step mode under the control of user.
M.A.Ansari Page 1
Assembler directives :
These are the statements that direct the assembler to do something.
They indicate how an operand is treated by the assembler and how assembler handles the program.
They also direct the assembler how program and data should be arranged in the memory.
They do not generate any machine code.
Directives are classified into following categories.
1) Data definition and storage allocation directives
2) Program organization directives
3) Value returning attribute directives
4) Data control directives
5) Procedure directives
6) Macro directives
Data definition and storage allocation directives :
Data definition directives are used to define the program variable and allocate a specified amount of memory to
them. They are as follows;
1) DB(Define data Byte) - DB directive is used to declare a byte type. Variable size of variable is 1 byte.
General form :
Name_Of_Varible DB Initialiation_value(,s)
2) DW (Define data Word) - The DW directive is used to define a variable of type word. Variable size of
variable is 2 byte.
General form :
Name_Of_Varible DW Initialiation_value(,s)
M.A.Ansari Page 2
General form :
Name_Of_Varible DD Initialiation_value(,s)
General form :
Name_Of_Varible DQ Initialiation_value(,s)
General form :
Structure_Name STRUCT
………………..
………………..
………………..
………………..
Structure_Name ENDS
7) EQU (Equate to) - This EQU directive is used to give a name to some value or to a symbol. Each time
the assembler finds the name in the program, it will replace the name with the value or symbol you given
to that name.
General form :
Symbol_Name EQU eXPRESSION
Example: FACTOR EQU 03H
8) EVEN –Align as even memory location : This EVEN directive is used to inform the assembler to
increment the location counter to the next even memory address if it is not already in the even address.
General Form:
EVEN
Example : DATA SEGMENT
M.A.Ansari Page 3
Name db ‘xyz’
EVEN
Age db 20
DATA ENDS
9) ALIGN :Alignment of memory addresses:
The directive ALIGN is used to force the assembler to align the next data item or instruction
according to given value.
General Form:
ALIGN Numeric_value
The number must be a power of 2 such as 2,4,8,16.
Example :
ALIGN 4
10) ORG-Originate : The directives ORG assigns the location counter with the value specified in the
directive. It helps in placing the machine code in the specified location while translating the instructions
into machine codes by the assembler.
General Form:
ORG Numeric_value
Example:
ORG 100H
2) SEGMENT and ENDS directives: They are used to mark the beginning and end of the particular
segment.
Syntax: segment_name SEGMENT
; code goes here
segment_name ENDS
For example, data segment can be declared as:
DATA SEGMENT
X DB 10H
Y DB 20H
DATA ENDS
3) END : The directive END is used to inform assembler about the end of the program.
Syntax: END
4) .CODE:Simplified CODE segment directive : This simplified segment directive defines the code
segment. All executable code must be defined in this segment.
General form:
.CODE
5) .DATA : Simplified DATA segment directive : This simplified segment directive defines the data
segment. All data definition and declaration must be placed in this segment.
General Form:
.DATA
6) .STACK: Simplified STACK segment directive :This simplified segment directive define the stack
segment and default size of the stack segment is 1024 bytes.
General Form:
.STACK
M.A.Ansari Page 4
7) .MODEL :Memory model declaration for segments : This simplified segment directive creates
default segments.
General Form:
.MODEL memory_models
Memory models are
.SMALL : All data in one segment and all code in one segment.
.MEDIUM: All data in one segment but code in more than one segment.
.COMPACT : Data in more than one segment but code in one segment.
.LARGE : both data and code in more than one segment, but no array may exceed 64 kbytes.
.HUGE : both data and code in more than one segment, but array may exceed 64 kbytes.
M.A.Ansari Page 6