Writing the Assembler in Hack (assembly) language

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Writing the Assembler in Hack (assembly) language

Amaan
Hey!

I was wondering how I'd go about creating the Assembler in the Hack Assembly Language itself, instead of using a language like Python or C. As far as I can tell, I'd need to create some mechanism to fill the Assembly code somewhere in memory, and for my Hack program to go over this memory, assembling it somehow.

As far as I can tell, this isn't made easy to do by the GUI.

Ways I can think of doing this:

1) Use the CPU Simulator and load up my Assembler.hack file and fill in Hack instructions in a pre-determined area of the RAM (interpreting every 2-byte register as an ASCII character?). Convert these instructions into the respective A-type and C-type instructions in a different area of RAM.

This method sounds incredibly painful, especially considering that the GUI is supplied with only the compiled class files, not the original Java files, so I can't simply modify the GUI to make it easier to input code into the RAM.

2) Write my own Hack interpreter, like what they've got, but one that can be extended more easily and will allow us to do what I want more easily.

This sounds like a pretty fun learning experience, but it might be a bit too involved for someone more interested in taking the course and less in creating the course itself.

Thoughts? Am I missing some other obvious way to create the Hack Assembler using the Hack Assembly Language itself?
Reply | Threaded
Open this post in threaded view
|

Re: Writing the Assembler in Hack (assembly) language

ivant
Check out this thread: How the real assemblers work?
Reply | Threaded
Open this post in threaded view
|

Re: Writing the Assembler in Hack (assembly) language

Amaan
Thanks! After having considered it for a bit, I think I'll just go the traditional route and build the Assembler in a high-level programming language.

Building an Assembler in Assembly can be a project for another time!