_________________________________________________________________ XA 2.1.4 65(c)02 Cross Assembler (c) Andre Fachat email: fachat@galileo.rhein-neckar.de _________________________________________________________________ 1. what it is 2. parameters and features 3. 6502 Assembler 4. pseudo-opcodes, block structures and where labels are valid 5. pre-processor 6. utilities * literature _________________________________________________________________ What it is This Cross-Assembler makes programms for another computer that has a 6502-like CPU. This CPU has been widely used in the famous Apple II, all the Commodore 8-Bit Computers (PET, VC20 and a derivate in the C64) and many others. Some are still used in one-chip microcontrollers, e.g. the Rockwell modem chipset. All these chip share a common set of standard machine language commands, some of them (e.g. the CMOS versions) have additional (software) features. I had the idea for this assembler when I built my small 6502 System that had place for 32kByte ROM to take the kernel and lots of other programms. (After all, it became a multitasking micro-kernel with file-systems for IBM and Commodore, I can even use the IBM drives as Floppy for my C64 with this computer as controller. Piping and i/o-redirection included, of course) Development on my old C64 began to suck with programms growing. So I decided to do a Cross-Assembler on my new Atari ST. First versions were very like the old Assembler on the C64, not really using the resources (Reading all files two times completely etc). With files growing the assembler also became more sophisticated. Now hashcodes are used for mnemonics, preprocessor definition and label search (Version >= 2.0.5). The files are only read once, putting the preassembled code into memory (Version >= 2.0), taking it from there on pass 2. Now it makes about 350kByte Source Code to about 30kByte ROM code in less then 2 Minutes on an 8 MHz Atari ST with 2.5 MByte RAM and Harddisk. (Well, the Atari is not fast. On my 486DX4/100 it takes about 2 seconds...) But adding the whole relocation stuff slowed it down again. Parameters and features The assembler contains only a single programm called "xa" (for Atari: XA.TTP). It takes one or more Source files into one object file, that can directly be used. But the assembler also has a mode to produce relocatable files, conforming to the 'o65' fileformat (See fileformat.txt). Call: xa [options] Source1 [Source2 ...] Object: this is the name, the output (object) file gets Error: Here you will find the Error listing. Label: this is the label list '-C' gives error codes when using CMOS-opcodes. Default is not to complain. '-c' do not produce o65 executable, but object files that can contain undefined references. '-v' go into verbose mode '-x' old filename behaviour (overrides -o, -e and -l) '-R' do not produce absolute code, but do relocation and all that. '-o filename' set output filename '-e filename' set errorlog filename '-l filename' set labellist filename '-r' add crossreference list to labellist output (i.e list of filename/line where label is used) '-M' allow ':' to appear in comments after a semicolon (MASM mode) '-b? adr' set segment start address for ? = t(ext), d(ata), b(ss) or z(ero) segment. '-A adr' If the _file_ starts at adr in a ROM, then the text segment need not be relocated. That of course only works, if the data/bss/zero segments are not occupied by other programs too! '-G' omit writing the exported globals to the file. '-B' Show lines with '.(' or '.)' pseudo opcodes '-Llabel' defines 'label' as absolute, undefined reference '-DDEF=TEXT' define a preprocessor replacement '-Ipath' additional include path for include files. Is evaluated before the XAINPUT environment variable. One path per '-I', multiple '-Ipath' allowed. Omitting the errorfile or labelfile Parameter will cause xa to not write these files. Using '-x' will cause xa to take the name of the first source file and change the extension (on an Atari there is only one, like in DOS) to 'obj', 'err' and 'lab' respectively - if the old behaviour is selected with the '-x' option or the files are defined with "-l" and "-e". If no output file is given, "a.o65" is used. Environment variables: You can use the variables XAOUTPUT and XAINPUT to adjust the directory structure. If source or include files are not found, the Path in XAINPUT is being searched for the files. The different paths are separated by a comma (','). XAINPUT gives the directory where the *.obj, *.err and *.lab files are put. If they are not set, there will be no search, respectively the files are saved to the current directory. The label file is a readable ASCII-file and lists all the labels together with their block-count (see below) and their address. The error file lists the version of the assembler, date and time of the assembler run, all the error messages and the stuff being printed with #echo and #print and last but not least a statistics of used resources. 6502 Assembler xa supports both the standard 6502 opcodes as well as the CMOS versions (Rockwell 65c02). Not supported are the 6502 undocumented opcodes, they have to be put in by hand (with ".byte" directives). For an introduction to 6502 Assembler please see elsewhere. A (very) short introduction is given in the german version of this text. Some Assembler specific details: When using addressing modes that could be zeropage or absolute, zeropage will be taken if possible. This can be prevented by prefixing the address with a '!'. Then absolute addressing is taken, regardless of the address. Values or Addresses can be expressed by arithmetik expressions with hierachy and bracket. The following operands are understood: 123 -decimal $234 -hexadecimal &123 -octal %010110 -binary * -program counter "A" -ASCII-code labelx -label -(lab1+1) -expression The following operands can be used (third column is priority): + -addition 9 - -subtraction 9 * -multiplication 10 / -integer-division 10 << -shift left 8 >> -shift right 8 >=,=> -more or equal 7 <=,=< -less or equal 7 < -less 7 > -more 7 = -equal 6 <>,>< -not equal 6 && -logical AND 2 || -Logical OR 1 & -Bitwise AND 5 | -Bitwise OR 3 ^ -Bitwise XOR 4 Operators with higher priority are evaluated first. Brackets can be used as usual. Valid expressions are, e.g.: LDA base+number*2,x For Addressing modes that do not start with a bracket, you can even use a bracket at the beginning of an expression. Otherwise try this: LDX (1+2)*2,y ; Wrong! LDX 2*(1+2),y ; Right! Before an expression you can use these unitary operators: < Gives the low byte of the expression > Gives the high byte LDA #