Vous êtes sur la page 1sur 5

Chapter 3

Assembler Directives
The direction to the assembler is commonly called assembler directives or pseudo
operation. In other word, the assembler directive is a message that tells the assembler
something it needs to know in order to carry out the assembling process.
Some of the assembler directives are explained below
1. SEGMENT and ENDS directives
The S!"#!$T and !$%S directive are used to identify a group of data items or a
group of instructions that you want to put together in a particular segment. & group of
data statements or a group of instruction statements contained between S!"#!$T
and !$%S directive is called logical segment. In example 3.', %&T&()!*!
S!"#!$T and %&T&()!*! !$%S setup a logical segment named %&T&()!*!.
%&T&()!*! is an arbitrary name +user defined,.

*ules to define segment name
- Segment name can be up to 3' characters.
- Cannot use space bar in a name but underscore can be used separate words in a
name.
- Cannot use instruction mnemonics as a segment name or label.
2. Naming data and addresses- EQU, DB, D and DD directives
.rogram work with three general categories of data- constants, variables and
addresses.
- The value of constant does not change during the execution of a program.
- & variable is a name given to a data item which can change during the execution
of a program.
- &ddress is the reference or location to the data.
EQU directive
The !/0 or !1uate directive is used to assign names to constants used in the program.
!xample bt !/0 23)

&%% &4, bt is e1uivalent to &%% &4, 23).
Constants can be declared at the start of the program and used later many times.
DB directive
The %5 directive after a name specifies that the data is of type byte.
!xample temperature %5 67)
Tempetarure %5 67), 38), 36), 29) will declare a data structure +array, of 3
bytes.
'
If you don:t want to initiali;e the value in a variable, then
temperature %5 <
D directive
%= is used to specify that the data is of type word +'2 bits,.
!xample' temperature %= 6>3&)
!xample6 temperature %= 6 %0. +>,
.oints defining example6
Sets aside storage for two words in memory and gives the starting
address of the frst word with the name temperature.
DUP (0) part of the statement tells the assembler to initialize the two
words to all zeros.
DD directive
%% is used to specify that the data is of type double word +36 bits,.
?alue' %= '633@278)
!. ASSUME directive
The &SS0#! directive is used to tell assembler the name of the logical segment
it should use for the specified segment.
E"am#le$ &SS0#! CS CA%!
Tells the assembler that instructions for a program are in the logical segment
named CA%!.
&SS0#! %S%&T&
Similarly segment named %&T& refers to data segment.
If for example, the assembler reads the statement #A? &B, C5BD after it reads
the &SS0#!, it will know that the memory location referred to by C5BD is in
logical segment %&T&.
%. END Directive
The !$% directive is put after the last statement of the program to tell the
assembler that this is the end of the program module. The assembler will ignore
any statements after !$% directive.
&. '()* directive
The .*AC directive is used to identify the start of a procedure.
!xample S#&*T(%I?I%! .*AC E&*
Identifies the start of a procedure named S#&*T(%I?I%! and tells the
assembler that the procedure is far +in a segment with a different name from the
one that contains the instruction that calls the procedure.,
The .*AC directive is used with the END' directive to bracket a procedure.
6
Assembl+ lang,age #r-gram devel-#ment t--ls
The following section gives you an introduction to several common program
development tools
1. Edit-r
&n editor is a program which allows us to create a file containing the assembly
language statements for the program.
!xamples $otepad, =ord .ad etc.
=hen we have typed all the programs we should save the file in any secondary
storage media. This file is called source file.
2. Assembler
&n assembler is a program that is used to translate assembly language mnemonics for
instructions to the corresponding binary codes. =hen you run the assembler, it reads
the source file of the program from the disk. There are two steps
a. .irst #ass
An the first pass, the assembler determines the displacement of named data items, the
offset of labels etc and puts the information in the symbol table.
b. Sec-nd #ass
An the second pass, the assembler produces the binary codes for each instruction and
inserts the offsets etc that is calculated during the first pass.
The assembler generates two files
a. )b/ect 0ile 1.-b/2
The obFect file contains the binary codes for the instruction and information about the
addresses of the instruction.
b. 3ist 0ile 1.lst2
The list file contains assembly language instructions, binary codes for each
instruction and offset for each instruction. The list file also contains any type of
syntax errors in the source program.
!. 3in4er
& linker is a program used to Foin several obFect files into one large obFect file. =hen
writing large programs, it is usually much more efficient to divide the large program
into smaller modules. !ach module can be individually written, tested and debugged.
Then when all modules work, their obFect modules can be linked together to form a
large functioning program.
%. 3-cat-r
& locator is a program used to assign the specific address of where the segments of
obFect code are to be loaded into memory.
&. Deb,gger
& debugger is a program which allows us to load the obFect code program into system
memory, execute the program and debug it. %ebugger can be used if the program
3
re1uires no external hardware or re1uires only hardware accessible directly from the
microcomputer.
5. Em,lat-r
&n emulator is a mixture of hardware and software usually used to test and debug the
hardware and software to the external system.
Macr- Assembler
#acro assembler translates a program written in macro language into machine
language. The macro assembler replaces the macro name with the appropriate
instruction se1uence each time it encounters a macro name.
#acro can be compared with a procedure but each one of them has specific
advantages and disadvantages. =hen the repeated group of instructions is too short or
not appropriate to be written as a procedure, we use a macro. & macro is a group of
instructions we bracket to give a name at the start of the program. !ach time we call a
macro in the program, the assembler will insert the defined group of instructions in
place of a call.
Comparison between macro and procedure
- In macro, the generated machine codes are right in line with the rest of the
program, the program does not have to go off to a procedure and return. Therefore
using a macro avoids the overhead time involved in calling and returning from a
procedure.
- & disadvantage of generating in line code each time a macro is called is the
utili;ation of memory than using a procedure.
%efining and calling a macro
.ush(all #&C*A
.0S)E
.0S)&B
.0S) 5B
.0S)CB
.0S)%B
.0S)5.
.0S)5I
.0S)%I
.0IS)%S
.0S)!S
.0S)SS
!$%#

The push(all #&C*A statement identifies the start of the macro and gives the macro a
name. The !$%# identifies the end of a macro.
$ow to call the macro in our procedure we simply put in the name of the macro.
3
5reath(rate .*AC E&*
&SS0#! CS.*AC!%0*!S, %S.&TI!$T(.&*&#!T!*S
.ush(all Gmacro call
#A? &B, .&TI!$T(.&*&#!T!*S Ginitiali;e data
#A? %S, &B
T+#es -0 assembler
a. )ne #ass assembler
This assembler goes through the assembly language program once and translates the
assembly language program. This assembler has the program defining forward
reference. This means that the Fump instruction using an address that appear later in
the program must be defined by the programmer after the program is assembled.
b. T6- #ass assembler
This assembler scans the assembly language program twice.
- In the first pass, the assembler generates the table of symbols. & symbol table
consists of labels with address assigned to them. In this way labels can be used for
H0#. statements and no address calculation is to be done by the user.
- In the second pass, the assembler translates the assembly language program into
the machine code. The two pass assembler is hence more efficient and easier to
use.
Assembl+ 3ang,age 7nstr,cti-n .-rmat
!ach instruction in assembly language is composed of three or four fields.
4abel field
Instruction mnemonic or op-code field
Aperand field
Comment field
!xample
3ABE3 MNEM)N7* )'E(AND *)MMENT
Start #?I a, '>) Gmove '>) into accumulator
&%I 6>) Gadd 6>) to the content of accumulator
4BI h, >6>>) Gload register pair with >6>>)
#A? m, a Gstore the content in the memory
H#. Start Grepeat
@

Vous aimerez peut-être aussi