C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 21st, 2005, 08:24 PM
Contra Contra is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The US
Posts: 7 Contra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 10 sec
Reputation Power: 0
Send a message via AIM to Contra
Question Text parsing for assembler

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!!

Reply With Quote
  #2  
Old August 22nd, 2005, 07:06 AM
MichaelSoft MichaelSoft is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The Netherlands
Posts: 121 MichaelSoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 20 sec
Reputation Power: 4
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...

Reply With Quote
  #3  
Old August 22nd, 2005, 09:29 AM
Contra Contra is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The US
Posts: 7 Contra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 10 sec
Reputation Power: 0
Send a message via AIM to Contra
Quote:
Originally Posted by MichaelSoft
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...


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).

Reply With Quote
  #4  
Old August 23rd, 2005, 06:15 AM
MichaelSoft MichaelSoft is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The Netherlands
Posts: 121 MichaelSoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 20 sec
Reputation Power: 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?

Reply With Quote
  #5  
Old August 23rd, 2005, 06:20 PM
Contra Contra is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The US
Posts: 7 Contra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 10 sec
Reputation Power: 0
Send a message via AIM to Contra
Preferably both. I noticed your links take me to tools for the 6502, I need tools for the 65816.

Reply With Quote
  #6  
Old August 24th, 2005, 06:11 AM
MichaelSoft MichaelSoft is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The Netherlands
Posts: 121 MichaelSoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 20 sec
Reputation Power: 4
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)??

Reply With Quote
  #7  
Old August 24th, 2005, 11:17 AM
Contra Contra is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The US
Posts: 7 Contra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 10 sec
Reputation Power: 0
Send a message via AIM to Contra
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.

Reply With Quote
  #8  
Old August 25th, 2005, 08:20 AM
MichaelSoft MichaelSoft is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The Netherlands
Posts: 121 MichaelSoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 20 sec
Reputation Power: 4
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

Reply With Quote
  #9  
Old August 25th, 2005, 08:53 AM
Contra Contra is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The US
Posts: 7 Contra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 10 sec
Reputation Power: 0
Send a message via AIM to Contra
Thanks for the info dude. This was really helpful.

Reply With Quote
  #10  
Old August 26th, 2005, 06:20 AM
MichaelSoft MichaelSoft is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The Netherlands
Posts: 121 MichaelSoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 20 sec
Reputation Power: 4
You're welcome

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Text parsing for assembler


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT