The assembler supports the use of special symbols within the code. These symbols provide the assembler with additional information about the mnemonic instructions. In addition, these symbols tell the assembler how to process the source code.
Data Type Constants
The AS11 assembler supports five numeric data type contants: decimal, hex, binary, octal and ASCII characters. Numbers are considered decimal unless they are preceded by a special symbol. If the user wants the assembler to interpret numbers as hex values, the numbers must be preceded by the “$” symbol. If numeric values are to be interpreted as binary, they must be preceded by the “%” symbol. If numeric values are to be interpreted as octal, they must be preceded by the “@” symbol. ASCII characters will be interpreted as the ASCII character codes when they are preceded by the single quote (’) character. It is common practice to provide the trailing single quote, yet the AS11 assembler does not require it. Examples of these data types are shown in Figure 7.3.
The decimal, hex and ASCII data types are the most common since they are read most easily. The binary type is used in place of hex when specific bits are being emphasized, but it is more difficult to read. The octal data type is rarely used with modern computers. Octal is a grouping of three binary digits.
Directives
The assembler supports a special set of commands called directives. A directive tells the assembler what to do and indirectly affects the resulting machine code. It is an instruction to the assembler. However, a directive is not an instruction that is converted to machine code. For this reason, the directives are sometimes called pseudo-ops. Figure 7.4 summarizes the directives supported by the AS11 assembler and what functionality each directive provides.
165 1. How can a programmer make the code more readable?
2. What are two different types of comments that can be used in a source file? 3. How can white space be used to make the code more readable?
86 7F LDAA #127 ;decimal 127 will be converted 86 2B LDAA
LDAA LDAA LDAA
#$2B ;hex 2B will be used
86 D6 #%11010110 ;binary 11010110 will be converted 86 9C #@234 ;octal 234 will be converted 86 41 #'A' ;'A' will be converted to ASCII code Figure 7.3 Assembler Data Types
One of the directives is a control directive. Control directives do not have a label preceding them as do the data directives. ORG is a control directive. Data directives define the data used by a program. They allocate memory for that data. Data directives are preceded by a label. The address of the data assigned by the data directive is assigned to this label; thus the label points to the data in memory.
Figure 7.5 illustrates how each of these directives is used. The source code block starts with four EQU directives. They are used to assign addresses to three labels PORTB, DLY10MS and OUTSTR, as well as a byte of data to a data parameter called TEN. The first ORG directive sets the default address of the machine code to the beginning of RAM at $0000. Next, an eight-byte memory block is reserved by the use of the RMB directive. The address of the first of these eight bytes is assigned to the label BUFFER (BUFFER = $0000). Then, two bytes are reserved and zeroed. The label ZERO is the address of the first of these two bytes (ZERO = $0008).
A second ORG statement appears in the code that changes the default address memory address to $0100. At this point in the source the program instructions start. The program consists of all the instructions up to and including the SWI instruction. Following the end of the program is a message in memory. The message is assigned to memory by the FCC directive. FCC converts each character of the message to the ASCII character codes.
166
Directive Syntax Function
BSZ BSZ n Block Store Zeros—Reserves n number of memory bytes and fills them with zero.
EQU EQU expression Equate—Causes the value of the expression to replace the label in the listing and machine code files.
FCB FCB n Form Constant Byte—Causes a byte of data n to be assigned to specific memory locations. Successive bytes can be separated by commas.
FCC FCC ‘String’ Form Constant Character—Causes ASCII codes to be assigned to specific memory locations. The characters of String are assigned to sequential memory locations. The String must appear between single quotes (‘String’).
FDB FDB n Form Double Byte—same as FCB except double bytes are formed.
FILL FILL val, n Fill Memory—Causes n memory locations to be filled with constant val.
ORG ORG address Origin—Causes the following code to be assigned to a memory block starting with address.
RMB RMB n Reserve Memory Byte—Causes n number of memory locations to be reserved.
ZMB ZMB n Zero Memory Byte—same as BSZ.
Figure 7.4 AS11 Assembler Directives
Assembler Arithmetic
Expressions can be used in many places throughout the code. The assembler will resolve the expression before making the assignment. If the label BUFFER equals the address $0000, then the expression BUFFER + 1 = $0001. An expression can consist of labels, constants or the asterisk character (denotes the value of the current memory address) joined by operators.
The AS11 supports eight operators, as shown in Figure 7.6. Expressions are evaluated from left to right, and there is no provision for parenthesized expressions. How these are used is illustrated in the comments of Figure 7.7.
167 0001 * program to print message on the monitor ten times
0002 * designed to demonstrate the use of various directives 0003
0004 1004 PORTB EQU $1004 ;assign address $1004 to label PORTB 0005 e2e5 DLY10MS EQU $E2E5 ;assign address $E2E5 to label DLY10MS 0006 ffc7 OUTSTR EQU $FFC7 ;assign address $FFC7 to label OUTSTR 0007
0008 000a TEN EQU 10 ;assign decimal value 10 to label TEN 0009
0010
0011 0000 ORG $0000 ;set default address to $0000 0012
0013 0000 BUFFER RMB 8 ;reserve 8 bytes starting at BUFFER 0014 0008 00 00 ZERO ZMB 2 ;zero 2 bytes following 8 byte BUFFER 0015
0016
0017 0100 ORG $0100 ;set default address to $0100 0018
0019 0100 18 ce 00 00 MAIN LDY #BUFFER ;load address of buffer into Y 0020 0104 86 0a LDAA #TEN ;load value of TEN into A 0021
0022 0106 bd e2 e5 LOOP JSR DLY10MS ;call subroutine at address DLY10MS 0023 0109 ce 01 19 LDX #MSG ;load address of MSG into X 0024 010c bd ff c7 JSR OUTSTR ;output message to the monitor 0025 010f 18 a7 00 STAA 0,Y ;store value of A at Y+0 0026 0112 b7 10 04 STAA PORTB ;store value of A at PORTB 0027 0115 4a DECA ;decrement counter 0028 0116 26 ee BNE LOOP ;if not done, do it again 0029
0030 0118 3f SWI 0031
0032 0119 57 61 69 74 65 64 MSG FCC 'Waited 10 ms' 20 31 30 20 6d 73
0033 0125 04 FCB $04 ;EOT character - delimiter
Operator Description + Integer addition - Integer subtraction * Integer multiplication / Integer division % Integer remainder & Bitwise AND
| Bitwise OR ^ Bitwise XOR
Figure 7.5 Example Using Directives
Figure 7.6 Operators Defined for Expressions