(Commentaire sous forme de note Flex User Group 11/11/1997 19:25:53 This document has been created on behalf of the FLEX User Group to keep FLEX Alive. Many thanks to the copyright holder of this manual for releasing the copyright to the Flex User Group.) FLEX 6809 Relocating Assembler Technical Systems Consultants, Inc. Table of Contents Table of Contents I. Introduction 1 II. Getting the System Started 6 III. Assembler Operation 13 IV. The Instruction Set 22 V. Standard Directives 35 VI. Conditional Assembly 47 VII. Macros 51 VIII. Special Features 60 IX. Error and Warning Messages 67 X. Adapting to Your System 70 XI. Appendix A: List of Prime Numbers from 773 to 2239 73 -iii FLEX 6809 Relocating Assembler FLEX 6809 Relocating Assembler INTRODUCTION This manual describes the operation and use of the 6809 Relocating Mnemonic Assembler for the 6809 FLEXÔ Disk Operating System. The assembler accepts all standard Motorola mnemonics for the 6809 instruction set as well as all standard 6800 and 6801 mnemonics. Relocation, external references, macros and conditional assembly are supported as well as numerous other directives for convenient assembler control. The assembler executes in two passes and can accept any size file so long as sufficient memory is installed to contain the symbol table. Output is in the form of a relocatable binary disk file as well as an assembled listing output which may be routed to a printer or to a disk file through the facilities of FLEX. This manual is by no means intended to teach the reader assembly language programming nor even the full details of the 6809 instruction set. It assumes the user has a working knowledge of assembly language programming and a manual describing the 6809 instruction set and addressing modes in full. The former can be acquired through any of a large number of books available on assembly programming, the latter from the 6809 hardware manufacturer or seller. Throughout the manual a couple of notational conventions are used which are explained here. The first is the use of angle brackets (’’ and ’’). These are often used to enclose the description of a particular item. This item might be anything from a filename to a macro parameter. It is enclosed in angle brackets to show that it is a single item even though the description may require several words. The second notation is the use of square brackets (’[’ and ’]’). These are used to enclose an optional item. Absolute Assemblers An absolute assembler, such as the FLEX "ASMB", produces absolute machine code in which all addresses will be correct only if the program is loaded at the specified locations. For example, a program ORG’ed at $1000, contains a JMP instruction. At execution time, control will be transfered to the intended location by the JMP statement only if the program resides at $1000. FLEX is a trademark of Technical Systems Consultants, Inc. -1 FLEX 6809 Relocating Assembler FLEX 6809 Relocating Assembler **** * cntchar - count the number of characters * in a null terminated string. * * exit (b)=count of the characters 1000 ORG $1000 1000 8E 100D CNTCHAR LDX #STRING GET ADDR OF STRING 1003 5F CLRB SET COUNT TO ZERO 1004 A6 80 LOOP LDA 0,X+ GET A CHARACTER 1006 27 04 BEQ DONE IF END OF STRING 1008 5C INCB COUNT THE CHARACTER 1009 7E 1004 JMP LOOP GET NEXT CHARACTER 100C 39 DONE RTS RETURN 100D 48 4F 57 20 STRING FCC ’HOW MANY CHARS ?’,0 The program segment will work as intended only if it is loaded at $1000. If CNTCHAR was instead loaded at $2000, at the time the JMP instruction is encountered, control would transfer to $1004; however, we would intend for control to go to $2004. Suppose it is not possible to know the starting location of a program segment. Such would be the case if each member of a team of programmers was responsible for developing a program segment. Since each segment is being developed independently of the others, it is not possible to know where one segment ends and, therefore, where the next is to begin. Position Independence VS. Relocatability The 6809 instruction set offers one solution to this problem. PC relative addressing uses the Program Counter (PC) register as an index register in much the same manner as X,Y,U, or S is used as an index register. PC relative addressing generates. offs@ts (or indexes) based on the current PC value. Using this addressing mode, the program will work as intended regardless of its position in memory. We can make CNTCHR position independent by replacing the JMP instruction with BRA, and LDX immediate with LEAX (PC offset indexing). Our position independent version of CNTCHR would look like this: -2 FLEX 6809 Relocating Assembler FLEX 6809 Relocating Assembler * cntchar - count the number of characters * in a null terminated string. * * exit (b)=count of the characters 1000 ORG $1000 1000 30 8D 0009 CNTCHAR LEAX STRING,PCR GET ADDR OF STRING 1004 5F CLRB SET COUNT TO ZERO 1005 A6 80 LOOP LDA 0,X+ GET A CHARACTER 1007 27 03 BEQ DONE IF END OF STRING 1009 5C INCB COUNT THE CHARACTER 100A 20 F9 BRA LOOP GET NEXT CHARACTER 100C 39 DONE RTS RETURN 100D 48 4F 57 20 STRING FCC ’HOW MANY CHARS ?’,0 Notice that this CNTCHAR contains no references to absolute addresses. It will execute as intended regardless of where it is placed in memory. In general, however, position independent code contains more op code bytes and takes longer to execute than absolute code. Also, the programmer must make an effort not to use certain instructions, or restrict usage to particular addressing modes, so that the rules of postion independence are not violated. All code, on the other hand, can be considered "relocatable" when assembled using a Relocating Assembler. Relocating Assemblers and Loaders Relocatable code is generated by a relocating assembler in such a way that addresses are not bound to absolute locations at "assembly time"; this binding of the address fields is deferred until "load time". A Relocating Loader binds the addresses at the time the program is brought into memory (loaded) to be executed. The binding or adjustment of the address fields is termed relocation. Because any code can be considered "relocatable", one can take advantage of the-speed and space savings of absolute code, with the adjustment of the address fields deferred until load time. To illustrate how the Relocating Assembler and Linking-Loader work in conjunction with each other, we will present another version of CNTCHAR. Note that it does not contain any ORG statements, and that the code starts at location 0. -3 FLEX 6809 Relocating Assembler FLEX 6809 Relocating Assembler * cntchar - count the number of characters * in a null terminated string. * exit (b)=count of the characters + 0000 8E 000D CNTCHAR LDX #STRING GET ADDR OF STRING 0003 5F CLRB SET COUNT TO ZERO 0004 A6 80 LOOP LDA 0,X+ GET A CHARACTER 0006 27 04 BEQ DONE IF END OF STRING 0008 5C INCB COUNT THE CHARACTER +0009 7E 0004 JMP LOOP GET NEXT CHARACTER 000C 39 DONE RTS RETURN 000D 48 4F 57 20 STRING FCC ’HOW MANY CHARS ?’,0 A plus sign in front of an instruction indicates that the address field of that instruction must be increased by a "relocation constant". The "relocation constant" is the address at which the program is loaded for execution. For example, if the above program was loaded at $1000, the two relocatable address fields marked by "+" must each be increased by $1000 in order for the program to execute as intended. The address referred to by the first instruction would be $000D+$1000=$100D, which would now correctly point to STRING. Address fields which do not require relocation are absolute addresses (their values remain the same regardless of the position of the program in memory). Since the loader does not have access to the source text, it cannot determine if an address field is absolute or relative (relocatable). In fact, it cannot distinguish addresses from data. Therefore, the assembler must indicate to the loader the address fields which require relocation. This communication is accomplished through "relocation records" which are appended to the object code file produced by the assembler. Such a file is called a "relocatable object code module". Linking-Loaders As discussed previously, it is necessary or desirable for parts of a program (modules) to be developed separately. Each module must be assembled and tested separately prior to final merging of all the modules. During this merging process of the modules, it is necessary to resolve references in a module which refer to addresses or data defined in another. The resolution of "external references" is called linking. The assembler must provide information to the linker, in a manner similar to relocation records, concerning the address fields which must be resolved. -4 FLEX 6809 Relocating Assembler FLEX 6809 Relocating Assembler 1) load a relocatable object code module into memory, 2) relocate any relative address fields, 3) resolve any external references, and 4) optionally execute the resultant program. At this time a few definitions would be in order. A global symbol is a location within a module that can be referenced from other separate modules. Each global symbol has a unique name associated with it. The linking-loader is given a list of the global symbols in each module. An external reference is a reference in one object module to a global symbol in another object module. And finally, a common block is a block that can be declared by more than one object module. The data used in the common blocks is "common" to all of the modules that have declared the common block. -5 FLEX 6809 Relocating Assembler FLEX 6809 Relocating Assembler GETTING THE SYSTEM STARTED The FLEX 6809 Relocating Mnemonic Assembler is very simple to use. There are no built-in editing functions - you must have a previously edited source file on disk before using the assembler. This file must be a standard FLEX text file which is simply textual lines terminated by a carriage return. There should be no line numbers or control characters (except for the carriage returns) in the file. When you have both the assembler and the edited source file on a disk or disks which are inserted in a powered up system, you are ready to begin. The Command Line The very minimum command line necessary to execute an assembly is as follows: +++RELASMB, The three plus signs are FLEX’s ready prompt, RELASMB is the name of the relocating assembler file (it has a .CMD extension), and the is the standard FLEX specification for the source file you wish to assemble. The defaults to a .TXT extension and to the assigned working drive if an explicit extension and drive number are not given. In this and forthcoming example command lines, a comma is used to separate items. It is also possible to use a space or spaces in this capacity. As stated, this is the very minimum command which can be used. It is possible to supply many more parameters or options to the assembler, but if left off as in this example, the assembler will assume default parameters. Perhaps the most important options available are the two associated with output. We say two because there are two types of output available from the assembler: object code output and assembled source listing output. The options regarding the assembled source listing output will be described a little later. The object code can be in the form of a relocatable binary disk file or no object code output at all. Since no specifications are made concerning object code output in the above example, the assembler will assume the default case which is a relocatable binary disk file. Since no name was specified, the output binary file will assume the same name as the input source file specified but with a .REL extension. If such a file already exists, you will be asked: -6 FLEX 6809 Relocating Assembler FLEX 6809 Relocating Assembler to which you may respond ’Y’ which will delete the existing file and continue to create the new file or ’N’ which will immediately terminate the assembly, returning to FLEX with the old binary file remaining intact. If you wish to create a binary file by another name or extension, you may do so by placing the desired file specification on the command line as follows: +++RELASMB,[][,+