You are on page 1of 21

Unit-2 : The Art of Assembly Language Programming

Unit-2 : The Art of Assembly Language Programming


PROGRAM DEVELOPMENT STEPS

The Programming in Assembly language or for that matter any language follows the specific

sequence of steps which is called as Program Development steps.

It is also called as Program Development Life Cycle (PDLC) or Software Development Life
Cycle (SDLC).

These steps can be listed as follows-

1. Defining the Problem

2. Representation of the Program Logic by-

 Algorithm-Textual representation
 Flowchart Graphical representation

3. Initialization Checklist

4. Coding-Choosing Correct Instructions

5. Converting Algorithms to Assembly Language Programs

The further discussion gives the detailed account of above mentioned steps.

Defining the Problem

 The first step in writing a program is to think very carefully about the problem that
you want the program.
 It is a good idea to write down exactly what you want the program to do and the
order in which you want the program to do it. At this point you do not write down
program statements, you just write the operations you want in general terms.
 It involves finalizing the functionality (What the program is supposed to do) as well
as the Input and Output Specifications (What the program receives from the user
and what the program delivers as result, to the user) Specifying functional and I/O
specs is very crucial part of this Problem definition stage.

1 |2 1
Unit-2 : The Art of Assembly Language Programming

Algorithms

 Once the problem is defined, it is analyzed for the solution. The solution is designed
for the given problem.
 The solution is crystallized and it is required to be represented systematically, by
some specific method or in the standard form.
 Algorithm is defined as the textual mode representation of the specific program logic
designed; in the form of sequence of steps.
 The language used is English like but important control structures are expressed by
specific words such as SET (To initialize the entity or variable) IF or IF.. THEN or IF..
THEN.. ELSE (For specifying decision points and decision paths) etc.
 All operational details are in the form of step by step sequence and it makes easy for
the programmer to understand the flow of the program. The algorithm is
programming language independent.
 In many cases, the program logic and flow is written in the Technical language having
appearance similar to generic programming languages such as C, C++ and called as
Pseudo-code which is another form of Algorithmic expression.

Flowcharts

Another method of standard representation of program logic and flow is a graphical method
called as Flowchart.

Fig. refers to set of symbols used in the Flowcharts -

2 |2 1
Unit-2 : The Art of Assembly Language Programming

 Flowchart is defined as the graphical mode or diagrammatic representation of the


specific program logic designed; in the form of sequence of set of standard symbols.
 The symbols are - Rectangle (representing the Process or Function Step), Diamond
(representing the Decision), Parallelogram (representing the Input/Output
operations), Oval (representing the termination of end-points), Arrowed lines
(representing the flow of the program) and Circle representing the continuation or
connections)

Initialization Checklist

 Besides the instructions constituting main program, there are few additional
instructions that you need to determine before you actually write your program.
 The purpose of these additional instructions is to initialize various parts of the
system, such as segment registers, Flags and Programmable ports.
 The various segment registers are initialized by loading immediate value in it. But
this cannot be done directly because immediate data cannot be loaded directly in
segment registers, e.g. to load Ø500 in DS, the instruction sequence will be –
MOV AX, Ø500 followed by MOV DS, AX.
 Thus before writing a program, the initialization check list should be prepared as
follows.

i. Data segment register DS iii. Extra segment register ES


ii. Stack segment register SS iv. Stack pointer register SP

v. Initialize data variables, Set Interrupt Enable flag


vi. Initialize the constants and Flags, if required any.
 This initialization is necessary as un-initialized registers, ports, flags and variables
may cause problem with the program output and adversely affect the functionality
of the program. The program may not function as desired or may function in a
completely wrong sense.

Choosing Instructions

 Once flowchart or algorithm specifying the program logic is ready, it is needed to be


converted into program statements. Hence, the Instruction set of the processor like

3 |2 1
Unit-2 : The Art of Assembly Language Programming

8086 must be fully known, in order to choose correct instructions that go into the
making of the program.
 We should choose instructions or group of instructions to implement the given step
correctly. If many alternatives are available, we should choose those instructions
that make program smaller in size and more importantly efficient in execution. Also,
consideration must be given to the faster executing Instructions as higher execution
speed improves the efficiency and performance of the program.
 Choice of correct instructions makes the program function correctly and optimally.

Converting Algorithms To Assembly Language

 Every step in the algorithm is converted into program statement using correct and
efficient instructions or group of instructions.
 When all steps are converted in this way, it forms the assembly language program
for given problem. The program is now ready. At the start of program, required
initialization instructions are written.
 The program should have following sequence of Operations -
 Work with the Data Segment
 Initialize Variables and Data structures needed for the program
 Initialize Constants needed
 Declare un-initialized variables, data structures using assembler operators
 Done with Data Segment
 Work with Code Segment
 Initialize required Segment registers
 Initialize Stack by loading the Stack pointer
 Initialize Ports, flags, Chips as per the initialization checklist
 Write Instructions/Set of Instructions for Algorithm/Flowchart steps
 Write Subroutines and Macro, if needed any
 Done with the Code segment
 End program with specified entry point.

4 |2 1
Unit-2 : The Art of Assembly Language Programming

ASSEMBLY LANGUAGE PROGRAM DEVELOPMENT TOOLS

 These tools are programs which help you run the program, to perform some function
on the program you are writing.
 These tools are pre-developed program software that comes to the aid of
developer/programmer for writing, assembling/linking, running, testing and
debugging the program at the various stages in the Program Development Life Cycle.

Editor

 An editor is a program which allows you to create a file containing the Assembly
language statements for your program.
 Program is typed using editor. If there is any typing error, it can corrected by moving
the cursor at that position and correcting/re-typing it. It is needed to store the
Assembly language program source code file with .ASM extension. E.g. MyProg.ASM
 With the Editor tool, we are able to create, edit, modify, list, print, save or update
and delete the Assembly language source code files of the program.
 Examples of the Editor are - EDIT from the DOS, NOTEPAD and WORDPAD of the
Microsoft Windows, are the well known editors.

Assembler

 An assembler is a program used to translate or convert the assembly language


mnemonics of the source code program for instructions to the corresponding binary
codes (machine language) which is called as the Object code of the program.
 It uses the source file with .ASM extension, as an input.
 It works in two pass. On the first pass through source program, the assembler
determines the displacement of named data items, the offset of labels, etc. and puts
this information in a symbol table.
 On the second pass through the source program, the assembler produces the binary
code for each instruction and inserts the offset etc. that is calculated during the first
pass.
 The assembler generates two files as output.

5 |2 1
Unit-2 : The Art of Assembly Language Programming

 The output file is called object file and has extension .OBJ. The object file contains
the binary codes for the instructions and information about the addresses of the
instructions. After further processing, the contents of this file would be loaded into
memory and executed.
 The other file generated by the assemblers is list file having extension .LST. This file
contains assembly instructions and binary codes side by side. This can be used for
testing and debugging.
 Assembler finds the syntax errors. These errors can be corrected by re-editing the
program using editor and then assembled again. This process is repeated to get
syntax error-free source code of the program.
 Examples of Assembler are - MASM, TASM etc.

Linker

 Linker is a program used to join several object files into one large object file and
converts the machine language object code of the program into Executable code of
the program.
 When writing large programs, it is usually much more efficient to divide the large
program into smaller modules. Each module can be individually written, tested, and
debugged, Then, when all the modules work, their object modules can be linked
together to form a large, functioning program.

6 |2 1
Unit-2 : The Art of Assembly Language Programming

 Also the object modules for useful programs like square root program can be kept in
library file and linked into other program as needed.
 The linker produces a link file which contains the binary codes for all the combined
modules.
 The linker also produces a link map file which contains the address information
about the linked files. The linker assigns only relative address to the program starting
from zero This form of program is said to be re-locatable because it can be put
anywhere in memory to be run.
 TASM or MASM assemblers use Tlink.exe and Link.exe as the linker tools,
respectively. The output of the linker is executable code of the developed program,
which is stored as .EXE file.

Debugger

 If the program does not require any external hardware or Console input or output,
then debugger is used to load the .EXE file in main memory and run it.
 It automatically assigns physical starting address to the segments.
 Debugger is the tool that helps us test and examine the program for its desired
specified functionality; as it is executing.
 By executing instructions stepwise, you can check the contents of registers and
memory locations and check the problems or software bugs at the various steps or
stages in the program.
 Debugging is essentially a Testing tool. It employees testing and debugging methods
such as Single stepping, Trace, Watches and Breakpoints for this purpose.
 Debugger optionally generates .DBG files, which can be of help to the
developer/programmer in checking/testing program variables and logic.
 Logical errors in the program are detected in the process of debugging with the help
of the debugger. Logical errors are errors in the logic of the program. i.e. Program
does not function the way it is supposed to.
 Logical errors are removed by doing appropriate corrections in the operating
program logic as suitably modifying the source code of the Program, accordingly.

7 |2 1
Unit-2 : The Art of Assembly Language Programming

ASSEMBLER DIRECTIVES

 These are not Assembly Language Instructions in the Instruction set of 8086/8088.
 They are commands or directions provided to the Assembler tool to perform certain
function or operation, while assembling the Source code of the Assembly language
program.
 These directives do not get assembled into equivalent object code or executable
code of the program as the program gets assembled and linked by the Assembler
and the Linker.
 As they provide directions to the Assembler tool, they are called as Assembler
Directives.
 A Large variety of Assembler directives are available for use with the 8086 Assembler
and most of them are supported by the two widely used Assemblers; namely TASM
(Turbo Assembler) and MASM (Microsoft Assembler).
1. SEGMENT Directive Description:
 The SEGMENT directive is used to indicate the start of a logical segment. Preceding
the SEGMENT directive is the name you want to give the segment. For example, the
statement- CODE SEGMENT
Declares to the assembler the start of a logical segment called CODE.
 The SEGMENT and ENDS directive are used to start and end a logical segment
containing code of data.
 Additional terms are often added to a SEGMENT directive statement to indicate
some special way in which we want the assembler to treat the segment. The
statement CODE SEGMENT WORD tells the assembler that we want the content of
this segment located on the next available word (even address) when segments are
combined and given absolute addresses.
 The statement CODE SEGMENT PUBLIC tells the assembler that the segment may be
put together with other segments named CODE from other assembly modules when
the modules are linked together.

8 |2 1
Unit-2 : The Art of Assembly Language Programming

2. ENDS Directive Description:

 This directive is used with the name of a segment to indicate the end of that logical
segment.
 Example:

CODE SEGMENT

Declares Start of logical segment named CODE, containing code i.e.


Instructions in the Program
CODE ENDS
Declares End of segment named CODE
 Any segment starting with SEGMENT Directive must end with ENDS directive, in
order to integrally complete the body and contents of a logical segment.

3. END Directive

Description:

 The END directive is put after the last statement of a program to tell the assembler
that this is the end of the program module. The assembler will ignore any statements
after an END directive, so one must make sure to use only one END directive at the
very end of your program module.
 A carriage return is required after the END directive.
Example:
END Start
It declares that the Assembler program has come to an end. Further it also specifies
execution entry point from label Start
 No line after the END directive is assembled. However, comments can be added after
the end. directive.

4. ASSUME Directive

 The ASSUME directive is used tell the assembler the name of the logical segment it
should use for a specified segment.

9 |2 1
Unit-2 : The Art of Assembly Language Programming

 The statement ASSUME CS: CODE, for example, tells the assembler that the
instructions for a program are in a logical segment named CODE.
 The statement ASSUME DS: DATA tells the assembler that for any program instruction,
which refers to the data segment, it should use the logical segment called DATA.
 Example :
ASSUME CS: CODE, DS: DATA
It declares that the Code segment register CS to be associated with logical segment
called CODE and Data Segment register DS to be associated with logical segment called
DATA.

5. DB (DEFINE BYTE) Directive

 The DB directive is used to declare a Byte type variable, or to allocate or more


storage memory locations of type Byte in memory.
 It is a very versatile directive as it can also be used to declare an array of Bytes
 Or a single character expressed in its ASCII code
 Or a String of characters; each character expressed as byte in its ASCII code.
 Example:
 ITEMS DB 49H, 98H, 29H

The statement declares an array of 3 bytes named ITEMS and initializes each byte with the
respective specified value.

FIRST_NAME DB "THOMAS"

The statement declares an array of 6 Character bytes named FIRST_NAME; essentially a


String and initializes with ASCII codes for the letters in THOMAS.

TEMPS DB 100 DUP (?)

It sets aside 100 bytes of storage in memory and give it the name TEMPS. But leave the 100
bytes un-initialized.

FORCE DB 20H DUP (0)

It sets aside 20H bytes of storage in memory, gives it the name FORCE and puts 0 in all 20H
locations.

10 |2 1
Unit-2 : The Art of Assembly Language Programming

6. Operators? and DUP-

 As it can be seen in the above specified examples, operators can be used in


conjunction with Assembler directives; usually as an adjective telling the Assembler
to perform certain specific task.
 Operators? and DUP are used in association with Data declaration type assembler
directives such as DB, DW, DD, DQ and DT.
 Operator?

➤ It is used to keep the declared variable un-initialized.

 Operator DUP

➤ It is used to duplicate or multi-plicate the declared variable.

 As seen in the example above, PRESSURE is a variable replicated 20H times and all
locations kept un-initialized due to DUP and? Operators, respectively.

7. DW (DEFINE WORD) Directive

 The DW directive is used to tell the assembler to define a variable of type word (16
Bits) or to reserve storage locations of type word in memory.
 The statement MULTIPLIER DW 437AH, for example, declares a variable of type word
named MULTIPLIER, and initialized with the value 437AH when the program is
loaded into memory to be run.
 Example :

TWOWORD DW 1234H, 3456H

Declare an array of 2 words named variable TWOWORD and initializes with the specified
values.

STORE DW 100 DUP (0)

Reserve an array of 100 words of memory and initialize all 100 words with 0000. Array is
named as STORE.

STORE2 DW 100 DUP (?)

11 |2 1
Unit-2 : The Art of Assembly Language Programming

Reserve 100 word of storage in memory and give it the name STORE2, but leave the words
un- initialized.

8. DD (DEFINE DOUBLE WORD) Directive

 The DD directive is used to declare a variable of type double word orto reserve
memory locations, which can be accessed as type double word.
 The statement ARRX DD 25629851H, for example, will define a double word named
ARRX and initialize the double word with the specified value when the program is
loaded into memory to be run. The low word, 9851H, will be put in memory at a
lower address than the high word.

9. DQ (DEFINE QUADWORD) Directive

 The DQ directive is used to tell the assembler to declare a variable 4 words in length
or to reserve 4 words of storage in memory.
 The statement BIG_NUM DQ 243598740192A92BH, for example, will declare a
variable named BIG_NUM and initialize the 4 words set aside with the specified
number when the program is loaded into memory to be run.

10. DT (DEFINE TEN BYTES) Directive

 The DT directive is used to tell the assembler to declare a variable, which is 10 bytes
in length or to reserve 10 bytes of storage in memory.
 The statement PKD_BCD DT 11223344556677889900 will declare an array named
PKD_BCD, which is 10 bytes in length. It will initialize the 10 bytes with the values 11,
22, 33, 44, 55, 66, 77, 88, 99, and 00 when the program is loaded into memory to be
run.
 The statement RESULT DT 20H DUP (0) will declare an array of 20H blocks of 10 bytes
each and initialize all 320 bytes to 00 when the program is loaded into memory to be
run.

12 |2 1
Unit-2 : The Art of Assembly Language Programming

11. EQU (EQUATE) Directive

 EQU is used to give a name to some value or symbol. Each time the assembler finds
the given name in the program, it replaces the name with the value or symbol you
equated with that name.
 Therefore, EQU directive is essentially used to define a Constant. Within the scope of
the program, its assigned value remains constant or fixed. It cannot be changed.
 Suppose, for example, you write the statement FACTOR EQU 03H at the start of your
program, and later in the program you write the instruction statement ADD AL,
FACTOR. When the assembler codes this instruction statement, it loads 03H,
constant value in AL register.
 Example :

CTRL EQU 11000110B

Suppose the constant is declared as above..Then -

MOV AL, CTRL

Actually assigns the binary value 11000110 in the 8-bit AL register.

DEC_ADJ EQU DAA

Creates better mnemonic for DAA, then it can be used as follows -

ADD AL, BL

DEC_ADJ

Store the result in BCD (i.e. Decimal) format

12. LENGTH Operator

 LENGTH is an operator, which tells the assembler to determine the number of


elements in some named data item, such as a string or an array.
 When the assembler reads the statement MOV CX, LENGTH STR1, in example, will
determine the number of elements in STR1 and load it into CX register.
 If the string was declared as a string of bytes, LENGTH will produce the
number of bytes in the string.

13 |2 1
Unit-2 : The Art of Assembly Language Programming

 If the string was declared as a word string, LENGTH will produce the number
of words in the string.
 Example:

NAME_STR DB "Shrikant"

Declares a string NAME_STR of 8 bytes with value "Shrikant", then -

MOV CX, LENGTH NAME_STR

Loads CX register with 08, which is the length of above specified string.

13. OFFSET Operator

 OFFSET is an operator, which tells the assembler to determine the offset or


displacement of a named data item (variable), a procedure from the start of the
segment, which contains it.
 When the assembler reads the statement MOV BX, OFFSET ITEMS, for example, it
will determine the offset of the variable ITEMS from the start of the segment in
which ITEMS is defined and will load this value into BX.
 Example:

NAME_STR DB "Shrikant"

Declares a string NAME_STR of 8 bytes with value "Shrikant", then -

MOV BX, OFFSET NAME_STR

Loads BX register with address or location displacement of the above specified string, in the
declared Data Segment.

14. PTR (POINTER) Operator

 The PTR operator is used to assign a specific type to a variable or a label. It is


necessary to do this in any instruction where the type of the operand is not clear.
 When the assembler reads the instruction with unary function INC [BX], it will not
know whether to increment the byte pointed to by BX or the word. We use the PTR
operator to clarify how we want the assembler to code the instruction.

14 |2 1
Unit-2 : The Art of Assembly Language Programming

 The statement INC BYTE PTR [BX] tells the assembler that we want to increment the
byte pointed to by BX. The contents of BX are incremented by 1.
 The statement INC WORD PTR [BX] tells the assembler that we want to increment
the word pointed to by BX. The contents of BX are incremented by 2.
 The PTR operator assigns the type specified before PTR to the variable specified after
PTR.
 The PTR operator is applicable to all unary functions having memory references, such
as INC (Increment), DEC (Decrement), NEG (Negate i.e. 2's Complement), NOT (Invert
i.e. 1's Complement) etc.

15. EVEN Directive

 This directive is used to align the memory allocation of a variable on an Even


boundary.
 As an assembler assembles a section of data declaration or instruction statements, it
uses a location counter to keep track of how many bytes it is from the start of a
segment at any time. The
 EVEN directive tells the assembler to increment the location counter to the next
even address, if it is not already at an even address.
 Example:

DATA SEGMENT

SALES DB 9 DUP (?)

This would occupy 9 memory locations, as they are allocated to SALES.

EVEN

Skips a location, starting next memory allocation at EVEN boundary, i.e. 000A INVENTORY
DW 100 DUP (0)

Array of 100 words, starting on even address reads data faster due to aligned cycles. DATA
ENDS

Note: Word Data transfers starting on Even address boundary are called Aligned Cycles and
are completed in single Machine cycle; where as Word Data transfers starting on Even

15 |2 1
Unit-2 : The Art of Assembly Language Programming

address boundary are called Misaligned Cycles and are completed in 2 back-to-back Machine
cycles, making it much slower to operate.

16. PROC (PROCEDURE) Directive

 The PROC directive is used to identify the start of a procedure. The PROC directive
follows a name you give the procedure. After the PROC directive, the term near or
the term faris used to specify the type of the procedure.
 The statement MULXPROC FAR, for example, identifies the start of a procedure
named MULX and tells the assembler that the procedure is far (in a segment with
different name from the one that contains the instructions which calls the
procedure). The PROC directive is used with the ENDP directive to indicate logical
start and end of a procedure.

17. ENDP (END PROCEDURE) Directive

 The directive is used along with the name of the procedure to indicate the end of a
procedure to the assembler. The directive, together with the procedure directive,
PROC, to declare logical start and end of a procedure.
 Example :

SQR_ROOT PROC NEAR

This directive declares Start of a Near (Intra-segment) procedure named SQR_ROOT.

(Body or contents of the Procedure)

SQR_ROOT ENDP

This statement declares End of the SQR_ROOT procedure.

18. ORG (ORIGINATE) Directive

 As an assembler assembles a section of a data declarations or instruction


statements, it uses a location counter to keep track of how many bytes it is from the
start of a segment at any time. The location counter is automatically set to 0000
when assembler starts reading a segment.

16 |2 1
Unit-2 : The Art of Assembly Language Programming

 The ORG directive allows you to set the location counter to a desired value at any
point in the program. The statement ORG 3000H tells the assembler to set the
location counter to 3000H, for example.
 A "$" it often used to symbolically represent the current value of the location
counter, the $ actually represents the next available byte location where the
assembler can put a data or code byte. The $ is often used in ORG statements to tell
the assembler to make some change in the location counter relative to its current
value.
 The statement ORG $+100 tells the assembler increment the value of the location
counter by 100 from its current value.

19. NAME Directive

 The NAME directive is used to give a specific name to each assembly module when
programs consisting of several modules are written.
 Example:

NAME CALC_MODULE

Declares Name of current program module as CALC_MODULE.

20. LABEL Directive

 As an assembler assembles a section of a data declarations or instruction


statements, it uses a location counter to be keep track of how many bytes it is from
the start of a segment at any time.
 The LABEL directive is used to give a name to the current value in the location
counter. The LABEL directive must be followed by a term that specifics the type you
want to associate with that name.
 If the label is going to be used as the destination for a jump or a call, then the label
must be specified as type NEAR or type FAR.
 If the label is going to be used to reference a data item, then the label must be
specified as type BYTE or type WORD.

17 |2 1
Unit-2 : The Art of Assembly Language Programming

21. EXTRN Directive

 The EXTRN directive is used to tell the assembler that the name or labels following
the directive are in some other assembly module.
 For example, if you want to call a procedure, which in a program module assembled
at a different time from that which contains the CALL instruction, you must tell the
assembler that the procedure is external.
 The assembler will then put this information in the object code file so that the linker
can link the two modules together.
 For a reference to externally named variable, you must specify the type of the
variable, as in the statement EXTRN DIVS: WORD. The statement EXTRN DIVS: FAR
tells the assembler that DIVIDE is a label of type FAR in another assembler module.
 Name or labels referred to as EXTRN (external) in one module must be declared
public with the PUBLIC directive in the module in which they are actually defined or
declared.

22. PUBLIC Directive

 Large program are usually written as several separate modules. Each module is
individually assembled, tested, and debugged.
 When all the modules are working correctly, their object code files are linked
together to form the complete program.
 In order for the module s to link together correctly, any variable name or label
referred to in other modules must be declared PUBLIC in the module in which it is
defined.
 The PUBLIC directive is used to tell the assembler that a specified name or label will
be accessed from other modules. An example is the statement PUBLIC ABC, XYZ
which makes the two variables ABC and XYZ available to other assembly modules.

23. SHORT Directive

 The SHORT operator is used to tell the assembler that only a 1 byte displacement is
needed to code a jump instruction in the program.

18 |2 1
Unit-2 : The Art of Assembly Language Programming

 The destination must in the range of - 128 bytes to +127 bytes from the current IP
register i.e. address of the instruction.
 The statement JMP SHORT NEXT is an example of the use of SHORT, which tells
assembler to take a short jump to the label NEXT, which should be in the 256 Bytes
vicinity (-128 bytes to +127 bytes) of the Current execution point of the program.

24. TYPE Operator

 The TYPE operator tells the assembler to determine the type of a specified variable.
The assembler actually determines the number of bytes in the type of the variable.
 For a byte type variable, the assembler will give a value of 1,
 For a word type variable, the assembler will give a value of 2,
 And for a Double word type variable, it will give a value of 4.
 It can be used in instruction such as ADD BX, TYPE WORD ARRX, where we want to
increment BX to point to the next word in an array ARRX of words.

25. GLOBAL Directive

 This directive is used to declare a variable, label or procedure to be of Global in


nature. i.e. They can be accessed Globally, within this program module as well as any
other program module that is linked together by the linker.
 The GLOBAL directive can be used in place of a PUBLIC directive or in place of an
EXTRN directive.
 For a name or symbol defined in the current assembly module, the GLOBAL directive
is used to make the symbol available to other modules. The statement GLOBAL DIVS,
for example, makes the variable DIVS public so that it can be accessed from this as
well as other assembly modules.

26. INCLUDE Directive

 This directive is used to tell the assembler to insert a block of source code from the
named file into the current source module.
 These are the directions to the assembler to insert another module in the current
place in the module.

19 |2 1
Unit-2 : The Art of Assembly Language Programming

 Example:

INCLUDE Program2.ASM

The contents of another program module stored in file Program2.ASM are included in the
current program module, by this statement.

27. Dot. Directives

 Dot. Directives are the set of directives used by memory models such as Tiny and
Small models making assembly language structures simpler. They also define the
current memory model in use, type of CPU in use etc.
 The different. Directives are -

(a) .MODEL Directive

Syntax: .MODEL <Memory_model_type>

Example: .MODEL Small

Valid Memory Model types are -

 Tiny - Flat model, Single segment, creates .COM executable code. ❖ Small - Single
Code Segment and Single Data Segment.
 Medium - Multiple Code Segment and Single Data Segments.
 Compact - Single Code Segment and Multiple Data Segments.
 Large - Multiple Code as well as Multiple Data segments, segments within 64KB size
limit.
 Huge Multiple Code as well as Multiple Data segments, segments having NO 64KB
size limit.

The Tiny model creates .COM executable code; it is pure machine code and usually platform
independent.

Remaining models create .EXE executable code; it is usually OS (Operating System)


dependent executable code. Assembler creates DOS compatible .EXE code.

20 |2 1
Unit-2 : The Art of Assembly Language Programming

(b) .CPU Directive

 Syntax:.<CPU_type>
 Example: .386 (Assembles the code compatible to 80386 instruction set)
 Valid CPU Types are .286 (for 80286 Processors); .386 (for 80386 Processors); .486
(for - 80486 Processors); .586 (for Pentium class Processors).

(c) .CODE Directive

 Syntax:.CODE
 This directive declares the start or beginning of the Code segment, it also
automatically associates CS register with it and initializes it.
 The subsequent statements should be code instructions.

(d) .DATA Directive

 Syntax: .DATA
 This directive declares the start or beginning of the Data segment, it also
automatically associates DS register with it and initializes it.
 The Subsequent statements should be Data declarations.

(e) .STACK Directive

 Syntax: .STACK <size>


 Example: .STACK 1024 (Allocates 1024 bytes to the stack)
 This directive declares the start or beginning of the Stack segment, it also
automatically associates SS register with it and initializes it.

(f) STARTUP Directive

 Syntax:.STARTUP
 It indicates or declares the initial execution point; also called as entry point of the
Program as the executable is run on the system.
 The program execution begins from the statement subsequent to this directive.

21 |2 1

You might also like