6502asm user guide – prerelease version A 65 PRE 0 EN 2ASMREL THI EA S I TI . If y RE .. IT SE S ou LY MA VE dis C cov OR Y N RSI er O ON R the erro EC T W O F r m T to s, ple LY OR me ! ase re YE K po T. 6502asm user guide rt v0.
6502asm user guide – prerelease version Introduction 6502asm is a simple assembler for 6502 code. It supports a variety of assembler commands to control output and extend the 6502 instruction set. The instruction set provided is the legal NMOS 6502 set, and the CMOS 65C02 instruction set according to the Western Design Center W65C02S datasheet (not the MOS 65CE02 variant). The NMOS “undocumented” instructions are not supported.
6502asm user guide – prerelease version Don’t write code like this: The assembler will see: LDX #0 : LDY #0 : LDA #0 : RTS LDX #0 (only the first instruction, the “LDX”) The source file is always read from the start to the end. It is possible to assemble in any location in the &FFFF (64K) addressing space at any given time by setting the address with the org command, however over-use of this can lead to messy code and other complications. Where execution starts depends on what you are assembling.
6502asm user guide – prerelease version c. Instructions [] Instructions are the usual three letter mnemonics, with optional parameters as necessary. Comments are introduced using the ‘;’ character. Anything following a semicolon until the end of the line is ignored. You can include comments at the ends of command lines and instruction lines. To reiterate: Each line is a separate entity, up to 80 characters long.
6502asm user guide – prerelease version The hardware stack lives in page one (&0100 to &01FF). Certain operations performed using the zero page addressing mode (relating to memory locations &0000 to &00FF) operate much more quickly than do the same instructions applied to any other part of the memory map.
502asm user guide – prerelease version You could also use the opcode table to implement various “undocumented” instructions that may be found in the NMOS versions of the 6502, some examples would be: AXS This ANDs the contents of the X register and the Accumulator and stores the result in memory. Neither register is altered, and the processor flags are not changed either.
6502asm user guide – prerelease version Assembler commands 6502asm commands are all three letters long (except EQUx which is handled specially). They look like processor instructions. This is intentional. BOT
[FORCE] This specifies the lower address of the assembly. If no address is specified, &0000 is assumed... ...unless the ROM command has been previously specified, in which case &E000 will be assumed.6502asm user guide – prerelease version DCW also EQUW Include a word (16 bit) value in the output, low byte first (6502-style). DCZ "" also EQUZ Include a zero-terminated string in the output. FIL , Insert bytes (of ) into the output, to fill or pad as desired. INF "" Load and embed the contents of the named file. You can use this to insert raw data or precompiled code.
6502asm user guide – prerelease version The default base address, &E000, was chosen because it is the start point of the Amélie EPROM. If this address is not suitable, you can easily do something like: ROM BOT &A000 FORCE ORG &A000 TOP
This specifies the higher address of the assembly. If no address is specified, the address after the last instruction assembled is assumed... ...unless the ROM command has been previously specified, in which case &FFFF will be assumed.6502asm user guide – prerelease version Ways of specifying a numerical value When you need to specify a value, say a constant or an address, you can use: Base 16 (hex): &12 $12 0x12 This is the Acorn way. This is the Pascal / Commadore way. This is the C way. The DOS (“12h”) and VisualBasic (“$H12”) forms are not supported. Base 10 (denary): 123 As expected... Base 2 (binary): %1100 The Acorn way. To recap, prefix with ‘&’ for hex and ‘%’ for binary. No prefix is necessary for denary numbers.
6502asm user guide – prerelease version The available logical operators are: >> Logical shift right << Logical shift left || Logical OR && Logical AND ^^ Logical Exclusive OR This will have slightly more use when it comes to inserting the addresses of things, such as: TXA STA buffer TYA STA [buffer + 1] The calculation works by extracting the parts of the calculation to a ‘stack’, so our example [12+42-11] would break down to be: location: 0 1 2 3 4 5 6 7 value: 12 + 42 11 ] x x (‘]’ meaning end and ‘x’ mea
6502asm user guide – prerelease version Immediate addressing # The value is directly provided. Note the ‘#’ character before the value; if it was not there then it would be taken as an address – the ‘#’ is important! Examples: LDA #123 Relative addressing Relative addressing is used only with branch instructions. The second byte of the instruction establishes a branch point which may be -128 to +127 bytes away from the following instruction (i.e.
6502asm user guide – prerelease version Indexed absolute addressing (aka Absolute, X or Y addressing) Indexed zero page addressing (aka Zero page, X addressing) , X , Y This behaves much like the Absolute / Zero page addressing previously described, however in addition to retrieving the address, the contents of the X or Y register (as applicable) is added.
6502asm user guide – prerelease version Example: LDA (&12, X) ; load A from ; address pointed to ; at (&12 + X) Indirect indexed addressing (post-indexed) (), Y This time... The second byte of the instruction points to an address in page zero. We add this new address to the contents of the Y register to obtain our ‘real’ target address.
6502asm user guide – prerelease version Absolute indirect JMP (
) This mode is only available for a specific type of JMP instruction. The contents of the address pointed to are read, and this in turn becomes the JMP address. For example: If &F000 was &A000... JMP (&F000) JMP will look at &F000 and ‘see’ &A000. Instead of jumping to &F000, it will indirect, and we’d jump to &A000.6502asm user guide – prerelease version String codes You can ‘embed’ special sequences within strings: \r Insert an &0D byte (linefeed) \n Insert an &0A byte (newline) \" Insert a double quote \' Insert a single quote \x## Insert a hex code directly (i.e. \x07 for TTY bell) \d### Insert a decimal code directly (i.e. \d169 for © symbol) \0 Insert a null byte \\ Insert a backslash This has been taken from the C method of inserting codes into strings...
6502asm user guide – prerelease version BOT ; ; ; ; &E000 FORCE; force low address to be &E000, EPROM start The above is important! Because we are assembling ROM code, we want only &E000 to &FFFF to be saved, but we also want to set up locations in page zero so we can refer to them by label. ; ; B I O S C O D E F O L L O W S ================================= ORG &F000 ; The BIOS sits in the second half of the EPROM ; R E S E T ; --------.nmi_vector .
6502asm user guide – prerelease version For a successful assembly, the display will look like: S:\Amélie>6502asm mybios.s65 mybios.img 6502asm v0.04 (11th June 2008) initialising... Written by Rick Murray, email me at Assembling, pass 1... Continued into file "appcode.s65"... Assembling, pass 2... Continued into file "appcode.s65"... Saved 8192 bytes to "amebios.img" - &E000 to FFFF 6502asm v0.04 (11th June 2008) exited. Thank you for using this software.
6502asm user guide – prerelease version ERROR: Memory allocation failure. Please free up an additional 72K and try again. In order to begin assembly, 6502asm allocates a 64K block of memory at start-up. The additional memory (it says 72K) is because if you are this short of memory, we’d better ensure we have room for the opcode table and some labels... Under MS-DOS™, you may also see: Available memory is only bytes, need at least 73728 (72K)...
6502asm user guide – prerelease version ERROR: Calculation too complex at line . The calculation ‘stack’ can only hold eight discrete items. Every number and operator is an item in the stack, thus [1+2+3] is six items. Why six? Don’t forget the end-of-calculation marker. ERROR: The instruction "" is not recognised. (at line ) You have entered something that is not understood as a valid instruction or pseudo-instruction.
6502asm user guide – prerelease version Known bugs Lines are clipped at 80 characters. This means if a comment on a line exceeds this, it will be read in as part of the next line, causing an error. If you receive the error “unknown command 'xxx' at line ”, where “xxx” is part of a word in the comment, this is why. In some cases, forward references to a label does not work.
6502asm user guide – prerelease version these conditions firstly to benefit the end-user, so that they will (hopefully) encounter the correct and up to date version and not spin-offs; and secondly to benefit myself, as I’ve been ripped off before and taken flak for problems in software versions that were not my own. Once bitten, twice shy. 9. I am a British citizen living in France. This entire software product, and all documentation, was created within the confines of département 35, France.
6502asm user guide – prerelease version Thanks to: Ewen Cathcart for lots of help, support, and introducing me to something better than my old Erasure and Pet Shop Boys tapes... I guess it could have been worse, it could have been Rick Astley... Glenn Richards for hosting my website (and you thought it was just a bunch of pictures of Alyson Hannigan, right?) and a lot of time chatting to me on the phone. I miss those days.