Sie sind auf Seite 1von 18

Assembler Directives

❑ There are some instructions in the assembly language program which


are not a part of processor instruction set.

❑ These instructions are instructions to the assembler, linker, and


loader.

❑ These are referred to as pseudo-operations or as assembler directives.


The assembler directives enable we to control the way in which a
program assembles and lists.

❑ They act during the assembly of a program and do not generate any
executable machine code.

There are many specialized assembler directives. Let us see the


commonly used assembler directive in 8086 assembly language
programming.
Wednesday, April 17, 2019 1
ALIGN:
❑ The align directive forces the assembler to align the next segment at an
address divisible by specified divisor. The general format for this
directive is as shown below.
ALIGN number

where number can be 2,4,8 or 16.

Example: ALIGN 8 ; This forces the assembler to align the next segment
; at an address that is divisible by 8. The assembler
; fills the unused bytes with 0 for data and NOP
instructions for code.

❑ Usually ALIGN 2 directive is used to start the data segment on a word


boundary and ALIGN 4 directive is used to start the data segment on a
double word boundary.

Wednesday, April 17, 2


2019
ASSUME:

❑ The 8086, at any time, can directly address four physical segments
which include a code segment, a data segment, a stack segment and an
extra segment.
❑ The 8086 may contain a number of logical segments.
❑ The ASSUME directive assigns a logical segment to a physical segment
at any given time.
❑ ASSUME directive tells the assemble what addresses will be in the
segment registers at execution time.

Example: ASSUME CS: code, DS: Data, SS: Stack.


.CODE:
❑ This directive provides shortcut in definition of the code segment.
General format for this directive is as shown below.
.code[name]
❑ The name is optional. It is basically specified to distinguish different
code segments when there are multiple code segments in the program.
.DATA:
❑ This directive provides shortcut in definition of the data segment.
Wednesday, April 17, 3
2019
DB, DW, DD, DQ and DT:

❑ These directives are used to define different types of variables, or to set


aside one or more storage locations of corresponding data type in memory.
Their definitions are as follows:
DB-Define Byte
DW-Define Word
DD-Define Doubleword
DQ-Define Quadword
DT-Define Ten Bytes
Example:
AMOUNT DB 10H,20H,30H,40H ; Define array of 4 bytes named AMOUNT
MES DB ‘WELCOME’ ; Declare array of 7 bytes and initialize
; with ASCII codes for letter in
; WELCOME.

Wednesday, April 17, 4


2019
DUP:
❑ The DUP directive can be used to initialize several locations and to
assign values to these locations.
Format Name Data_Type Num DUP (value)
Example: TABLE DW 10 DUP(0) ; Reserve an array of 10 word
; words of memory and initialize
; all 10 words with 0. Array is
named TABLE

END:
❑ 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 ignores any statement after an END directive.

Wednesday, April 17, 5


2019
EQU:
❑ 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.
Formats:
Numeric Equate: Name EQU expression
String Equate: Name EQU <string>
Example:
FACTOR EQU 03H ; you have to write this statement at the
starting of your program and later in the program you can use
this as follows
ADD AL, FACTOR ; When it codes this instruction the assembler
will code it as ADDAL, 03H
;The advantage of using EQU in this manner is, if FACTOR is used
many no of times in a program and you want to change the value,
all you had to do is change the EQU statement at beginning, it
will changes the rest of all.
Wednesday, April 17, 6
2019
.MODEL :

❑ It is available in MASM version 5.0 and above. This directive provides


short-cuts in defining segments.
❑ It is initializes memory model before defining any segment.
❑ The memory model can be SMALL, MEDIUM, COMPACT or
LARGE.
❑ We can choose the memory model based on our requirement by
referring following table.

Model Code Segments Data Segments


Small One One
Medium Multiple One
Compact One Multiple
Large Multiple Multiple

Wednesday, April 17, 7


2019
ORG:
❑ The assembler uses a location counter to account for its relative
position in a data or code segment.
Format: ORG expression
Example: ORG 1000H, set the location counter to 1000H.
SEGMENT and ENDS:
❑ An assemble program in EXE format consists of one or more
segments.
❑ The start of these segments are defined by SEGMENT directive and
the ENDS statement indicates the end of the segment.
Format: name SEGMENT[options]; Begin segment
.
name ENDS ; End Segment
Example : CODE SEGMENT
.
.
.
Wednesday, April 17, CODE ENDS 8
2019
SHORT:
❑ A short is a operator. It is used to tell the assembler that only 1–byte
displacement is needed to code a jump instruction.
❑ The short operator should be used only when the destination is in the
range of -128 bytes to 127 bytes from the address of the instructions after
the jump.
Example: JMP SHORT

TITLE:
❑ The TITLE directive help to control the format of listing of an assembled
program.
❑ TITLE directive causes a title for a program to print on line 2 of each
page of the program listing. Maximum 60 characters are allowed as title.
Format: TITLE text

Example: TITLE Program to find maximum number

Wednesday, April 17, 9


2019
PTR (POINTER)
❑ 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 INC [BX], for example, it will not know
whether to increment the byte pointed to by BX.

❑ We use the PTR operator to clarify how we want the assembler to code the instruction.
The statement INC BYTE PTR [BX] tells the assembler that we want to increment the
byte pointed to by BX. The statement INC WORD PTR [BX] tells the assembler that we
want to increment the word pointed to by BX.

❑ The PTR operator assigns the type specified before PTR to the variable specified after
PTR.

❑ We can also use the PTR operator to clarify our intentions when we use indirect Jump
instructions.
❑ The statement JMP [BX], for example, does not tell the assembler whether to code the
instruction for a near jump. If we want to do a near jump, we write the instruction as
JMP WORD PTR [BX]. If we want to do a far jump, we write the instruction as JMP
DWORD PTR [BX].

Wednesday, April 17, 10


2019
Assembly Language Development Tools

The followings are the assembly language development tools:


1. Editor
2. Assembler
3. Linker
4. Locator
5. Debugger
6. Emulator

Wednesday, April 17, 11


2019
Wednesday, April 17, 12
2019
Editor

An editor is a program which allows you to create a file


containing the assembly language statements for your
program.
Example: PC-Write, Wordstar.

As you type in your program, the editor stores the ASCII codes
for the letters and numbers in successive RAM locations.

When you have typed in all your program, you then save the
file on the hard disk. This file is called source file and the
extension is .asm.

Wednesday, April 17, 13


2019
Assembler
❑ An assembler program is used to translate the assembly language
mnemonics for instructions to corresponding binary codes. When you
run the assembler, it reads the source file of your program from the disk
where you have saved it after editing.
❑ On the first pass through the 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 offsets, etc. that it
calculated during the first pass.
❑ The assembler generates 2 files on the floppy disk or hard disk. The first
file is called object file (.obj).
❑ The second file generated by assembler is called the assembler list file
and is given extension (.lst).

Wednesday, April 17, 14


2019
Linker
❑ A linker is a program used to join several object files into one large
object file.

❑ 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 (.exe).
Locator
❑ A locator is a program used to assign the specific address of where the
segments of object code are to be loaded into memory.

❑ A locator program called EXE2BIN comes with the IBM PC Disk


Operating System (DOS). EXE2BIN converts a .exe file to a .bin file
which has physical addresses.

Wednesday, April 17, 15


2019
Debugger
❑ A debugger is a program which allows you to load your object code program
into system memory, execute the program and troubleshoot or debug it.

❑ The debugger allows you to look at the contents of registers and memory
locations after your program runs.

❑ It allows you to change the contents of registers and memory locations and re-
run the program.

❑ Some debuggers allow you to stop execution after each instruction so that you
can check or alter after each register contents.

❑ A debugger also allows you to set a breakpoint at any point in your program.
If you insert a breakpoint at any point in your program, the debugger will run
the program up to the instruction where you put the breakpoint and then stop
the execution.

Wednesday, April 17, 16


2019
Emulator

❑ An emulator is a mixture of hardware and software.

❑ It is used to test and debug the hardware and software of an


external system, such as the prototype of a microprocessor
based instrument. Part of the hardware of an emulator is a
multiwire cable which connects the host system to the system
being developed.

Wednesday, April 17, 17


2019
MOD and R/M Bit Patterns in 8086

Das könnte Ihnen auch gefallen