Sunteți pe pagina 1din 6

8086 ASSEMBLER DIRECTIVES

Varun Kumar Sen, RB6703B50, 3460070010,


B.tech (ECE) + MBA, Dept. Of ECE,
Lovely Professional University, Phagwara, Punjab, 144402
E-mail id: varun01683@gmail.com

ABSTRACT: End program 8. ENDP- End procedure 9. ENDS-


End segment 10. EQU- Equate 11. EVEN- Align on
The words defined in this review are directions to the
even memory address 12. EXTRN 13. GLOBAL-
assembler not instructions for the 8086. An
Declare symbols as public 14. GROUP- Group
assembler directive is a message to the assembler
related segments 15. INCLUDE- Include source code
that tells the assembler something it needs to know in
from file 16. LABEL 17. LENGTH- Not
order to carry out the assembly process; for example,
implemented in IBM MASM 18. NAME 19.
an assemble directive tess the assembler where a
OFFSET 20. ORG- Originate 21. PROC- Procedure
program is to be located in memory. The assembler
22. PTR-Pointer 23. Public 24. SEGMENT 25.
directives described here are those for the Intel 8086
SHORT 26. TYPE
macro assembler. After whole study the results shows
that 8086 assembler directives has wide range of 2. THEORY:
applications in assembly programming as well as
EXPLAINATION OF ASSEMBLER DIRECTIVES:
high level languages like C and ASP.NET. In this
paper I tried my best to explain all assembler ASSUME: The ASSUME directive is used to tell the
directives which are in existence and some assembler the name of the logical segment it should
applications in software designing with C and use for a specified segment. The statement ASSUME
ASP.NET. CS: CODE, for example, tells us the assembler that
the instructions for a statement ASSUME DS: DATA
1. INTRODUCTION:
tells the assembler that for any program instruction
Assembler directives are the word which gives the which refers to the data segment. It should use the
directions to the assembler. The common assembler logical segment called DATA. For example, the
directives are: assembler reads the statement MOV AX,[BX] after it
reads this ASSUME, it will know that the memory
1. ASSUME directives, 2. DB- Define Byte, 3. DD-
location referred to by [BX] is in the logical segment
Define Double word 4. DQ- Define Quad word 5.
DATA. You must tell the assembler what to assume
DT- Define Ten Byte 6. DW- Define word 7. END-
for any segment you use in a program. If you use a
stack in your program, you must tell the assembler words of storage and initializes them all to 0 when
the name of the logical segment you have set up as a the program is loaded into memory to be run.
stack with a statement such as ASSUME SS:
DT- Define Ten Bytes: DT is used to tell the
STACK_ HERE. For a program with string
assembler to define a variable which is 10 bytes in
instructions which use DI, the assembler must be told
length or to reserve 10 bytes of storage in memory.
what to assume for the extra segment with a
The statement PACKED_BCD DT
statement such as ASSUME ES:
11223344556677889900 will declare an array named
STRING_DESTINATION.
PACKED_BCD which is 10 bytes with values
DB- Define Byte: The DB directive is used to 11223344556677889900 when the program is loaded
declare a byte-type variable, or to set aside one or into memory to be run.
more storage locations of type byte in memory. The
DW- Define Word: The DW directive is used to fell
statement CURRENT_TEMPERATURE DB 42H,
the assembler to define a variable of type word or to
for example, tells the assembler to reserve 1 byte of
reserve storage locations of type word in memory.
memory for variable named
For example, the statement MULTIPLIER DW
CURRENT_TEMPERATURE and to put the value
437AH, declares a variable of type word named
42H in that memory location when the program is
MULTIPLIER. The statement also tells the assembler
loaded into RAM to be run.
that the variable MULTIPLIER should be initialized
PRICES DB 49H,98H,29H; Declare array of 3 bytes with the value 437AH when the program is loaded
named PRICES and initialize 3 bytes as shown. into memory to be run.

DD- Define double word: The DD directive is used END- End Program: The directive is put after the
to declare a variable of type double word or to last statement of a program to tell the assembler that
reserve memory locations which can be accessed as this is the end of the program module. The assembler
type double word. The statement will ignore any statements after an END directive, so
ARRAY_POINTER DD 25629261H, for example, you should make sure to use only one END directive
will define a double word with the specified value at the very end of your program module. A carriage
when the program is loaded into memory to be run. return is required after the END directive.

DQ- Define Quad word: This directive is used to ENDP- End Procedure: This directive is used along
tell the assembler to declare a variable 4 words in with the name of the procedure to indicate the end of
length or to reserve 4 words of storage in memory. a procedure to the assembler. This directive, together
For example, the statement BIG_NUMBER DQ with the procedure directive, PROC, is used to
243598740192A92BH, will declare a variable named “bracket” a procedure. For example,
BIG_NUMBER and initialize the 4 words set aside
SQUARE_ROOT PROC; Start of procedure
with the specified number when the program is
loaded into memory to be run. The statement ; Procedure
STORAGE DQ 100 DUP (0) reserves 100 quad instruction
; Statement EXTRN: The EXTRN directive is used to tell the
assembler that the names or labels following the
SQUARE_ROOT ENDP; End of procedure
directive are in some other assembly module. For

ENDS- End segment: This directive is used with the example, if you want to call a procedure which is in a

name of a segment to indicate the end of that logical program module assembled at a different time from

segment. ENDS are used with the SEGMENT that which contains the CALL instruction, you must

directive to “bracket” a logical segment instructions tell the assembler that the procedure is external. The

or data. Look at this example: assembler will then put information in the object
code file so that the linker can connect the two
CODE SEGMENT; start of logical segment modules together.

; containing code GROUP- Group related Segments: The GROUP


directive is used to tell the assembler to group the
; Instruction statements
logical segments named after the directive into one
CODE ENDS; End of segment named logical group segment. This allows the contents of all
the segments to be accessed from the same group
; CODE
segment base. The assembler sends a message to the
EQU- Equate: EQU is used to give a name to some linker and locator telling it to link the segments so
value or symbol. Each time the assembler finds the that the segments are physically in the same 64-kbyte
given name in the program. It will replace the name segment. An example of the GROUP directive would
with the value or symbol you equated with that name. be SMALL/-SYSTEM GROUP CODE, DATA,
STACK_SEG. An appropriate ASSUME statement
EVEN- Align on Even Memory Address: As the
to follow this would be ASSUME
assembler assembles a section of data declarations or
CS: SMALL_SYSTEM, DS: SMALL_SYSTEM,
instruction statements, it uses a location counter to
SS: SMALL_SYSTEM.
keep track of how many bytes it is from the start of a
segment at any time. The EVEN directive tells the INCLUDE- Include source code from file: This
assembler to increment the location counter to the directive is used to tell the assembler to insert a block
next even address if it is not already at an even of source code from the named file into the current
address. The 8086 can read a word from memory in source module. This shortens the source code. An
one bus cycle if the word is at an even address. If the alterative is to use the editor block commands to copy
word starts at an odd address, the 8086 must do two the file into the current source module.
bus cycles to get the 2 bytes of the word. Therefore, a
LABEL: As the assembles a section of data
series of words can be read much more quickly if
declarations or instruction statements, it uses a
they are at even addresses. When EVEN is used in a
location counter to keep track of how many bytes it is
data segment, the location counter will be
from the start of a segment at any time. The LABEL
incremented to the next even address if necessary.
directive is used to give a name to the current value
in the location counter. The LABEL directive must
be followed by a term which specifies the type you OFFSET: OFFSET is an operator which tells the
want associated with that name. if the label is going assembler to determine the offset or displacement of
to be used as the destination for a jump or a call, then a named data variable or procedure from the start of
the label must be specified as type near or type far. If the segment which contains it. This operator is
the label is going to be used to reference a data item, usually used to load the offset of the variable into a
then the label must be specified as type byte, type register so that the variable can be accessed with one
word, or type double word. Here’s how we use the of the indexed addressing modes.
LABEL directive for a jump address.
ORG- Originate: As the assembler assembles a
ENTRY_POINT LABEL FAR; can jump to here section of data declarations or instruction statements,
from another segment it uses a location counter to keep track of how many
bytes it is from the start of a segment at any time. The
NEXT: MOV AL, BL; cannot do a far jump
location counter is automatically set to 0000 when

; Directly to a label the assembler starts reading a segment. The ORG


directive allows you to set the location counter to a
; With a colon desired value at any point in the program. The
statement ORG 2000H tells the assembler to set the
LENGTH- Not implemented in IBM MASM:
location counter to 2000H.
LENGTH is an operator which tells the assembler to
determine the number of elements in some named PROC- Procedure: The PROC directive is used to
data item, such as a string or an array. When the identify the start of a procedure. The PROC directive
assembler reads the statement MOV CX, LENGTH follows a name you give the procedure. After the
STRING1, for example, it will determine the number PROC directive, the term near or the term far is used
of elements in STRING1 and code this number in as to specify the type of the procedure.
part of the instruction. When the instruction executes,
then, the length of the string will be loaded into CX. PTR- Pointer: The PTR operator is used to assign a

If the string was declared as a string of bytes, specific type to a variable or to a label. It is necessary
LENGTH will produce the number of bytes in the to do this in any instruction where the type of the

string. If the string was declared as a word string, operand is not clear. We also use the PTR operator to

LENGTH will produce the number of words in the clarity our intentions when we use indirect jump

string. instructions.

NAME: The NAME directive is used to give a PUBLIC: Large programs are usually written as

specific name to each assembly module when several separate modules. Each module is

programs consisting of several module are written. individually assembled, tested, and debugged. When

The statement NAME PC_BOARD, for example, all the modules are working correctly, their object

might be used to name an assembly module which code files are linked together to firm the complete

contains the instructions for controlling a printed- program. In order for the modules to link together

circuit-board-making machine. correctly, any variable name or label referred to in


other modules must be declared public in the module
linking to a specific page or user control.
in which it is defined. The PUBLIC directive is used
Assemblies located in the bin subdirectory
to tell the assembler that a specified name or label
under the application's virtual root are
will be accessed from other modules.
automatically linked to the application and
SEGMENT: The SEGMENT directive is used to do not need to be included in an Assembly
indicate the start of a logical segment. Preceding the directive. There are two permissible
SEGMENT directive is the name you want to give attributes:
the segment.
NAME: Assembly directive NAME is used to give
SHORT: The SHORT operator is used to tell the
the name of the assembly to link to the
assembler that only a 1- byte displacement is needed
page. It does include filename extension
to code a jump instruction. If the jump destination is
because assembly usually has dll
after the jump instruction in the program, the
extension.
assembler will automatically reserve 2 bytes for the
displacement. Using the SHORT operator saves 1
<%@ Assembly Name= “MyAssembly” %>
byte of memory by telling the assembler that it needs
reserve only 1 byte for this particular jump for this SRC: SRC directive is used to give the path to
destination must be in the range of -128 bytes to source file to dynamically compile and
+127 bytes from the address of the instruction after link.
the jump.
<%@ Assembly Src = “SomeSource.cs” %>
TYPE: The TYPE operator tells the assembler to
determine the type of a specified variable. The
Assembly directives in C application code:
assembler actually determines the number of bytes in
the type of the variable. An assembly routine can be added and called from
the C program. To Write an assembly routine in the
*.a30 file the following is the procedure to write an
3. APPLICATIONS:
assembly routine in a C application program:

Assembly Directive in ASP.NET: 1. Specify the section where the assembler


functions is located using the assembler
The Assembly directive links an assembly to the
directive .SECTION.
application used as command-line switch
2. Specify the function name preceded by an
used by the C# and VB.NET command-
underscore ( _ ) using the .GLB directive.
line compilers. The Assembly directive is 3. The function name has to be in label format,
contained in either the global.asax file, for so specify the function name preceded by an
application-wide linking, or in a page underscore ( _ ).
(.aspx) or user control (.ascx) file, for
4. Save the FLAG register onto the stack to 1. “Douglas V. Hall”, “Microprocessors and
protect the B and U flag values. interfacing”, Tata McGraw- hill, 2002

5. Extract the FLAG value from the stack. www.java-sample.com

6. Use the RTS instruction to return from the www.codeidol.com

assembler function.
For example:

.section program

.glb _asm_func

_asm_func:

pushc FLG

F0010 EB32 _asm_fun PUSHC FLG

pushm R3, R1

F0012 EC50 PUSHM R1, R3

; write the function body

popm R3, R1

F0014 ED0A POPM R1, R3

popc FLG

F0016 EB33 POPC FLG

rts

F0018 F3 RTS

.END

4. CONCLUSION:

The result shows that we have wide range of


assembler directives used in assembly language
programming. These have wide range applications in
multi languages programming for example in C
programming and ASP.NET.

REFERENCES:

S-ar putea să vă placă și