Hardware Reference
In-Depth Information
2.3 Assembler Directives
Assembler directives look just like instructions in an assembly language program, but they
tell the assembler to do something other than create the machine code for an instruction. The
available assembler directives vary with the assembler. Interested readers should refer to the
user's manual of the specific assembler for details.
We discuss assembler directives supported by the as12 in detail here. In the following dis-
cussion, statements enclosed in square brackets [ ] are optional. All directives and assembly
instructions can be in either upper- or lowercase.
end
The end directive is used to end a program to be processed by the assembler. In general, an
assembly program looks like this:
(your program)
end
The end directive indicates the logical end of the source program. Any statement following the
end directive is ignored. A warning message will occur if the end directive is missing from the
source code; however, the program will still be assembled correctly.
org (origin)
The assembler uses a location counter to keep track of the memory location where the
next machine code byte should be placed. If the programmer wants to force the program or data
array to start from a certain memory location, then the org directive can be used. For example,
the statement
org $1000
forces the location counter to be set to $1000.
The org directive is mainly used to force a data table or a segment of instructions to start
with a certain address. As a general rule, this directive should be used as infrequently as pos-
sible. Using too many orgs will make your program less reusable.
db (define byte), dc.b (define constant byte), fcb (form constant byte)
These three directives define the value of a byte or bytes that will be placed at a given
memory location. The db (or dc.b or fcb ) directive assigns the value of the expression to the
memory location pointed to by the location counter. Then the location counter is incremented.
Multiple bytes can be defined at a time by using commas to separate the arguments. For ex-
ample, the statement
array db $11,$22,$33,$44,$55
initializes 5 bytes in memory to
$11
$22
$33
$44
$55
and the assembler will use array as the symbolic address of the fi rst byte whose initial value is
$11. The program can also force these 5 bytes to a certain address by adding the org directive.
For example, the sequence
org
$1000
array
db
$11,$22,$33,$44,$55
 
Search WWH ::




Custom Search