BigDumbDinosaur wrote:
Not to be pedantic about it, but you assemble 65xx machine code, not compile. A compiler translates a higher level language (e.g., C or COBOL) to machine language, usually by first generating an assembly language source file and then assembling the assembly language instructions. Compilers confer a degree of portability between systems (e.g., a program written in C is usually portable between systems for which a native C compiler exists) and insulate the programmer from the raw machine code instruction set of the target system. By definition, assembly language is not portable, as each MPU has its own instruction set and each system has its own unique architecture.
To be even more pedantic, this isn't strictly true.
An assembler is a compiler, but a degenerate one. An assembler distinguishes itself from other compilers in that it provides a 1:1 correspondence between input source text and output binary image. This is why Forth, despite the routine and informal references to compilation, is nonetheless described as an
assembler for a virtual stack machine.
Indeed, nothing in assembly languages implies lack of portability either; Java's VM has several assemblers for it, yet their results are able to be run anywhere a JVM exists. Indeed, IBM's AS/400 system success is very much predicated on this concept. Even in the VAX/VMS world, out of necessity, contemporary VAX assemblers exist for OpenVMS systems which, actually, emit code for Alpha and IA64 architectures. As long as a one-for-one code correspondence exists, it's an assembler.
Compilers, interestingly, don't always imply portability either. BASIC-Stamp systems are tightly integrated with the PIC architecture, as the "Wire" language is for the Arduino platform.
And, I won't get into the dirty little secret behind C's ostensible claim to portability. It's portable, but only with a whole lot of qualifications that often get swept under the rug for marketing or convenience purposes.
Quote:
Start your source code with .ORG <address> or *=<address> to set the starting assembly address. There is seldom a default and the MPU itself goes to $FFFC-$FFFD for the starting address following a hard reset.
Some assemblers don't take the starting address from the ORG directive, but rather, the END directive. If you are using a relocatable loader format, you actually
never hard-wire a starting position, for that is determined at
load-time by the system software.
To find out at run-time where your code exists, you can use the following clip of code to find out:
Code:
JSR *+3
PLA ; HUH -- I'm so used to working with the 65816,
TAX ; I forgot that not all 6502 variants support PLX. :)
PLA
after which, A will contain the high byte of (PC-1), and X will contain the low byte of (PC-1). Note the -1 bias exists because of how the 6502 handles return addresses. You'll need to compensate for this manually in software if you're using the address for something other than "Where am I?"