• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading and converting file contents  RSS feed

 
Aaron Hanisch
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
greetings!
I am trying to find out how I might do the following:
I wish to read in a text file that is an assembly code. As the java program reads it I want it to convert the mnemonics it sees into opcodes. I have the table of opcodes, and all the mnemonics, but I need to know to to do the read and converting part.
Any help I'd really appreciate!
--Aaron
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aaron,
So you want to write an assembler? You certainly have everything you need in Java. But that isn't to say that it will be a cake walk. It's been over twenty years since I wrote any assmbly code, but as I recall one mnemonic could generate any number of opcodes according to indexing mode, etc. Then there is the problem with generating a symbol table and keeping up with offsets. But if you've thought all that out then you will probably want to use a java.io.FileReader for input and FileOutputStream wrapped in a BufferedOutputStream for output.
Here is the basic jist:

Now the above attacks the problem with a very optimistic approach. We are assuming that we can process one line at a time, which is probably not the case since any particular line may be affected by some other line. But this should give you a starting point. Of course you'll have to write the byte[] processLine(String) method above.
Hope this helps,
Michael Morris
[ February 13, 2003: Message edited by: Michael Morris ]
[ February 13, 2003: Message edited by: Michael Morris ]
[ February 13, 2003: Message edited by: Michael Morris ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!