6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 8:21 pm

All times are UTC




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Sun Dec 12, 2010 9:05 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
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?"


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Dec 12, 2010 9:34 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Dec 12, 2010 9:52 pm 
Offline

Joined: Thu Dec 09, 2010 3:37 pm
Posts: 12
Location: France
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

_________________
Mindiell
-----------------------
French coder of a new 6502 simulator


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 13, 2010 3:46 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8506
Location: Midwestern USA
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. :)

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 13, 2010 8:34 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 13, 2010 8:42 am 
Offline

Joined: Thu Dec 09, 2010 3:37 pm
Posts: 12
Location: France
Eh eh, don't fight for me ! I understand the concept behind each definition ;)

_________________
Mindiell
-----------------------
French coder of a new 6502 simulator


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 13, 2010 9:46 am 
Online
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Dec 14, 2010 2:55 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
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. ;)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: