What language do most students use to write the assembler?
What language are most of your students using to write the assembler? I've told mine they can use any programming language/environment they want; most of them are electing to use java (probably because they know it the best, having just come out of the AP course). Any pros and cons to the different languages?
I just finished an assembler that can do Add.asm using bash. I started it on a plane on a windows laptop where the only programmery thing I had available was cygwin. I don't think I will continue on this path.
Python is an elegant language and it is easy to make prototypes in it very fast.
With Python you always have a running program, more or less correct.
Programming with Python feels a bit like modeling clay.
The assembler was my first Python program (170 lines) ever and I learned programming Python
from the official Python tutorial and "Learning Python - 4-edition , O'Reiilly " by Mark Lutz.
I used GNU Emacs version 24 on Fedora Linux with the standard Python mode,
which has excellent text highlighting and error handling.
The GNU Emacs editor, as an programming environment, is just AMAZING.
You step in a conceptually very well designed new world , boundless, really user friendly and (thus) demanding.
I did mine in Fortran, about 350 lines. It was several years after I last touched f77, and the code quality does not make me too proud. It was quite fast though.
I have received implementations in java, c#, perl, python and ruby, java being by far the most popular.
UPDATE: For the VM (Chapter 7) I switched to Swift. I don't have the time/patience to deal with string manipulation and memory management in C right now!
I wrote mine in C. It's definitely a lot harder than one in a language like Ruby or Python would be, but but I did it for a couple of reasons.
* I'm doing nand2tetris to learn more about how computers work. So when it comes to the programming projects I don't mind having to deal with the low-level details as that's what I'm here for. I could whip up an assembler in Ruby but I wouldn't learn nearly as much.
* If I ever did want to implement my own language (or work on one of the popular ones out there) there's a good chance the compiler or VM for that will be written in C.
I've just started the next project (VM instructions to assembly instruction compiler) in C too :).
I should note though I took a lot of shortcuts to get something working, like having a fixed sized array for commands and symbols (instead of using linked lists and hash tables). I plan to come back and improve that later once I've I done more of the later states.
Re: What language do most students use to write the assembler?
This post was updated on .
Thanks, I did see that post about uthash. I'll probably start using it once I don't feel like writing my own any longer :) But I think at least for this I'll implement one.
Thanks for the book recommendation. It seems like you can only get second hand copies but that's fine, I might get one. Actually I'm working my way through "Learn C The Hard Way" which the author has put online and is free to read according to his licence note (the book isn't published yet, but is quite complete, and all the examples I've tried compile/run fine). It's excellent, I find the coding style quite readable and refreshingly different to what I remember C looking like last I learned it (many years ago). I like use of "modern" techniques like unit testing that you don't normally associate with C. The latter half of the book covers some data structures and algorithm implementations (everything I'd imagine you'd need for a Jack compiler, from what I know of it so far).
I might try and incorporate tests into the VM (Project 7) translator.
Also, completely unrelated to this but I'm thinking now of structuring my project as one app that I refine through the projects. That way I can benefit from bug fixes etc. that I make.
jack Prog.asm # Produces Prog.hack, i.e. Project 6
jack Prog.vm # Produces Prog.asm i.e. Project 7
jack Prog.jack # Produces Prog.vm (I think, haven't made it that far yet!)
Maybe then finally once all done, the file writing in between could be moved to optional flags and then it could be one step to go from .jack to .hack:
jack Prog.jack # Produces Prog.hack
This isn't really suggested anywhere in the book but it seems to make more sense than several distinct programs.
I used Common Lisp. ~100 lines of code when blank and comment lines are ignored.
I wrote it in functional style using an alist instead of a hash table for the symbol table so I guess it will be a bit slow when assembling a program with a huge number of symbols. No trouble with pong though - it assembles in a fraction of a second.
This is the longest program I've written in lisp to date. It was also the toughest of the projects so far for me but the buzz from playing pong assembled with my program certainly made it worthwhile.
This really is a fantastic course. Thank you!