6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Jun 13, 2024 9:14 pm

All times are UTC




Post new topic Reply to topic  [ 48 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: Wed Oct 21, 2020 3:31 pm 
Offline

Joined: Thu Feb 27, 2020 9:15 am
Posts: 18
Hello

I am currently in the process of making an assembler for the 6502 family and i do have a working in-dev version of it (only 6502 and 65C02 w/o Rockwell as of now tho).
And i am thinking of what syntax to support with it. For example some assemblers use ':' for labels whereas others dont.

What syntax do you think is more popular and does it even matter?
Also, what directives do you think are most useful to have? (apart from obvious things such as macros, labels & simple data)


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 21, 2020 3:45 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1435
Location: Scotland
JustClaire wrote:
Hello

I am currently in the process of making an assembler for the 6502 family and i do have a working in-dev version of it (only 6502 and 65C02 w/o Rockwell as of now tho).
And i am thinking of what syntax to support with it. For example some assemblers use ':' for labels whereas others dont.

What syntax do you think is more popular and does it even matter?
Also, what directives do you think are most useful to have? (apart from obvious things such as macros, labels & simple data)


It's your assembler - use the syntax you're most comfortable with.

I use as65 from the cc65 suite and my own assembler (a work in progress) is more or less compatible with that.

as65 defaults to needing :'s but there is a flag to make them optional, so it can assemble source designed for a different assembler. (Also see "Postel's Law")

As for directives - conditional assembly and include another file along with the ones you mentioned. I use a 'repeat' construct in some of my code to unwind a loop too, so that's handy for me, but for you? ....

There might be a 'but' or 'however' though and that's if you expect others to use it. That's a hard sell in my book, (e.g. will it run on MS Win, Linux, Mac, C64, X16, my Ruby system, and other comments along those lines are what you'll get), so I'd save yourself the stress and just do it your way.

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 21, 2020 3:57 pm 
Offline

Joined: Thu Feb 27, 2020 9:15 am
Posts: 18
drogon wrote:
as65 defaults to needing :'s but there is a flag to make them optional, so it can assemble source designed for a different assembler. (Also see "Postel's Law")

Hm, yeah i probably should have a similar option.

drogon wrote:
As for directives - conditional assembly and include another file along with the ones you mentioned. I use a 'repeat' construct in some of my code to unwind a loop too, so that's handy for me, but for you? ....

There might be a 'but' or 'however' though and that's if you expect others to use it. That's a hard sell in my book, (e.g. will it run on MS Win, Linux, Mac, C64, X16, my Ruby system, and other comments along those lines are what you'll get), so I'd save yourself the stress and just do it your way.


I do have conditional assembly & file include directives supported yeah) I also implemented "regions" to separate label/macro lookup.
As for others using it, it is my hobby project but i am going to release it on github when i feel like it is in a presentable form so that if somebody would want to use it that would be nice. Its not my target though, im mostly making it as an exercise.
As for compatibility, i plan for it to be compiled for windows, linux & mac, it wouldn't be compatible with older systems tho because it relies on "modern"-ish C and flex & bison for parsing.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 21, 2020 4:16 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10827
Location: England
Personally I tend to use ca65, which also has some mode flags for slight syntax variation.

In the land of Acorn and the BBC Micro, there's BeebAsm which implements something like the assembler-embedded-in-Basic which the Beeb offers, so you get Basic programming and expression evaluation to add something a bit like macros.

But but but, can I go right against the flow and the probable consensus here? I came across the assembler syntax used by Acorn back in the day, and it's unusual but I think it just might be great.

Instead of the familiar 3 letter opcodes, which form into a nice orderly column, you get a mix of lengths because the addressing mode is appended, which actually adds form and structure, making it easier to see what's going on. There's also a really minimal syntax for conditional assembly:
Code:
 LDAIM &FF
 JSR OSBPUT
 LDXIM -FILLEN
SRCL03
 LDAZX CURFILE+FILLEN
 JSR OSBPUT
 INX
 BNE SRCL03 ;Output the filename
SRCL05
 [ $TURBO
 LDAIM /SYMSHI
 STA XSYMPT
 ]
 RTS


The conditional syntax is an IF THEN, but also there's an ELSE form:
Code:
 [ :LSB:TEXT /= 0
 LDAIM TEXT
 STA LOADAD
 |
 CLR LOADAD
 ]
 LDAIM /TEXT

(I'm guessing CLR is a synonym for STZ, and / is a bitwise negation.)

Examples from the MASM sources themselves - it seems MASM is written in MASM.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 21, 2020 4:25 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1435
Location: Scotland
JustClaire wrote:
I do have conditional assembly & file include directives supported yeah) I also implemented "regions" to separate label/macro lookup.


Something I've just thought of - and this may be yout 'regions' here - as65 has a notion of a 'procedure' with .proc and .endproc and inside that area labels defined are local to that area. So you can have multiple .proc/.endproc's in the same file each using the same label names.

Also un-named labels:

Code:
    inc    ptr+0
    bne    :+
    inc    ptr+1
:


and so on ...

The trouble is... it would just end up looking like my (currently) favourite assembler ;-)

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 21, 2020 4:33 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10827
Location: England
Some sort of local labels can be useful, especially for very short jumps out of loops or back to the head, things which barely need a name, but have to have a label.

There will certainly be a variety of opinions, and every practising assembly coder is likely to have settled on a preference. (All the same, I'm supportive of a new project, to see what it might bring.)


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 21, 2020 6:17 pm 
Offline
User avatar

Joined: Mon May 12, 2014 6:18 pm
Posts: 365
BigEd wrote:
Instead of the familiar 3 letter opcodes, which form into a nice orderly column, you get a mix of lengths because the addressing mode is appended, which actually adds form and structure, making it easier to see what's going on.
Just my 2 cents so feel free to disagree, but I have always been strongly against this since it only really exists to make life easier for the assembler writer at the expense of making it slightly harder for the people using the assembler. It's easy though to see the temptation since LDA (foo+1),Y and LDA (foo)+1,Y are two different addressing modes but a pain to tell apart for the assembler author.

In my opinion, the place where an assembler really shines is it's macro system. as65 and macro assembler AS are both good in this regard, though I've tried to do things with both where the macros weren't sophisticated enough. For one project, I switched to NASM, an x86 assembler, for the macro functionality then assembled the result with a 6502 assembler. It might be worth it to compare the different macro systems (they vary a lot) and see how you would like your macros to work.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 21, 2020 7:29 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8458
Location: Southern California
JustClaire wrote:
For example some assemblers use ':' for labels whereas others don't.
Ones that don't use the colon generally require labels to start in column 1. I'd say do not require labels to start in column 1. Text editors that have a "condense" feature can give a display of only the lines that have something in column 1, which makes it faster to find things sometimes. When I do this, I don't want to see the labels that are only of local interest. Labels that start in column 2 or later can still be recognized as labels if they're the first thing on the line and are followed by a colon. Using a colon after a label is good practice anyway, even when it's not required, because if you do a search for the label, you can put the colon in the search term and it will take you right to it, rather than wasting your time by first turning up a lot of references to the label.

Druzyek wrote:
In my opinion, the place where an assembler really shines is its macro system.
Absolutely!

JustClaire wrote:
Also, what directives do you think are most useful to have? (apart from obvious things such as macros, labels & simple data)
I have a list of requests for assembler writers at http://wilsonminesco.com/AssyDefense/as ... uests.html .

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 22, 2020 12:06 am 
Offline

Joined: Thu Feb 27, 2020 9:15 am
Posts: 18
GARTHWILSON wrote:
I have a list of requests for assembler writers at http://wilsonminesco.com/AssyDefense/as ... uests.html .

Thanks, I'll check it out!
Also, what do you think is the better way to treat indirect addressing syntax?

I currently do not allow bracketed expressions as the operand for indirect addressing, as it would be very confusing to distinguish between
Code:
JMP (offset_label + $)
where the operand is
Code:
offset_label + $
and the addressing mode is indirect, and
Code:
JMP (offset_label + $)
where the operand is
Code:
(offset_label + $)
and the addressing mode is absolute.
Currently the assembler would expect any indirect addressed instruction (indirect only, indirect indexed and indexed indirect dont count) to not have any brackets in the expression.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 22, 2020 12:39 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8458
Location: Southern California
The C32 assembler I use uses { and } for grouping things. What you show however does not need any grouping. JMP offset_label + $ is perfectly valid in all the assemblers I've used, and they don't need ( ) unless you want it indirect.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 22, 2020 1:48 am 
Offline

Joined: Thu Feb 27, 2020 9:15 am
Posts: 18
GARTHWILSON wrote:
What you show however does not need any grouping.

I used that as an example, i meant any expression in brackets in general.
Using other brackets for me would be problematic though, as my current syntax uses {} to explicitly specify bit width of a value.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 22, 2020 2:03 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8458
Location: Southern California
JustClaire wrote:
GARTHWILSON wrote:
What you show however does not need any grouping.

I used that as an example, i meant any expression in brackets in general.
Using other brackets for me would be problematic though, as my current syntax uses {} to explicitly specify bit width of a value.

Some (many? most?) assemblers do that with the "<". So for example, for the C32 assembler I use, if I'm programming for the 65816 and have the index registers in 8-bit mode and want an 8-bit LDX immediate, I might say LDX #<$1F, because without the "<", it would lay down a 16-bit operand.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 22, 2020 2:09 am 
Offline

Joined: Thu Feb 27, 2020 9:15 am
Posts: 18
GARTHWILSON wrote:

Some (many? most?) assemblers do that with the "<". So for example, for the C32 assembler I use, if I'm programming for the 65816 and have the index registers in 8-bit mode and want an 8-bit LDX immediate, I might say LDX #<$1F, because without the "<", it would lay down a 16-bit operand.


Hm. Maybe i could use the C-style ":" to define bit width. I do not like/want to use the "<" for defining bit width as it is fairly limited and can be confused with bit shift operation and boolean relation.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 22, 2020 2:18 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8458
Location: Southern California
C32 does shifts with << and >>. If there's any chance of confusing < for a "less than," you could put it in the brackets, like 2*{<foobar} (although that one should be clear without the brackets). I'll scan and post the list of operators. I've never found any problem with them (even if I'm not fond of some of them).

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 22, 2020 2:30 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8458
Location: Southern California
Attachment:
C32expressions1.gif
C32expressions1.gif [ 92.52 KiB | Viewed 1061 times ]


Attachment:
C32expressions2.gif
C32expressions2.gif [ 89.48 KiB | Viewed 1061 times ]

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 48 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC


Who is online

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