You are on page 1of 6

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.

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.

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.

Program development steps :


1) Defining the problem: The first step in the program development is the careful analysis of problem. The
objective of the program should be clear.
2) Algorithm: It is the step wise procedure designed to perform operations according to the program which
will lead to correct results.
3) Flowchart: It is the graphical representation of the program operation.
4) Initialization checklist: In this step, variables, constants and various parts of the system such as
segment registers, stack, flags etc. are initialized properly.
5) Choosing instructions: It includes selecting the proper instructions that will perform the
desired operations.
6) Converting algorithm to assembly language program : In this step , the instructions are arranged in
the proper sequence according to algorithm and then converted into machine language so that the
desired output can be obtained.
Algorithm and flow chart :
Algorithm is step by step procedure designed to perform an operation and which will lead to final result.
FlowChart: It is graphical representation of algorithm. Symbols used to draw flowchart are :

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_VaribleDBInitialiation_value(,s)

Example: PRICE1 DB 49h


PRICE2 DB ?

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_VaribleDW Initialiation_value(,s)

Example: PRICE1 DW 1234h


PRICE2 DW ?
3) DD (Define DoubleWord) - This directive is used to define a variable of type double. Variable size of
variable is 4 byte.

Page 2
General form :
Name_Of_Varible DDInitialiation_value(,s)

Exmaple :PRICE1 DD 11223344H


PRICE2 DD ?
PRICE3 DD 5 DUP(0)
4) DQ (Define Quad Word) - This directive is used to define a variable of type quad word. Variable size
of variable is 8 byte.

General form :
Name_Of_Varible DQInitialiation_value(,s)

Exmaple :PRICE1 DQ 1122334455667788h


PRICE2 DQ ?
PRICE3 DQ 5 DUP(0)
5) DT (Define Ten Bytes) - This directive is used to define a variable which is 10 bytes in length.
General form :
Name_Of_VaribleDTInitialiation_value(,s)

Exmaple :PRICE1 DT 00112233445566778899h


PRICE2 DT ?
PRICE3 DT 5 DUP(0)
6) STRUCT:Structure Declaration : The directive STRUCT is used to declare the data type which is
a collection of primary data types (DB,DW,DD).

General form :
Structure_Name STRUCT
………………..
………………..
………………..
………………..
Structure_NameENDS

Exmaple :STUDENT STRUCT


STUD_NAME DB 15 DUP(0)
STUD_ROLLNO DB 01H
STUD_PER DB ?
STUDENT 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
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

PROGRAM ORGANIZATION DIRECTIVES : These directives are used to organize program.


1) ASSUME directive : It is used to give logical names to the different
segments. e.g. Assume cs:code, ds:data, ss:stack

2) SEGMENT and ENDS directives: They are used to mark the beginning and end of the particular
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

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.

Value Returning Attribute Directive:


1) LENGTH: The directive LENGTH informs the assembler about the number of the elements in a
data items such as array.
General Form:
LENGTH Variable_name
Example:
MOV CX, LENGTH ARRAY
This statement, when assembled, will substitute the length of the array ARRAY in bytes, in the instruction.
2) SIZE : The directive SIZE is same as LENGTH except that it returns the number of bytes allocated to
the data item instead of the number of elements in it.
General Form:
SIZE Variable_name
Example:
MOV CX, SIZE ARRAY
3) OFFSET: The directive OFFSET informs the assembler to determine the displacement of the specified
variable with respect to the base of the segment.
General Form:
OFFSET Variable_name
Example:
MOV SI, OFFSET ARRAY
4) TYPE - TYPE operator instructs the assembler to determine the type of a variable and determines the
number of bytes specified to that variable.
General Form:
TYPE Variable_name
Example:
MOV DX, TYPE NUM

PROCEDURE DEFINITION DIRECTIVE :


PROC and ENDP directives :
They are used to define procedures in assembly language programs. They mark the beginning
and end of the procedure. The term near or far is used to specify the type of the procedure.
Syntax: Proc_name PROC <NEAR/FAR>
;body of the procedure
RET
Proc_name ENDP
Observe ENDP is always preceded by either RET or IRET instruction.
MACRO DEFINITION DIRECTIVES :
Page 5
MACRO and ENDM directives:
They are used to define macros in assembly language programs. They mark the beginning and end of the
MACRO.
Syntax: Macro_name MACRO <set of parameters>
.
. ;body of the macro
ENDM
Data Control Directives :
1) PUBLIC - The PUBLIC directive is used to instruct the assembler that a specified name or label will
be accessed from other modules.
General Form:PUBLIC variable1,variable2,……………….variable N
Example:PUBLIC DIVISOR, DIVIDEND
; these two variables are public so these are available to others modules.
2) EXTRN: External and PUBLIC:
The directive EXTRN informs the assembler that the data items or label following the directive will be used in
a program module, which is defined in the other program modules.
General Form:Extrn variable1,variable2,……variable N
Example :EXTRN msg:byte, name:word
3) PTR -Pointer : The directive PTR is used to indicate the type of the memory access i.e. BYTE/WORD/DWORD.
General Form :
PTR Variable_Name
Example:
INC BYTE PTR [DI]
ADD AL,BYTE PTR NUM
4) LOCAL: The lables, variables, constants or procedures declared LOCAL in a module are to be used
only by that modul.
General Form:LOCAL variable_Name

5) GLOBAL :The labels, variables, constants or procedures declared GLOBAL may be used by other
modules of the program. Once a variable is declared GLOBAL, it can be used by any module in
the program. The following statement declares the procedure ROUTINE as a global label.
ROUTINE PROC GLOBAL
File Inclusion Directives:
INCLUDE - This INCLUDE directive informs the assembler to include the statement defined in the include
file. The name of the include file follows the statement INCLUDE.
General form: INCLUDE <file path specified with file name>
Example : INCLUDE C:\TASM\MACRO.LIB
INCLUDE C:\TASM\MYPROC.LIB

Difference between instructions and assembler directives :


Assembler Directives Instructions
It directs the assembler to perform certain actions It is the operation performed by processor.
during assembly phase.
Assembler directive does not create any machine Assembler instruction generates machine code.
code.
It does not contribute to program size. It contributes to program size.
e.g. assume,proc,endp,ends,segment etc. E.g. add,sub,mul,div etc

Page 6

You might also like