Yet another 6502 assembler
-
erhanbaris
- Posts: 3
- Joined: 21 Aug 2024
Yet another 6502 assembler
I was working on some other compiler and want to get a fresh breeth, so, I worked on that project.
It support basic syntax and some preprocessor directives. It can generate binary file (ROM) but not ELF or MBF format. You can use it for NES or Atari game development. I will be happy to get feedback and improve it make it usable by who interest on that.
https://github.com/erhanbaris/timu6502asm
It support basic syntax and some preprocessor directives. It can generate binary file (ROM) but not ELF or MBF format. You can use it for NES or Atari game development. I will be happy to get feedback and improve it make it usable by who interest on that.
https://github.com/erhanbaris/timu6502asm
Last edited by erhanbaris on Wed Aug 21, 2024 11:53 am, edited 1 time in total.
Re: Yet another 6502 compiler
Hello, and welcome! Well done, it's always good to see a software project which is useful to 6502 users.
I think perhaps it would be best to call this an assembler - even better if you could edit the subject of this thread. Otherwise we might have a pointless reply (or two) about the use of "compiler" versus "assembler" - which to me is obviously just a difference of dialect.
I think perhaps it would be best to call this an assembler - even better if you could edit the subject of this thread. Otherwise we might have a pointless reply (or two) about the use of "compiler" versus "assembler" - which to me is obviously just a difference of dialect.
-
erhanbaris
- Posts: 3
- Joined: 21 Aug 2024
Re: Yet another 6502 compiler
BigEd wrote:
Hello, and welcome! Well done, it's always good to see a software project which is useful to 6502 users.
I think perhaps it would be best to call this an assembler - even better if you could edit the subject of this thread. Otherwise we might have a pointless reply (or two) about the use of "compiler" versus "assembler" - which to me is obviously just a difference of dialect.
I think perhaps it would be best to call this an assembler - even better if you could edit the subject of this thread. Otherwise we might have a pointless reply (or two) about the use of "compiler" versus "assembler" - which to me is obviously just a difference of dialect.
Re: Yet another 6502 assembler
Great!
What we should really be doing is discussing the facilities your assembler offers - of course, I haven't had a good look.
Also notable, on this forum you'll find a number of unique self-built 6502 computer designs, as well as interest in the historical offerings from Commodore, Apple, Acorn, and others. We're quite well distributed over the various possible interests - including but not limited to the consoles.
What we should really be doing is discussing the facilities your assembler offers - of course, I haven't had a good look.
Also notable, on this forum you'll find a number of unique self-built 6502 computer designs, as well as interest in the historical offerings from Commodore, Apple, Acorn, and others. We're quite well distributed over the various possible interests - including but not limited to the consoles.
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Yet another 6502 assembler
Welcome to 6502 land.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: Yet another 6502 assembler
Oh, one thing I notice in your README, Erhan, is that you do offer local labels - a nice feature - but you call them 'branches'. I think everyone would say that a label is the place you get to, whereas a branch is the means of getting there.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Yet another 6502 assembler
I'll second that. A label is a target. A branch is an action, as with all the conditional branch instructions BNE, BEQ, BPL, etc. (and the BRA Branch Relative Always instruction). In the interest of source-code density, hopefully labels don't require being on their own line, but can instead be followed by code on the same line.
I suggest also changing the terminology also on variables. What you have here:
suggests that variable 1 is stored at address $10 (which is in ZP RAM). Otherwise, what you have there are constants, or equates, not variables. Variables are scratchpad records the target computer can keep changing as needed. Most assemblers will do something like (and I'll change your "var" to "con" for "contant"):
Where you have:I suspect you meant to put ".word" there (in blue), not ".byte."
This may need some clarification:
because in my experience with assemblers, .org very much does change where the code is laid down.
I have a list of recommendations for if someone writes an assembler, at http://wilsonminesco.com/AssyDefense/as ... uests.html, linked on the Program Tips page of the 6502 Primer—although I see now it could stand some improvement.
In any case, writing an assembler is always a good learning experience.
I suggest also changing the terminology also on variables. What you have here:
Code: Select all
var1 = $10
var2 = 22
var3 = %11001100Code: Select all
CON1: EQU $10
CON2: EQU 22
CON3: EQU %11001100Where you have:
Quote:
.word
Write 1 or many word information into memory
.byte $1122
.byte $3344, $5566
Write 1 or many word information into memory
.byte $1122
.byte $3344, $5566
This may need some clarification:
Quote:
.org
Change reference locations. It is not changing where the codes are stored, it is changing jump and branch references.
Change reference locations. It is not changing where the codes are stored, it is changing jump and branch references.
I have a list of recommendations for if someone writes an assembler, at http://wilsonminesco.com/AssyDefense/as ... uests.html, linked on the Program Tips page of the 6502 Primer—although I see now it could stand some improvement.
In any case, writing an assembler is always a good learning experience.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
-
erhanbaris
- Posts: 3
- Joined: 21 Aug 2024
Re: Yet another 6502 assembler
I made a small mess in the README file. I'll make the necessary correction. Since English is not my first language, I occasionally make mistakes. I appreciate all of your feedback. I'll take care of those problems as soon as I can, and feel free to request any more features that you would really like to see or use. Since I wrote it in less than ten days, not many features are available at this time. If someone is interested in my project, I intend to dedicate more effort to improving it.
I will check all those links and try to change based on those informations.
I will check all those links and try to change based on those informations.
Re: Yet another 6502 assembler
Very impressive! Not to worry too much about your English - easily corrected!
I see you have a few minimal test files - it might be good also to have an example file which shows every feature. In particular, all of your directives.
One directive which might be useful is an alignment directive - for example to place something at the next page boundary.
I see you have a few minimal test files - it might be good also to have an example file which shows every feature. In particular, all of your directives.
One directive which might be useful is an alignment directive - for example to place something at the next page boundary.
Re: Yet another 6502 assembler
GARTHWILSON wrote:
in my experience with assemblers, .org very much does change where the code is laid down.
But not always always. Occasionally there's a need for assembling code to one location with the intent that it be copied to another before it is run (such as CHRGET in Microsoft's BASIC). Do any assemblers provide a way to do that? It's not something that would be used often, but it would be a useful feature to have.
Re: Yet another 6502 assembler
Most assemblers can do that. I most cases the .org statement defines the stert adress of the code, but not the location of the code in the source file. Thus, by careful .ORGing und referencing the code in question can be easily copied to its destined location in memory.
Dietrich
Dietrich
My system: Elektor Junior Computer, GitHub https://github.com/Dietrich-L
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Yet another 6502 assembler
John West wrote:
GARTHWILSON wrote:
in my experience with assemblers, .org very much does change where the code is laid down.
But not always always. Occasionally there's a need for assembling code to one location with the intent that it be copied to another before it is run (such as CHRGET in Microsoft's BASIC). Do any assemblers provide a way to do that? It's not something that would be used often, but it would be a useful feature to have.
A common trick seen with 6502-powered home computers from the late 1970s and early 1980s was loading a program into the stack, which would cause it to automatically run when loading was finished. Obviously it wasn’t possible to assemble directly into the stack—the assembler would lose control of the machine, so the program was assembled for the stack address, but actually deposited elsewhere in RAM for saving to local mass storage.
The HCD-65 DEVPAK assembler for the Commodore 128 emitted an object file in MOS Technology portable format (similar to an S-record file), rather than an actual binary. A loader included with the assembler was then used to place a binary image of the program anywhere desired in memory, regardless of assembly address. That made it possible to assemble for the stack or zero page without actually overwriting either area.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: Yet another 6502 assembler
John West wrote:
But not always always. Occasionally there's a need for assembling code to one location with the intent that it be copied to another before it is run (such as CHRGET in Microsoft's BASIC). Do any assemblers provide a way to do that? It's not something that would be used often, but it would be a useful feature to have.
Code: Select all
$ cat r.s
org $00
lab1:
jmp lab1
org $20
lab2:
jmp lab2
rorg $8000
lab3:
jmp lab3
org $10
lab4:
jmp lab4
$ vasm6502_oldstyle -quiet -Fbin r.s
$ hexdump -C a.out
00000000 4c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |L...............|
00000010 4c 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |L...............|
00000020 4c 20 00 4c 00 80 |L .L..|
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Yet another 6502 assembler
erhanbaris, your English is very good for someone whose first language is not English.
That's what every assembler I've used does, and it's almost always what you want.
But not always always. Occasionally there's a need for assembling code to one location with the intent that it be copied to another before it is run (such as CHRGET in Microsoft's BASIC). Do any assemblers provide a way to do that? It's not something that would be used often, but it would be a useful feature to have.
...and then there are linkers, which I suppose are primarily for when multiple people are working on different parts of the same project. The first commercial assembler I used, 2500AD, used a linker, and I never did figure it out, only use the command line that was recommended by someone else, modifying it for each project's file names. I haven't used that assembler in over 30 years though.
John West wrote:
GARTHWILSON wrote:
in my experience with assemblers, .org very much does change where the code is laid down.
But not always always. Occasionally there's a need for assembling code to one location with the intent that it be copied to another before it is run (such as CHRGET in Microsoft's BASIC). Do any assemblers provide a way to do that? It's not something that would be used often, but it would be a useful feature to have.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Yet another 6502 assembler
I haven't studied the behaviour of org in this assembler. But one common little difficulty - not really a difficulty, but often seen as one - is that, for example, code which lives in a ROM which will ultimately be accessed at say $8000 will have addresses in the ROM which start at $0000. There's a difference between the offset in ROM, and the address the 6502 sees.
I think this difficulty is resolved by the way in which the assembler can produce a binary, or the way in which that binary is used to produce a ROM image.
(In the case of emulators, of course the ROM image will be a binary file loaded by a program. In the case of physical systems, the ROM image will be fed to a programmer, or built into a bitstream, or loaded by a monitor.)
I think this difficulty is resolved by the way in which the assembler can produce a binary, or the way in which that binary is used to produce a ROM image.
(In the case of emulators, of course the ROM image will be a binary file loaded by a program. In the case of physical systems, the ROM image will be fed to a programmer, or built into a bitstream, or loaded by a monitor.)