Hardware Reference
In-Depth Information
2.2 Assembly Language Program Structure
An assembly language program consists of a sequence of statements that tells the computer to
perform the desired operations. From a global point of view, an HCS12 assembly program consists
of three sections. In some cases, these sections can be mixed to provide better algorithm design.
1. Assembler directives . Assembler directives instruct the assembler how to process
subsequent assembly language instructions. Directives also provide a way to define
program constants and reserve space for dynamic variables. Some directives may also
set a location counter.
2. Assembly language instructions . These instructions are HCS12 instructions. Some
instructions are defined with labels.
3. Comments . There are two types of comments in an assembly program. The first
type is used to explain the function of a single instruction or directive. The second
type explains the function of a group of instructions or directives or a whole routine.
Adding comments improves the readability of a program.
Each line of an HCS12 assembly program, excluding certain special constructs, is made up of
four distinct fi elds. Some of the fi elds may be empty. The order of these fi elds is
1. Label
2. Operation
3. Operand
4. Comment
2.2.1 The Label Field
Labels are symbols defined by the user to identify memory locations in the programs and
data areas of the assembly module. For most instructions and assembler directives, the label is
optional. The rules for forming a label are as follows:
The label field can begin in column one or in any column if it is terminated by a
colon (:). It must begin with a letter (A-Z, a-z), and the letter can be followed by
letters, digits, or special symbols. Some assemblers permit special symbols to be used.
For example, the assembler from IAR Inc. allows a symbol to start with a question
mark (?), a character (@), and an underscore ( _ ) in addition to letters. Digits and the
dollar ($) character can also be used after the first character in the IAR assembler.
Most assemblers restrict the number of characters in a label name. The as12
assembler reference manual does not mention the limit. The IAR assembler allows
a user-defined symbol to have up to 255 characters.
The as12 assembler from several companies allows a label to be terminated by a
colon (:).
Example 2.1 Examples of Valid and Invalid Labels
The following instructions contain valid labels:
begin
ldaa
#10
; label begins in column 1
print:
jsr
hexout
; label is terminated by a colon
jmp
begin
; instruction references the label begin
 
Search WWH ::




Custom Search