6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Sep 20, 2024 6:40 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: macroassembler standard?
PostPosted: Sun Jul 17, 2011 5:29 pm 
Offline
User avatar

Joined: Sun Feb 13, 2005 9:58 am
Posts: 85
there are lot of 6502 assembler implementation, is it possible to think on a unique way for writing a 6502 asm source?

maybe we already talk about this topic, but searching in the forum i didnt find the right thread.

in my opinion, it's important to preserve source code without the need of translating it to a fresh implementation, like cc65 or something like that.

surelly it's possible to make up an automatic translator, but from what language to what standard? (for example, from krusader to kowalski)

tnx


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jul 18, 2011 7:00 pm 
Offline
User avatar

Joined: Sun Feb 13, 2005 9:58 am
Posts: 85
lot of answers!

ok, let me try to define some common syntax.

label are on the left and normally end with colon, but i also found the dot-label syntax and also nothing at all (positional column)

start:

token commands are dot-somethings, not listed here

.org $4000

usually * is the address compile memory, like the program counter.

; is comment

# stand for immediate


........


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jul 18, 2011 8:27 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8510
Location: Southern California
It's not very clear what you're looking for. There won't be any way to change legacy assemblers and all the code written for them, but a translator program might be in order. It won't be perfect though, as it will change vertical alignment, requiring a human to modify things again to re-gain visual factoring and so on.

Since WDC owns the 6502 intellectual property, I looked up what they have to say about it in their programming manual. Page 366 says,
Quote:
6502 assemblers have been wildly inconsistent in their syntax, and early 65802 assemblers have not set standards either. This book describes syntax recommended by the designers of the 65816, as implemented in the ORCA/M assembler. Others, however, do and will differ.

and it gives a couple of examples, but not about the star. Page 78 says,
Quote:
The assembly syntax used in this book is that recommended by the Western Design Center in their data sheet (see Appendix F [which I don't find --gw]). The assembler actually used is the ProDOS ORCA/M assembler for the Apple // computer, by Byteworks, Inc.. Before learning how to code the 65816, a few details about some of the assembler directives need to be explained.


The two 6502 assemblers I've used are C32 from Universal Cross Assemblers, and 2500AD. There are very few differences in their syntaxes. If I had to go to another one and translate code for it, I would probably start with a search-and-replace in the text editor, set to require confirmation for every replacement. (There is also my teensy assembler in my Forth kernel, but it is not intended for doing entire applications in assembly, just a few subroutines, Forth primitives and runtime routines, ISRs that need maximum speed, etc..)

One thing I am not fond of is when an assembler requires all labels to start in column 1. This clutters the screen when I go into condensed mode in the text editor, a mode which omits every line that does not have a character in column 1. It is useful to see just major labels and scroll to one where you want to see the code and press <Enter> to return to nomal mode. In that situation, I don't want to see all the minor labels used for local branches. The assembler ought to allow a label starting in any column as long as it's the first thing on the line and is immediately followed by a colon to tell that it's a label.

There is a related topic, "desirable assembler features".


Top
 Profile  
Reply with quote  
 Post subject: Assembler Syntax
PostPosted: Mon Jul 18, 2011 10:00 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8389
Location: Midwestern USA
GARTHWILSON wrote:
Since WDC owns the 6502 intellectual property, I looked up what they have to say about it in their programming manual. Page 366 says,
Quote:
6502 assemblers have been wildly inconsistent in their syntax, and early 65802 assemblers have not set standards either. This book describes syntax recommended by the designers of the 65816, as implemented in the ORCA/M assembler. Others, however, do and will differ.

and it gives a couple of examples, but not about the star. Page 78 says,
Quote:
The assembly syntax used in this book is that recommended by the Western Design Center in their data sheet (see Appendix F [which I don't find --gw]). The assembler actually used is the ProDOS ORCA/M assembler for the Apple // computer, by Byteworks, Inc.. Before learning how to code the 65816, a few details about some of the assembler directives need to be explained.

What's interesting is that the ORCA/M assembler that the authors suggest was never fully compliant to the WDC standard. Also, as you noted, Appendix F doesn't exist in the book, or anywhere else that I've looked.

Quote:
One thing I am not fond of is when an assembler requires all labels to start in column 1.

Most assemblers don't impose that requirement in a physical sense (the old Commodore MADS assembler didn't, for example). Usually, leading blanks are stripped from a line of code and field parsing starts at the first non-blank character.

ptorric wrote:
ok, let me try to define some common syntax.

label are on the left and normally end with colon, but i also found the dot-label syntax and also nothing at all (positional column)

start:

Uh, labels normally don't end with a colon. That was an aberration introduced by a few assemblers whose authors hadn't bothered to read the old MOS Technology standard from which many 65xx assemblers have been derived. The only field that requires a specific delimiter is the comment field, since a comment can contain anything from the ASCII character set.

It's easy for a 65xx assembler parser to distinguish a label/symbol/pseudo-op/macro name from a mnemonic. If the first field is not 3 characters in length, it cannot possibly be a mnemonic. If it is 3 characters in length, initially treat it as a mnemonic and search the mnemonic table. If it isn't a mnemonic, does the field start with a period, the usual indicator to the assembler that what follows is a pseudo-op? If not, temporarily assume it's a macro and search the macro table. If it's not there, it's a label/symbol. Not rocket science.

Quote:
token commands are dot-somethings, not listed here

.org $4000

What you are referring to as "token commands" are properly called assembler pseudo-operations or pseudo-ops.

Quote:
usually * is the address compile memory, like the program counter.

Assemblers "assemble," not "compile." I try not to be pedantic about this, but when someone is trying to learn this stuff, terminology becomes important.

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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jul 18, 2011 10:56 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8510
Location: Southern California
Quote:
It's easy for a 65xx assembler parser to distinguish a label/symbol/pseudo-op/macro name from a mnemonic. If the first field is not 3 characters in length, it cannot possibly be a mnemonic. If it is 3 characters in length, initially treat it as a mnemonic and search the mnemonic table.

The 2500AD assembler has a .MACFIRST directive to make it look for macros first, in case you wanted to re-define a mnemonic.

Quote:
Uh, labels normally don't end with a colon.

Even if the colon is not required, I've found that it's good to put it on, so if you do a search for the label, you don't waste your time with a ton of uses of it before you find the label itself. If you do a search for "FOOBAR:", the only place it will take you is that label.

Quote:
What you are referring to as "token commands" are properly called assembler pseudo-operations or pseudo-ops

or assembler directives


Last edited by GARTHWILSON on Wed Jul 20, 2011 5:51 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Assembler Syntax
PostPosted: Wed Jul 20, 2011 4:21 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8389
Location: Midwestern USA
GARTHWILSON wrote:
Quote:
It's easy for a 65xx assembler parser to distinguish a label/symbol/pseudo-op/macro name from a mnemonic. If the first field is not 3 characters in length, it cannot possibly be a mnemonic. If it is 3 characters in length, initially treat it as a mnemonic and search the mnemonic table.

The 2500AD assembler has a .MACFIRST directive to make it look for macros first, in case you wanted to re-define a mnemonic.

That's a worthwhile feature, especially if trying to extend existing opcodes to encompass new features (e.g., STA $123456,X with a 65C816). Unfortunately, it seems most assemblers do not consult the macro table before they look up an opcode. The Commodore Dev-Pak assembler was a notable exception, which feature allowed me to macro-ize it to assemble new addressing modes supported by the 65C02.

Quote:
Quote:
Uh, labels normally don't end with a colon.

Even if the colon is not required, I've found that it's good to put it on, so if you do a search for the label, you don't waste your time with a ton of uses of it before you find the label itself. If you do a search for "FOOBAR:", the only place it will take you is that label.

True, although not all assemblers accept the colon as valid in the label field. The original MOS Technology standard required that labels/symbols contain no characters other than letters and numerals. Even the underscore was prohibited in the standard. Adding to the pain, most of those early assemblers limited the programmer to six character names. Looking back at it, I'm amazed that we worked to such narrow definitions in those days (late 1970s, early 1980s).

Quote:
Quote:
What you are referring to as "token commands" are properly called assembler pseudo-operations or pseudo-ops

or asseembler (sic) directives

Yeppers. When I first learned how to use an assembler (c. 1970) the directives were always referred to as pseudo-ops, and that term is so ingrained in my dinosaur brain I use it without thought. Old habits...

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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jul 20, 2011 6:53 pm 
Offline
User avatar

Joined: Sun Feb 13, 2005 9:58 am
Posts: 85
thank you for your msgs, i'm sorry for my pour english.

because i love to revive old sources, it's not the first time for me that i have to convert listing in the ca65 that i actually use.

i normally use text editor for converting sources, but i think it's time for me to write some little tools that help to convert without error, checking all the source (missing label, strange directive and so on)

something like "lint" for c language, but it must be able to read different dialect and generate an output, maybe in different dialect too, or maybe in a normalized 6502 assembler.

this spare time project i think it will be done in javascript and, a must, open source.

looking around i found some popular assembler and disassembler that can be considered a good starting point, also here in the tools menu.

it will be very usefull for me to have lot of different source code so, if you dont care, please continue to post your hints!

tnx


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 29 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:  
cron