0% found this document useful (0 votes)
13 views33 pages

Assembler Directives

The document outlines various assembler directives used in assembly language programming, specifically for the 8086 instruction set. It categorizes directives into executable statements and assembler directives, detailing their functions such as defining segments, setting memory models, and handling data types. Key directives discussed include .CODE, .DATA, .MODEL, EQU, and others that manage memory allocation, procedure definitions, and code organization.

Uploaded by

Sayantan Maity
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views33 pages

Assembler Directives

The document outlines various assembler directives used in assembly language programming, specifically for the 8086 instruction set. It categorizes directives into executable statements and assembler directives, detailing their functions such as defining segments, setting memory models, and handling data types. Key directives discussed include .CODE, .DATA, .MODEL, EQU, and others that manage memory allocation, procedure definitions, and code organization.

Uploaded by

Sayantan Maity
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Assembly Language Development Tools

Assembler Directives
• Assembly language consists of two type of statements
• 1) Executable statements
These are the statements to be executed by the processor. It
consists of the entire instruction set of 8086

• 2) Assembler directives
• These are the statements that direct the assembler to do
something. As the name says, it direct the assembler to do a
task. The specialty of these statements is that they are
effective only during the assembly of a program but they do
not generate any code that is machine executable
Assembly directives
• Assembler directives provide information to the
assembler about how to process the code, define
segments, set up memory models, and handle data.
• . CODE [name]
• This assembler directive indicates the beginning of
the code segment.
• The name in this format is optional
• .DATA
• This directive indicates the beginning of the data
segment
• 3. .MODEL
• Model
• Small Medium
• This directive is used for selecting a standard
memory model for the assembly language
program
• Each memory model has various limitation
depending on the maximum space available
for code and data
• Common Memory Models
• SMALL: One segment for code and one segment for
data. Both segments can be up to 64 KB.
• COMPACT: One segment for code and multiple
segments for data. The code segment can be up to
64 KB, and the data segments can also be up to 64
KB.
• LARGE: Multiple segments for both code and data.
Both can exceed 64 KB, but a single code or data
segment cannot exceed 64 KB.
• .STACK [size]
• The size of the stack is 1024 bytes by default
but this size can be overridden We can omit
the stack command if the stack segment is not
to be used in a program. Example of the stack
directive is
• STACK 100 Which reserves 100 bytes for the
stack segment.
• EQU-Equate
• It is used to give a name to some value or symbol in the program.

• Each time when the assembler finds that name in the program, it replaces
that name with the value assigned to that variable.

• Its format is (name) EQU initial value.

• e.g. FACTORIAL EQU 05H.

• This statement is written during the beginning of the program and


whenever now FACTORIAL appears in an instruction or another directive,
the assembler substitutes the value 5. The advantage of using EQU in this
manner is that if FACTORIAL is used several times in a program and the
value has to be changed, all that has to change the EQU statement and
reassemble the program. The assembler with automatically put the new
value each time it finds the name FACTORIAL
• Define Byte [DB]
• This directive defines the byte type variable
• Define byte. It is used to declare a byte
variable or set aside one or more storage
locations of type byte in memory.
• For example, CURRENT_VALUE DB 36H tells
the assembler to reserve 1 byte of memory
for a variable named CURRENT_ VALUE and to
put the value 36 H in that memory location
when the program is loaded into RAM .
• DW -Define word. It tells the assembler to
define a variable of type word or to reserve
storage locations of type word in memory.
• Define Double word or DWORD [DD]
• It defines the data items that are a double
word (four bytes) in length.
• It creates storage for 32 bit double words. The
format is
• [name] DD initial value. e.g. BUFF DD
• . Define Quad word or QWORD [DQ]
• This directive is used to tell the assembler to
declare variable 4 words in length
• or to reserve 4 words of storage in memory. It
may define one or more constants, each with
a maximum of 8 bytes or 16 Hex digits.
• Its format is:
• [name] DQ initial value, [initial value].
• e.g. Num DQ 1234567898765432H.

• Define Ten Bytes or TBYTE [DT]
• It is used to define the data items that are 10
bytes long.
• Its format is
• [name] DT initial value, [initial value].
• e.g. unpackDT 1234567890.
• Unlike the other data directives with store
hexadecimal numbers, DT will directly store
the data in decimal form.
• ORG -Originate : The ORG statement changes the
starting offset address of the data.
• It allows to set the location counter to a desired
value at any point in the program.
• For example the statement ORG 3000H tells the
assembler to set the location counter to 3000H.
• The $ is often used in ORG statements to inform
the assembler to make change in location counter
relative to its current value.
• e.g. ORG $+50
• Increments the location counter by 50 from in
current value.
• ASSUME : The ASSUME directive is used to inform the assembler the
name of the logical segment it should use for a specified segment.
• Ex: 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.

• END
• This is placed at the end of a source and it acts as the last statement of
a program.

• This is because the END directive terminates the entire program.

• The assembler will neglect any statement after an END directive.


• The format of END directive is as follows:

• END
• SEGMENT and ENDS

• The SEGMENT directive is used to indicate the


start of a logical statement
• ENDS directive is used with the segment directive.
• ENDS directive indicates the end of the segment.

• Its format is name SEGMENT name ENDS


• e.g. DATA SEGMENT

• DATA ENDS.
• . GROUP
• This directive collects the segments of the
same type under one name.
• It does it so that the segments that are
grouped will reside within one segment
usually data segment.
• Its format is [name] GROUP Seg-name, [seg-
name]
• e.g.: NAME GROUP SEG 1, SEG 2.
• MACRO AND ENDM
• The macros in the programs can be defined by
MACRO directive The ENDM directive is used
along with the Macro directive
• ENDM defines the end of macro
• Its format is
• DISP MACRO
• Statements inside the Macro
• ENDM
• DUP Operator
• Whenever we want to allocate space for a table or an array the DUP
directive can be used. The DUP operator it will be used after a
storage allocation directive like (DB, DW, DQ, DT, DD). With DUP, we
can repeat one or more values while assigning the storage values.
Its format is
• [name] Data-Type Number DUP (value).

• eg: List DB 20 DUP [0] ; A list of 20 bytes, where each byte is zero. A
DUP operator may be nested.

• e.g. LIST 1 DB 4 DUP (4 DUP [0]. 3 DUP ('X']); The assembler assigns
the values in memory here as follows,

• 00, 00, 00, 00, x, x, x 00, 00, 00, 00, x, x, x 00, 00, 00, 00, x, x, x 00,
00, 00, 00, x, x, x
• . ALIGN
• This directive will tell the assembler to align the
next instruction on an address which corresponds
to the given value. Such an alignment will allow the
processor to access words and double words
• ALIGN number //it aligns the address to given
bound
• This number should be 2, 4, 8, 16.... i.e. it should
be a power of 2.
• Example let address of variable is 00402
• Align 2 means 00404
• Align 4 means 00408
• EVEN: It is used to inform the assembler to
align the data beginning from an even address.
• LABEL
• This directive assigns name to the current value
of the Location Counter. The LABEL directive
must be followed by a term which specifies the
type associated with that symbolic name If
label is going to be used as the destination for a
jump or call, then the LABEL must be specified
as type near or type Far.
• PROC: (PROCEDURE)
• It is used to identify the start of a procedure. It
follows a name we give the procedure.
• After the procedure the term NEAR and FAR is
used to specify the procedure
• Example:
• SMART-DIVIDE PROC FAR identifies the start
of procedure named SMART-DIVIDE and tells
the assembler that the procedure is far.
• ENDP-End Procedure
• This directive is used along with the name of
the procedure to indicate the end of
procedure
• ENDP defines the end of procedure.
• eg: FACT PROC FAR Start procedure named
FACT and informs the assembler that the
procedure is FAR.
• Body of Procedure
• FACT ENDP End of Procedure FACT
• EXTRN
• It indicates that the names or labels that
follow the EXTRN directive are in some other
assembly module.
• e.g. EXTRN DISP: FAR
• The statement tells the assembler that DISP is
a label of type far in another assembly
module.
• PUBLIC
• It informs the assembler and linker that the identified
variables in a program are to be referenced by other
modules linked with the current one.
• Its format is,
• PUBLIC variable, [variable]
• The variable can be a number (up to two bytes) or a
label or a symbol.
• e.g. PUBLIC MULTIPLIER, DIVISOR
• This makes the two variables Multiplier and Divisor
available to other assembly modules.

• PAGE
• This directive is used to specify the maximum number
of lines on a page and the maximum number of
characters on a line.
• The format of this directive is as follows:
• PAGE [length], [width]
• Number of lines on a page. Number of characters on a line.

• The example is PAGE 55, 102 which shows that the,


there are 55 lines per page and 102 characters per line.
• The number of lines per page typically range from 10 to
255 and the number of characters per line will range
from 60 to 132
• TITLE
• It is used to give a title to program and print
the title on the second line of each page of the
program.
• The maximum number of characters allowed
as a title is 60.
• The format of this assembler directive is as
follows, TITLE Text
• INCLUDE
• This directive is used to tell the assembler to
insert a block of source code from the named
file into the current source module. This
shortens the source code.
Its format is
• INCLUDE path: file name
• NAME
• This directive assigns a specific name to each
assembly module when programs consisting
of several modules are written.
• GLOBAL
• This directive can be used instead of PUBLIC
directive or instead EXTRN directive
• For a name or variable defined in the current
module, the GLOBAL directive is used to make
the variable available to all other modules.
• Its format is
• e.g.: GLOBAL FACTOR
• it makes the variable FACTOR public so that it
can be accessed from all other modules that
are linked
• LENGTH
• It informs the assembler to find the number of
elements in a named data item like a string or an array
• The length of string is always stored in Hex by the
8086
• OFFSET
• It informs the assembler to determine the offset or
displacement of a named data item.
• It may also determine the offset of a procedure from
the start of the segment which contains it
• Its format is MOV AX, OFFSET NUM, It will load the
offset of NUM in the AX
• PTR-Pointer
• It is used to assign a specific type to a variable or to a
label.
• It is necessary to do this in any instruction where the
type of operand is not clear.
• SHORT
• It is used to tell the assembler that only 1-byte
displacement is needed to code a jump instruction.
• If the jump destination is after the jump instruction in
the program, the assembler will automatically reserve
2-bytes for the displacement.
• e.g. JMP SHORT NEAR_LABEL.
• TYPE
• It informs the assembler to find the type of a
specified variable.
• The assembler actually finds the number of
bytes in the type of variable.
• For a byte type variable the assembler gives a
value 1.
• For word type variable the assembler gives a
value 2 and for double word 4.

You might also like