6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Sep 29, 2024 7:28 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Tue Oct 12, 2021 5:52 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
Hi guys

Ages (years) ago I started writing my own 6502 cross assembler, mainly targetd at the WD's 65C02 for my own projects. The 'feel' was initially based off the assembler in the BBC Micro in the 80's, although I've since moved away from that and made it more conformist to what most people expect (using .org to set the assembly address, semi colon for comments, labels with <name>: and $ as the default hex prefix, etc.).
I then left it for quite a long time, picked it up, put it down again and then picked it up again. During that time I converted it to command-line only, rewrote it from the ground up as it was a tad messy, and finally moved it from .NET Framework to .NET Core 5 (so I can later port it to linux - hopefully).
It's mostly complete now, with me clearing up bugs, adding finishing touches and now expanding the supported assembler-base commands.

Supported capabilities listed here: https://6502ca.net/


Now, part of the reason I'm posting this is to get peoples' over-all opinion, but also to ask for any additional suggestions for commands and for a review of the IF command that I've just implemented (based on a previous suggestion from Garth a while back).

There are two versions of IF:
Code:
IF <(!)flag or operator> JUMP <address>
IF <(!)flag or operator> BEGIN
<some code>
END


The operator comparison is based on the status flags set by CMP, CPX, CPY.
A full description can be found here (scroll down to the IF command), along with the code assembled: https://6502ca.net/index.php?Commands.

If anyone is interested in taking it for a test run you can download the setup EXE (windows 10 & 11 tested, windows 7 tested but needs SP1 and to be fully patched):
https://6502ca.net/index.php?Downloads (also has a link for downloading the PDF manual).
You can also download a language XML file for notepad++ from: https://6502ca.net/index.php?Editor
Other pages on the site show more information on command-line switches, but basically you can just type (once installed): 6502ca <filename> and it will attempt to assemble your source code. If you don't put a file extension then it assumes '.6502ca'.

If anyone spots any bugs then I'd be interested to know as I haven't had anyone put it through it's paces - just me testing.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 12, 2021 10:48 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
Thank you very much for sharing your efforts! I browsed the documentation and it looks quite nice, but I don't have any direct need for a command line assembler at this time ... I'm playing with 'mulators and IDEs like Kowalski for now.

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 13, 2021 6:20 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
This project is mostly for me to be fair, but thought I'd throw it out there in case it's of use to anyone else.
But thanks for having a look through anyway - appreciated :).


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 13, 2021 6:41 pm 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
I suspect it's usually the case that no one else uses our personal software products, but that many still get ideas from them for their own projects. The ideas might simmer for even years before a missing piece comes along to make them come to fruition.

_________________
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: Wed Oct 13, 2021 7:07 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
GARTHWILSON wrote:
I suspect it's usually the case that no one else uses our personal software products, but that many still get ideas from them for their own projects. The ideas might simmer for even years before a missing piece comes along to make them come to fruition.

You're probably right. Also, if you have a product that already works for you why move elsewhere unless there are significant gains? C'est la vie.

One thing which would be very handy is if someone would be ok checking the code my IF command asssmbles? Mostly, it's the signed code I want to be sure of:

This is for the IF <operator/flag> JUMP <address> version:
Attachment:
IFcmd1.GIF
IFcmd1.GIF [ 369.82 KiB | Viewed 3510 times ]


This is for the IF <operator/flag> BEGIN ... <code> ... END version:
Attachment:
IFcmd2.GIF
IFcmd2.GIF [ 355.9 KiB | Viewed 3510 times ]


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 13, 2021 11:00 pm 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
banedon wrote:
One thing which would be very handy is if someone would be ok checking the code my IF command asssmbles?

With a quick look, it looks correct. Apart from relative branch distances though, I don't think I've ever used signed 8-bit numbers, only 16 or more.

It would probably be good to choose names that don't conflict with what's used in other assemblers. For example END in all the assemblers I've used brought all assembly to an end; meaning that to reduce the number of changes necessary to make pre-existing code work with your assembler, you'd want to change the name. What I did in my program-flow-control structure macros was to use END_IF (not ENDIF or ENDI which some assemblers use in conditional assembly). You'll want ELSE too, so you can have for example,
Code:
        IF_EQ
            <do this>
            <do this>
        ELSE_
            <do this other stuff>
            <do this other stuff>
        END_IF
(ELSE_ having the trailing _ so it doesn't conflict with the ELSE of conditional assembly).

The IF <operator/flag> JUMP <address> doesn't shorten the code any, or even make it particularly more clear, for someone who knows the instruction set. BNE for example already means "Branch if Not Equal," and in my head I usually say what they mean when I type the three-letter mnemonics.

There are extended examples of my use of macros for the structures in the last 40% of my page on simple multitasking methods at http://wilsonminesco.com/multitask/ .

_________________
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: Wed Oct 13, 2021 11:40 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
Cheers for having a look.
The IF command is definitely more about the BEGIN - END version, but thought there was no harm in adding in the JUMP version. The ELSE option is a good idea, so I'll look at adding that in and I'll have a think about the naming convention. Most of my assembler commands (apart from IF) begin with # and so there is a #END command which can be used to denote the end of what you wish to be assembled, so yes, could lead to confusion. I could try curly braces/brackets instead of BEGIN END perhaps? Will have a ponder.
Thanks for the link: I'll have a look through it. :)


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 14, 2021 12:59 am 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
banedon wrote:
I could try curly braces/brackets instead of BEGIN END perhaps? Will have a ponder.

It may be just a personal thing, but I much prefer natural-language structure words over C's curly braces (to put it politely).

_________________
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 14, 2021 7:16 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
GARTHWILSON wrote:
banedon wrote:
I could try curly braces/brackets instead of BEGIN END perhaps? Will have a ponder.

It may be just a personal thing, but I much prefer natural-language structure words over C's curly braces (to put it politely).

That's fair enough. The whole BEGIN - END reminds me of Borland Pascal which I used to do a little bit of coding in when I was younger. Good times :).
Is there anything else command-wise that you can think of which might be helpful? I was looking at DO LOOP but, much like my JUMP version of IF, it's easy enough to implement without special commands. If there isn't anything else of practical use then I'll do some more bug testing and then draw a line under the project. Next up will be the emulator at that point which will probably be gui based.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 14, 2021 9:29 pm 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
banedon wrote:
Is there anything else command-wise that you can think of which might be helpful? I was looking at DO LOOP but, much like my JUMP version of IF, it's easy enough to implement without special commands.

I patterned my structure macros mostly after Forth's structures, with exceptions where 6502's normal assembly language doesn't lend itself well, like where I used FOR...NEXT in place of Forth's DO...LOOP (since Forth's DO gets the limit and index from the data stack, something we don't often implement in 6502 assembly language).  Forth allows the user to extend even the compiler itself though, so if you want a new kind of program-flow control structure, you can easily make it.  Similarly (but not quite with the same flexibility), you can make new 6502 assembly-language macros.  The IF...JMP line will always require a label to jump to, right?  The ones I'm talking about don't require a label, so the source code is cleaner.  (You can still use labels when you want to, but they're not required for most situations.)  There are other practical structures such as
Code:
    BEGIN
        <process stuff>
        <do more stuff>
        <with a flag result>
    WHILE_NEQ                ; (or other condition)
        <do this stuff>
    REPEAT

where if the WHILE condition is no longer met, you branch out of the structure to the first instruction following the REPEAT.  But as long as the WHILE condition is met, the instructions following it get executed, and then REPEAT sends the program counter back up to the top of the structure for another lap.  An example usage would be displaying a null-terminated string, where each character is fetched, and if it's not zero, you send it to the display or print device, then go back for another character.  When you do reach a zero byte, you skip out of the structure.

The CASE structure is the one that would eliminate the most labels and manual jumps.

You can nest the structures too, with others of the same or different kind, and the assembler will assemble the branches correctly.

Andrew Jacobs (esteemed late forum member "BitWise") integrated a lot of this kind of things in his As65 assembler, so the user wouldn't need macros to do them (although it supports macros too), which is what you want to do, right?

_________________
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: Fri Oct 15, 2021 12:59 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
Unfortunately I've never used FORTH, although I heard others speak of it in very positive terms. I'll have a look through the page you provided and consider the example you've given - many thanks.

My assembler does allow some expansion - was the following what you had in mind?

Macros:

Code:
; Example definition:
#SETMACRO addr-to-stack = LDA @0 | PHA   ; Load a byte form the parameter (address) and push to the stack
; Example Use:
!addr-to-stack $401A     ;  Call the macro and supply address $401A

The above would assemble to:
Code:
LDA $401A
PHA


Also, macros can also nest/call each other:
Code:
#SETMACRO save-to-stack = PHX | TSX | PHX
#SETMACRO restore-from-stack = PLX | TXS | PLX
#SETMACRO CheckVIA = save-to-stack | LDX VIAaddr+@0 | CPX #@2 | BEQ @3 | restore-from-stack

; CheckVIA <via offset> <value to check> <where to jump if equals>
CheckVIA $1 | $0A | mike


How a line of source code is processed:

Quote:
The IF...JMP line will always require a label to jump to, right?

You can use any variable, label or address to jump to. The assembler does the following before assembly:

- Check for sets of double quotes and if found, excludes those parts of the line from the following:
- Check for variables and if found, replace them with the variable values
- Check for hex and binary numbers and replace them with decimal equivilents
- Check for equations and replace them with the results of the equations
Example:
Code:
VIAaddr = $9000
LDA VIAaddr+1

... would result in
Code:
LDA 36865
and that would then be passed to the actual assembler functions.

Another example:
Code:
hello = " world!"
EQUS "hello"+hello

... would result in
Code:
EQUS "hello world!"
being passed to the assembler functions.


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 15, 2021 3:19 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
Just modified the IF command to add a new register option. Will be present in the next release coming soon:

Existing:

(signed) is optional and if present will indicate the comparison involves signed numbers
<comparitor> can be:
equals: eq, equ, =, ==, ==
not equals: neq, !=
less than: LT, <
greater than: GT, >
less than or equals: LTE, <=
greater than or equals: GTE, >=

Flags which can be tested: C, N, Z, V

Syntax:
IF (signed) <comparitor> JUMP <address>
IF (signed) <comparitor> BEGIN
IF (signed) <(!)flag> JUMP <address>
IF (signed) <(!)flag> BEGIN <address>

New register mode:
IF (signed) <register> <comparitor> (#)<value/address> JUMP <address>
IF (signed) <register> <comparitor> (#)<value/address> BEGIN

Example of the new register mode:
Code:
IF A = #4 JUMP $4000      ; if A is equal to the decimal value 4 then jump to address $4000
IF SIGNED X > $5000 BEGIN      ; if X is greater than the contents of address $5000 then begin code beneath

This new mode adds in an appropriate CMP <value/address>, CPX <value/address> or CPY <value/address> at the beginning.


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

All times are UTC


Who is online

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