Page 2 of 2

Posted: Sun Dec 12, 2010 9:05 pm
by kc5tja
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: Select all

 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?"

Posted: Sun Dec 12, 2010 9:34 pm
by GARTHWILSON
Quote:
Thank you so much, but next time I'll do another thread in order to make it easier for someone else looking for the same information :wink:
As a moderator, I would prefer that you keep related questions together in one topic. As an example of what not to do, a forum member a few years ago had a string of questions on clock requirements and circuits, and he kept starting new topics for them instead of keeping them together since they were all clock questions. It clutters the forum and makes it harder to make the mental connections between them.

Posted: Sun Dec 12, 2010 9:52 pm
by Mindiell
GARTHWILSON wrote:
As a moderator, I would prefer that you keep related questions together in one topic.
I'll do that, for sure. But my third question (about assemblers (or compilers ;) )) was not directly related... The second one, about the P register was related I guess

Posted: Mon Dec 13, 2010 3:46 am
by BigDumbDinosaur
kc5tja wrote:
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.
From TechEncyclopedia:
  • Compiler:

    Software that translates a program written in a high-level programming language (C/C++, COBOL, etc.) into machine language. A compiler usually generates assembly language first and then translates the assembly language into machine language. A utility known as a "linker" then combines all required machine language modules into an executable program that can run in the computer. See optimizing compiler.

    Assembler:

    Software that translates assembly language into machine language. Contrast with compiler, which is used to translate a high-level language, such as COBOL or C, into assembly language first and then into machine language.
Funny how that sounds almost like what I said. :)

Posted: Mon Dec 13, 2010 8:34 am
by kc5tja
Those are commonly-accepted definitions, and are proper subsets of what I said. Go ahead -- try it yourself. Try to use my words as if to argue against yours. You'll only find that your definitions are subsumed by mine.

Posted: Mon Dec 13, 2010 8:42 am
by Mindiell
Eh eh, don't fight for me ! I understand the concept behind each definition ;)

Posted: Mon Dec 13, 2010 9:46 am
by BigEd
Perhaps the lesson here is that pedantic corrections (and re-corrections) aren't as useful to readers as the writer might hope.

Way way back, before BDD's contribution, we had an excellent and sufficient gentle correction on this point:
GARTHWILSON wrote:
Quote:
Do you know where I can find a 6502 compiler with which I can take a source and obtain the binary result ?
It sounds like you just want an assembler. Almost any assembler should work. Most have several options for output format.
I think that leaves a better conversation than what followed on that point.

As a constructive suggestion: if anyone feels like writing a lecture on some topic, please go ahead with a new thread, and the debate can proceed over there. Ideally we'll see phrases like 'opinions differ on this' or 'the terminology you use depends on your background' - we can have respectful debate.

Cheers
Ed

Posted: Tue Dec 14, 2010 2:55 am
by kc5tja
Mindiell wrote:
Eh eh, don't fight for me ! I understand the concept behind each definition ;)
BDD and I go around like this several times a year. It's a sporting event at this point. ;)