📄 asmlnk.doc
字号:
b: ldx #btable ;get table address lda #0d48 ;table length 1$: clr ,x+ ;clear deca bne 1$ 1.3.4 Current Location Counter The period (.) is the symbol for the current location coun- ter. When used in the operand field of an instruction, the period represents the address of the first byte of the instruction: AS: ldx #. ;The period (.) refers to ;the address of the ldx ;instruction. When used in the operand field of an ASxxxx directive, it represents the address of the current byte or word: QK = 0 .word 0xFFFE,.+4,QK ;The operand .+4 in the .word ;directive represents a value ;stored in the second of the ;three words during assembly. If we assume the current value of the program counter is 0H0200, then during assembly, ASxxxx reserves three words of storage starting at location 0H0200. The first value, a hex- idecimal constant FFFE, will be stored at location 0H0200. The second value represented by .+4 will be stored at location 0H0202, its value will be 0H0206 ( = 0H0202 + 4). The third value defined by the symbol QK will be placed at location 0H0204. At the beginning of each assembly pass, ASxxxx resets the lo- cation counter. Normally, consecutive memory locations are as- signed to each byte of object code generated. However, the value of the location counter can be changed through a direct assignment statement of the following form: THE ASSEMBLER PAGE 1-13 SYMBOLS AND EXPRESSIONS . = . + expression The new location counter can only be specified relative to the current location counter. Neglecting to specify the current program counter along with the expression on the right side of the assignment operator will generate the (.) error. (Absolute program areas may use the .org directive to specify the absolute location of the current program counter.) The following coding illustrates the use of the current location counter: .area CODE1 (ABS) ;program area CODE1 ;is ABSOLUTE .org 0H100 ;set location to ;0H100 absolute num1: ldx #.+0H10 ;The label num1 has ;the value 0H100. ;X is loaded with ;0H100 + 0H10 .org 0H130 ;location counter ;set to 0H130 num2: ldy #. ;The label num2 has ;the value 0H130. ;Y is loaded with ;value 0H130. .area CODE2 (REL) ;program area CODE2 ;is RELOCATABLE . = . + 0H20 ;Set location counter ;to relocatable 0H20 of ;the program section. num3: .word 0 ;The label num3 has ;the value ;of relocatable 0H20. . = . + 0H40 ;will reserve 0H40 ;bytes of storage as will .blkb 0H40 ;or .blkw 0H20 The .blkb and .blkw directives are the preferred methods of allocating space. THE ASSEMBLER PAGE 1-14 SYMBOLS AND EXPRESSIONS 1.3.5 Numbers ASxxxx assumes that all numbers in the source program are to be interpreted in decimal radix unless otherwise specified. The .radix directive may be used to specify the default as octal, decimal, or hexidecimal. Individual numbers can be designated as binary, octal, decimal, or hexidecimal through the temporary radix prefixes shown in table 6. Negative numbers must be preceeded by a minus sign; ASxxxx translates such numbers into two's complement form. Positive numbers may (but need not) be preceeded by a plus sign. Numbers are always considered to be absolute values, therefor they are never relocatable. 1.3.6 Terms A term is a component of an expression and may be one of the following: 1. A number. 2. A symbol: 1. A period (.) specified in an expression causes the current location counter to be used. 2. A User-defined symbol. 3. An undefined symbol is assigned a value of zero and inserted in the User-Defined symbol table as an un- defined symbol. 3. A single quote followed by a single ascii character, or a double quote followed by two ascii characters. 4. An expression enclosed in parenthesis. Any expression so enclosed is evaluated and reduced to a single term before the remainder of the expression in which it ap- pears is evaluated. Parenthesis, for example, may be used to alter the left-to-right evaluation of expres- sions, (as in A*B+C versus A*(B+C)), or to apply a un- ary operator to an entire expression (as in -(A+B)). 5. A unary operator followed by a symbol or number. THE ASSEMBLER PAGE 1-15 SYMBOLS AND EXPRESSIONS 1.3.7 Expressions Expressions are combinations of terms joined together by binary operators. Expressions reduce to a 16-bit value. The evaluation of an expression includes the determination of its attributes. A resultant expression value may be one of three types (as described later in this section): relocatable, ab- solute, and external. Expressions are evaluate with an operand hierarchy as follows: * / % multiplication, division, and modulus first. + - addition and subtraction second. << >> left shift and right shift third. ^ exclusive or fourth. & logical and fifth. | logical or last except that unary operators take precedence over binary operators. A missing or illegal operator terminates the expression analysis, causing error codes (o) and/or (q) to be generated depending upon the context of the expression itself. At assembly time the value of an external (global) expression is equal to the value of the absolute part of that expression. For example, the expression external+4, where 'external' is an external symbol, has the value of 4. This expression, however, when evaluated at link time takes on the resolved value of the symbol 'external', plus 4. Expressions, when evaluated by ASxxxx, are one of three types: relocatable, absolute, or external. The following dis- tinctions are important: 1. An expression is relocatable if its value is fixed re- lative to the base address of the program area in which it appears; it will have an offset value added at link time. Terms that contain labels defined in relocatable program areas will have a relocatable value; THE ASSEMBLER PAGE 1-16 SYMBOLS AND EXPRESSIONS similarly, a period (.) in a relocatable program area, representing the value of the current program location counter, will also have a relocatable value. 2. An expression is absolute if its value is fixed. An expression whose terms are numbers and ascii characters will reduce to an absolute value. A relocatable ex- pression or term minus a relocatable term, where both elements being evaluated belong to the same program area, is an absolute expression. This is because every term in a program area has the same relocation bias. When one term is subtracted from the other the reloca- tion bias is zero. 3. An expression is external (or global) if it contains a single global reference (plus or minus an absolute ex- pression value) that is not defined within the current program. Thus, an external expression is only par- tially defined following assembly and must be resolved at link time. 1.4 GENERAL ASSEMBLER DIRECTIVES An ASxxxx directive is placed in the operator field of the source line. Only one directive is allowed per source line. Each directive may have a blank operand field or one or more operands. Legal operands differ with each directive. 1.4.1 .module Directive Format: .module string The .module directive causes the string to be included in the assemblers output file as an identifier for this particular ob- ject module. The string may be from 1 to 8 characters in length. Only one identifier is allowed per assembled module. The main use of this directive is to allow the linker to report a modules' use of undefined symbols. At link time all undefined symbols are reported and the modules referencing them are listed. THE ASSEMBLER PAGE 1-17 GENERAL ASSEMBLER DIRECTIVES 1.4.2 .title Directive Format: .title string The .title directive provides a character string to be placed on the second line of each page during listing. 1.4.3 .sbttl Directive Format: .sbttl string The .sbttl directive provides a character string to be placed on the third line of each page during listing. 1.4.4 .page Directive Format: .page The .page directive causes a page ejection with a new heading to be printed. The new page occurs after the next line of the source program is processed, this allows an immediately follow- ing .sbttl directive to appear on the new page. The .page source line will not appear in the file listing. Paging may be disabled by invoking the -p directive. 1.4.5 .byte and .db Directives Format: .byte exp ;Stores the binary value .db exp ;of the expression in the ;next byte. .byte exp1,exp2,expn ;Stores the binary values .db exp1,exp2,expn ;of the list of expressions ;in successive bytes. where: exp, represent expressions that will be exp1, truncated to 8-bits of data. . Each expression will be calculated
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -