Professional Documents
Culture Documents
User Friendly.
Easy to debug.
Requires usage of compiler or Interpreter.
Requires move memory space.
Assembler Directives
Assembler Directives
Assembler Directives
Second Pass:
o Produces the binary code for each instruction and inserts the offsets
etc which are generated during first pass.
o In order to facilitate programmer to test and troubleshoot program, list
file is sent to printer.
o The assembler can give information only about the syntax errors.
o After generating object file and list file an linker or locator is used to
assign the physical starting addresses for the segments.
Assembler Directives
Assembler Directives
Locator :
o Program used to assign the specific addresses for the segments in object
code to be loaded into memory.
Debugger :
o Program which allows programmer to load object code of program into
system memory, execute the program and debug it i.e ., trouble shoot it.
Assembler Directives
Emulator:
o Mixture of hardware and software.
o Usually used to test and debug the hardware and software of an external
system like prototype of microprocessor based instruments.
o Emulator have a multi-wire cable which connects the host system to
prototype system.
Assembler Directives
Start
Define Problem
2
Develop Algorithm
Create Source File
With Editor
Assemble
YES
Assembl
y
Errors
.ASM
.OBJ
.LST
NO
Assembler1Directives
NO
Load Debugger
Load Program
LINK
.EXE
.MAP
Locate
.BIN
External
System
YES
Load Emulator
Load Program
Assembler Directives
10
4
NO
NO
Errors
Errors
YES
YES
Assembler Directives
11
Disadvantages of MLP :
o The process is complicated and time consuming.
o The chances of error being committed are more at the machine level( in
hand-coding and entering the program byte-by-byte into the system).
o Debugging a program at the machine-level is more difficult.
o The programs are not understood by every one and the results are not
stored in user friendly form.
Assembler Directives
12
Assembler Directives
13
Assembler Directives
14
Assembler Directives
15
Operand :
An instruction may contain zero, one (or) two operands.
An operand may be a register, a memory variable, or an immediate
value (data).
The choice of operand is usually determined by the addressing mode.
The addressing mode tells the assembler, where to find data in each
operand, i.e., whether in a register, or in a memory or as immediate data.
Instruction
Mnemonic + Operand
Assembler Directives
16
Assembler Directives
17
Assembler Directives
18
Assembler Directives
19
Assembler Directives
20
Assembler Directives
21
Assembler Directives
Data definition and storage allocation:
Statements that reassign data and reserve storage have the form:
Variable Mnemonic Operand,.,Operand ; Comments
(Label)
The variable is optional, but if it is present it is assigned the offset of
the first byte that is reserved by the directive.
Unlike the label field, a variable must be terminated by a blank, not
a colon.
The mnemonic in the statement determines the length of each operand
and is one of the following:
DB (Define Byte) : Each operand datum of the label or variable
occupies one byte location in memory.
DW(Define Word) : Each operand datum of the label or variable
occupies one Word or two memory locations where low-order byte is
stored in first location and the higher-order byte is stored in second
location.
Assembler Directives
22
Assembler Directives
DD (Define Double Word) : Each operand datum is two words long with
low-order word followed by high-order word.
DQ(Define Quad Word) : Each operand data is 4 words long i.e. 8 bytes and
is stored starting from lowest byte to higher bytes.
DT(Define Ten Bytes) : Each operand datum is 10 bytes long and is stored
starting from the lowest byte to higher bytes.
The character string is stored in between single quotes and each characters
ASCII codes are saved(stored) in successive locations(i.e. the first character
goes into the first byte assigned to the variable, then second character of the
string is stored at second byte and so on)
The character string is defined or pre-assigned using byte type.
The character string can be defined using DW and DD also, but they are
rarely used as the bytes are reversed and also string operands in a DW or DD
cannot exceed two characters in length.
Assembler Directives
23
Assembler Directives
When an question mark (?) is used along with mnemonic as second
mnemonic, it does not pre-assign any value but, the appropriate amount of
space is reserved.
DUP operator is used along with data size defining mnemonics to duplicate
multiple locations with the specified value in the braces.
ex: DUP(0) fills 0s in all the variable locations.
Assembler Directives
24
Assembler Directives
Hexadecimal : ex: 30H
Always any hexadecimal number is represented using a suffix of
character H.
Always a 0(zero) is to be appended in front of a hexadecimal number
that starts with alphabet.
An decimal data type is converted to equivalent hexadecimal number
and then stored in the memory locations.
BCD : ex: 37H
the difference between an hexadecimal number and an BCD number can be
made only from its usage.
ASCII : ex: Array
An ASCII value is always written in single quotes.
An variable of ASCII type will have the ASCII equivalent value of the
operand is stored in the memory.
An Alphanumeric character string given in single quotes as ASCII string
is case sensitive.
Assembler Directives
25
Assembler Directives
Program termination directive: END
END Label
As an END statement is needed to signal the end of a high-level language
program, the end directive indicate the end of a set of assembler language
code.
The label appears only in the termination of the main program in a program
structure,although all separately assembled program modules must conclude
with an END directive.
The label must also appear in the instruction to be executed first, the point at
which the program begins.
Specifically, the address associated with this label is the address that the
loader branches to after the program has been loaded and is ready for
execution.
Thus the END directive is put after the last statement of the program to tell
the assembler that it is the end of the program module/file.
Any statement after an END directive is ignored by the assembler.
Assembler Directives
26
Assembler Directives
Procedure Definitions directives:
PROC & ENDP
PROC
The PROC directive is used to identify the start of the
procedure.
The PROC directive follows a name given to the procedure.
After the PROC directive the label NEAR or FAR is used to
specify the type of the procedure.
ENDP
The ENDP directive is used along with the name of the
procedure to indicate the end of a procedure to the assembler.
Assembler Directives
27
Assembler Directives
Alignment Directives:
EVEN: This directive forces the address of the next byte to be even.
ORG :
ORG Constant Expression
The ORG directive causes the next byte to be associated with the byte
number expressed by the constant expression
ORG 1000H
X DW 2002H
[1000H] = 2002H
When an program is being assembled by the assembler (data
declarations or instruction statements) an location counter keeps track of
how many bytes it is from the start of a segment at any time.
The usage of EVEN directive tells the assembler to increment the
location counter to the next EVEN address if it is not already at even
address.
Assembler Directives
28
Assembler Directives
When the directive EVEN is used in data segment then the location counter
is simply be incremented to the next even address is necessary.
When the EVEN directive is used in code segment, the location counter will
be incremented to the next even address if necessary. A NOP instruction will
be inserted in the location incremented over.
EVEN Num1 DW 4
Assembler Directives
Expression_name: any valid identifier or label
Expression: Have the format of any valid operand or that evaluates to a
constant or any valid mnemonic.
Normally assigning names to expressions is done in the beginning to
the program
EQU (equate) : The directive EQU is used to assign a label with a value or a
symbol.
The use of this directive is just to reduce the recurrence of the
numerical values or constants in a program code.
While assembling, whenever the assembler comes across the label, it
substitutes the numerical value for that label and finds out the equivalent
code.
Using the EQU directive, even an instruction mnemonic can be
assigned with a label which can then be used in program in place of that
mnemonic.
Assembler Directives
30
Assembler Directives
Segment definition directives:
One of the tasks that an assembler should perform is to assign the
offsets of the labels and variables as it translates the instructions into
machine language, the same information has to be passed to the linker such
that various segments and modules are put together to form a program.
In order to explain the exact structure of each segment such that
variable and label offsets are assigned by the assembler
The data,extra data, or stack segment normally has the form:
Segment_name SEGMENT
storage definition directives
allocation and alignment directives
Segment_name ENDS
Assembler Directives
31
Assembler Directives
A code segment normally has the form of
Segment_name SEGMENT
Instructions and
Instruction-related directives
Segment_name ENDS
The directives SEGMENT and ENDS defines the starting and ending
boundaries of a segment and the Segment_name is identifier of the segment.
The definitions,allocations and directives between SEGMENT and ENDS
directives are contained within that particular segment.
In addition to specifying boundaries for the assembler to translate the
instructions, it must know the exact correspondence between the segments
and the segment registers, which allows the assembler to check for certain
types of errors and inconsistencies i.e., whether a variable is defined in the
appropriate data or stack segment.
Assembler Directives
32
Assembler Directives
The assignments of the segments to the segment registers are
made using the directive ASSUME whose format is:
ASSUME Assignment,..,Assignment
Where Assignment will be of the form:
Segment_register_name : Segment_name
It is important to note that the assume directive does not load the
segment addresses into the corresponding segment registers.
The segment addresses can not directly loaded into segment
registers, so general purpose registers are used for this purpose.
When an logical segment is set-up, a name is to be given as a
label for the segment and the label cannot have spaces within it,
but an underscore can be used.
Instruction mnemonic or assembler directive can not be used as
label.
Assembler Directives
33
Assembler Directives
A logical segment is not usually given a physical starting address when it is
declared. After the program is assembled and linked with other assembled
program modules, it is then assigned the physical address where it will be
loaded in the memory to run.
Additional terms/indicators like PUBLIC,WORD.etc are added along
with the segment directive statement to indicate some special way in which
we want the assembler to treat the segment.
Public: To indicate that this can be used with other segments with same
name from other assembly modules, when the modules are linked
together.
Word: Contents of this segment located on the next available word(even)
address when absolute addresses given to it, else it will be loaded on the
next available paragraph(16-bytes) address.
When the assembler starts reading a segment by default the location
counter is automatically set to 0000H, the ORG directive allows
programmer to set the location counter to a desired value at any point in
the program.
Assembler Directives
34
Assembler Directives
LABEL :
Used to give a name to the current value in the location counter.
INCLUDE : (Include Source Code From File)
Used to tell the assembler to insert a block of source code from the
named file into current source module.
GROUP: (Group Related Segments)
The group directive is used to tell the assembler to group the logical
segments named after the directive into one logical group segment.
This directive allows the contents of all the segments to be accessed
from the same group segment base.
The assembler sends a message to the linker telling it to link the
segments so that the segments are physically in the same 64K-Byte segment.
Assembler Directives
35
Assembler Directives
PUBLIC:
Any label/variable name 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.
GLOBAL : (Declare symbols as Public/Extern)
The GLOBAL directive is used in the place of a PUBLIC / EXTERN
directive.
The GLOBAL directive is used to make the symbol/variable available
to other modules.
EXTERN :
Used to tell the assembler that the names or labels following the
directive are in some other assembly module.
LOCAL :
The labels, variables, constants or procedures declared LOCAL in a
module are to be used only by that particular module.
Assembler Directives
36
Assembler Directives
NAME : (Logical Name Of A Module)
The NAME directive is used to assign a name to an assembly language
program module. The module,may now be referred to by its declared name.
The names, if selected to be suggestive, may point out the functions of
the different modules and hence may help in documentation.
FAR PTR :
This directive indicates to the assembler that the label following FAR
PTR is not available within the same segment and the address of the label is
of 32-bits i.e., 2-bytes offset followed by 2-bytes segment address.
NEAR PTR :
This directive indicates that the label following NEAR PTR is in the
same segment and needs only 16-bits i.e., 2 bytes offset to address it.
Assembler Directives
37
Operators
SHORT :
Used to tell the assembler that only a 1-byte displacement is needed to
code a jump instruction.
Using the SHORT operator saves 1-byte of memory by telling the
assembler that it needs to reserve only 1-byte for this particular jump.
The destination must be in the range of 128 bytes to +127 bytes from
the address of the instruction after the jump.
LENGTH :
Returns the number of units assigned to a variable (not available in
MASM)
SIZE :
Same as the LENGTH operator,except that it returns the number of
bytes instead of the number of units.
Assembler Directives
38
Operators
+ and - operators:
These operators represent arithmetic addition and subtraction respectively
and are typically used to add or subtract displacements( 8-bit or 16-bit ) to
base or index registers and stack or base pointer registers.
SEG :
Causes the segment address of the variable or label to be inserted as an
immediate data or operand (although the actual insertion is made by the
linker)
If the data_seg is assigned to the block of memory beginning at 05000H and
opr1 is in data_seg, then the instruction
MOV BX, SEG opr1 would put 0500 in BX register.
TYPE :
Tells the assembler to determine the data type of a specified variable/label
and replaces the TYPE label by the decided data type.
The assembler determines the number of bytes in the type of the variable,ex:
for the word type variable the data type is 2.
ex: MOV AX , TYPE STR will load 1 into AX if STR is a byte array and 2 is
STR is a word array
Assembler Directives
39
Operators
OFFSET : Offset of the label
Tells the assembler to determine the offset or displacement of a named
data item (variable) or procedure from the start of the segment which
contains it.
This operator is usually used to load the offset of a variable into a
register so that the variable can be accessed with one of the indexed
addressing modes.
PTR : ( Pointer)
Used to assign a specific type to a variable or a label .
It is necessary to do so in any instruction where the type of the operand
is not clear.
The PTR operator can be used to override the declared type of variable
and also to clarify our intentions when we use indirect jump instructions.
Assembler Directives
40