| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am trying to write an assembler for the 65C816 CPU, but I am not sure how to parse a text file. If anybody could give me a generic text parser shell that I could modify that would be great. I want the assembler the parse mnemonics then numbers (I believe that this is called two-pass assembling, forgive me if I am wrong
). Thanks for any help you have!! |
|
#2
|
|||
|
|||
|
I don't want to step on you toe ... but I think that writing an assembler is much more difficult then parsing a text file. So, are you sure you're up for the job?
Did you try to find some available assemblers for this (or compatible) processor? I'm sure that there even are some C compilers for it... |
|
#3
|
|||
|
|||
|
Quote:
I did try to find some tools, and belive it or not there are very few assemblers for this processor that are free, and they are not all that good. WDC(the company who make the 65C816) offers a C/C++ compiler but its extremely expensive(about $2000USD). |
|
#4
|
|||
|
|||
|
Did you tried the one listed on this page?
http://www.6502.org/crossdev/lang/ Also have a look at: http://sourceforge.net/search/?type...id=0&words=6502 This sounds very promissing! What is your goal; do you need an assembler or a C-compiler? |
|
#5
|
|||
|
|||
|
Preferably both. I noticed your links take me to tools for the 6502, I need tools for the 65816.
|
|
#6
|
|||
|
|||
|
As far as I can tell are the 6502 and the 65816 compatible. They have the same opcode set. The pin-out is different though.
Maybe I'm wrong, sorry about that then ![]() No response received on your original question (maybe on other forums)?? |
|
#7
|
|||
|
|||
|
I am developing a game system using the 65816, so I need a assembler or compiler, but all of the ones I seen are don't work on my PC or they are just not that powerful, thats why I decided to write my own. As far as the compatibility o between the 6502 and 65816, yes they are compatible, but, there are features very unique to the 65816 that the 6502 doesn't have. E.G. the 65816 is a 16-bit CPU(while the 6502 is 8-bit), that uses a 24-bit address bus, so it can address up to 128Mbits. it also has extended functionality on its Direct page addressing mode, something the 6502 never really had. I thought if I wrote my own assembler I could get all of the features I want and need, without other 'features' getting in my way. I did find one assembler for the 65816 but it was geared toward programming the Super Nintendo(which uses the 65816). I tried it out but in order for the code to assemble you need macros that are hardware specific to the SNES, and I don't know how that may effect my system.
|
|
#8
|
|||
|
|||
|
Okay, so you're an assembly programmer who want to make a 'little' C-Tool?
Maybe this can help you get started. I would (at first) suggest you use a fixed width source. E.g. a text file called 'source.asm': Code:
LDA $0445F2 ; load byte
LDA $03412F,x
Then walk through each line: Code:
char cLine[255];
FILE *f = fopen("source.asm", "r");
if(f)
{
while(!foef(f))
{
if(fgets(cLine, 255, f) != NULL)
{
ParseLine(cLine);
}
}
}
Using these functions: Code:
void TrimR(char *cLabel, int iSize)
{
int i;
cLabel[iSize] = '\0';
// Remove trailing spaces
for(i = (iSize-1); i>=0; i++)
{
if(cLabel[i] == ' ') cLabel[i] = '\0';
else break;
}
}
void ParseLine(char *cLine)
{
int i;
char cLabel[11], cOpcode[5], cParams[101];
// Locate remarks and strip it
char *p = strchr(cLine, 'r');
if(p) *p = '\0';
// Copy the label from pos 0 to 10
strncpy(cLabel, &cLine[0], 10);
TrimR(cLabel, 10);
// Copy the opcode from pos 10 to 14
strncpy(cOpcode, &cLine[10], 4);
TrimR(cOpcode, 4);
// Copy the parameters from pos 14
strncpy(cParams, &cLine[14], 100);
TrimR(cParams, 100);
/*
Do something with the parsed info here
*/
}
No idea if this compiles correct, but the principle should be enough ![]() |
|
#9
|
|||
|
|||
|
Thanks for the info dude. This was really helpful.
|
|
#10
|
|||
|
|||
|
You're welcome
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Text parsing for assembler |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|