📄 asmlnk.doc
字号:
The ASxxxx assemblers were written following the style of several cross assemblers found in the Digital Equipment Corpora- tion Users Society (DECUS) distribution of the C programming language. The DECUS code was provided with no documentation as to the input syntax or the output format. Study of the code revealed that the unknown author of the code had attempted to formulate an assembler with attributes similiar to those of the PDP-11 MACRO assembler (without macro's). The incomplete code from the DECUS C distribution has been largely rewritten, only the program structure, and C source file organization remains relatively unchanged. However, I wish to thank the author for his contribution to this set of assemblers. The ASLINK program was written as a companion to the ASxxxx assemblers, its design and implementation was not derived from any other work. The ASxxxx assemblers and the ASLINK relocating linker are placed in the Public Domain. Publication or distribution of these programs for non-commercial use is hereby granted with the stipulation that the copyright notice be included with all copies. I would greatly appreciate receiving the details of any changes, additions, or errors pertaining to these programs and will attempt to incorporate any fixes or generally useful changes in a future update to these programs. Alan R. Baldwin Kent State University Physics Department Kent, Ohio 44242 baldwin@shop-pdp.kent.edu tel: (216) 672 2531 fax: (216) 672 2959 CHAPTER 1 THE ASSEMBLER 1.1 THE ASXXXX ASSEMBLERS The ASxxxx assemblers are a series of microprocessor assem- blers written in the C programming language. Each assembler has a device specific section which includes: 1. device description, byte order, and file extension in- formation 2. a table of the assembler general directives, special device directives, assembler mnemonics and associated operation codes 3. machine specific code for processing the device mnemon- ics, addressing modes, and special directives The device specific information is detailed in the appendices. The assemblers have a common device independent section which handles the details of file input/output, symbol table genera- tion, program/data areas, expression analysis, and assembler directive processing. The assemblers provide the following features: 1. Command string control of assembly functions 2. Alphabetized, formatted symbol table listing 3. Relocatable object modules 4. Global symbols for linking object modules 5. Conditional assembly directives THE ASSEMBLER PAGE 1-2 THE ASXXXX ASSEMBLERS 6. Program sectioning directives ASxxxx assembles one or more source files into a single relo- catable ascii object file. The output of the ASxxxx assemblers consists of an ascii relocatable object file(*.rel), an assembly listing file(*.lst), and a symbol file(*.sym). 1.1.1 Assembly Pass 1 During pass 1, ASxxxx opens all source files and performs a rudimenatry assembly of each source statement. During this pro- cess all symbol tables are built, program sections defined, and number of bytes for each assembled source line is estimated. At the end of pass 1 all undefined symbols may be made global (external) using the ASxxxx switch -g, otherwise undefined sym- bols will be flagged as errors during succeeding passes. 1.1.2 Assembly Pass 2 During pass 2 the ASxxxx assembler resolves forward refer- ences and determines the number of bytes for each assembled line. The number of bytes used by a particular assembler in- struction may depend upon the addressing mode, whether the in- struction allows multiple forms based upon the relative distance to the addressed location, or other factors. Pass 2 resolves these cases and determines the address of all symbols. 1.1.3 Assembly Pass 3 Pass 3 by the assembler generates the listing file, the relo- catable output file, and the symbol tables. Also during pass 3 the errors will be reported. The relocatable object file is an ascii file containing sym- bol references and definitions, program area definitions, and the relocatable assembled code, the linker ASLINK will use this information to generate an absolute load file (Motorola or Intel formats). THE ASSEMBLER PAGE 1-3 SOURCE PROGRAM FORMAT 1.2 SOURCE PROGRAM FORMAT 1.2.1 Statement Format A source program is composed of assembly-language statements. Each statement must be completed on one line. A line may con- tain a maximum of 128 characters, longer lines are truncated and lost. An ASxxxx assembler statement may have as many as four fields. These fields are identified by their order within the statement and/or by separating characters between fields. The general format of the ASxxxx statement is: [label:] Operator Operand [;Comment(s)] The label and comment fields are optional. The operator and operand fields are interdependent. The operator field may be an assembler directive or an assembly mnemonic. The operand field may be optional or required as defined in the context of the operator. ASxxxx interprets and processes source statements one at a time. Each statement causes a particular operation to be per- formed. 1.2.1.1 Label Field - A label is a user-defined symbol which is assigned the value of the current location counter and entered into the user de- fined symbol table. The current location counter is used by ASxxxx to assign memory addresses to the source program state- ments as they are encountered during the assembly process. Thus a label is a means of symbolically referring to a specific statement. When a program section is absolute, the value of the current location counter is absolute; its value references an absolute memory address. Similarly, when a program section is relocat- able, the value of the current location counter is relocatable. A relocation bias calculated at link time is added to the ap- parent value of the current location counter to establish its effective absolute address at execution time. (The user can also force the linker to relocate sections defined as absolute. This may be required under special circumstances.) If present, a label must be the first field in a source statement and must be terminated by a colon (:). For example, THE ASSEMBLER PAGE 1-4 SOURCE PROGRAM FORMAT if the value of the current location counter is absolute 01F0(H), the statement: abcd: nop assigns the value 01F0(H) to the label abcd. If the location counter value were relocatable, the final value of abcd would be 01F0(H)+K, where K represents the relocation bias of the program section, as calculated by the linker at link time. More than one label may appear within a single label field. Each label so specified is assigned the same address value. For example, if the value of the current location counter is 1FF0(H), the multiple labels in the following statement are each assigned the value 1FF0(H): abcd: aq: $abc: nop Multiple labels may also appear on successive lines. For ex- ample, the statements abcd: aq: $abc: nop likewise cause the same value to be assigned to all three la- bels. A double colon (::) defines the label as a global symbol. For example, the statement abcd:: nop establishes the label abcd as a global symbol. The distinguish- ing attribute of a global symbol is that it can be referenced from within an object module other than the module in which the symbol is defined. References to this label in other modules are resolved when the modules are linked as a composite execut- able image. The legal characters for defining labels are: A through Z a through z 0 through 9 . (Period) $ (Dollar sign) _ (underscore) A label may be any length, however, only the first eight (8) characters are significant and, therefore must be unique among all labels in the source program (not necessarily among THE ASSEMBLER PAGE 1-5 SOURCE PROGRAM FORMAT separately compiled modules). An error code(s) (m or p) will be generated in the assembly listing if the first eight characters in two or more labels are the same. The m code is caused by the redeclaration of the symbol or its reference by another state- ment. The p code is generated because the symbols location is changing on each pass through the source file. The label must not start with the characters 0-9, as this designates a local symbol with special attributes described in a later section. The label must not start with the sequence $$, as this represents the temporary radix 16 for constants. 1.2.1.2 Operator Field - The operator field specifies the action to be performed. It may consist of an instruction mnemonic (op code) or an assembler directive. When the operator is an instruction mnemonic, a machine in- struction is generated and the assembler evaluates the addresses of the operands which follow. When the operator is a directive ASxxxx performs certain control actions or processing operations during assembly of the source program. Leading and trailing spaces or tabs in the operator field have no significance; such characters serve only to separate the operator field from the preceeding and following fields. An operator is terminated by a space, tab or end of line. 1.2.1.3 Operand Field - When the operator is an instruction mnemonic (op code), the operand field contains program variables that are to be evaluated/manipulated by the operator. Operands may be expressions or symbols, depending on the operator. Multiple expressions used in the operand fields may be separated by a comma. An operand should be preceeded by an operator field; if it is not, the statement will give an error (q or o). All operands following instruction mnemonics are treated as expressions. The operand field is terminated by a semicolon when the field
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -