What language do most students use to write the assembler?

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

What language do most students use to write the assembler?

Marty Billingsley
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?
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

ybakos
I've received implementations in Ruby, Python, C++, PHP, Java and even Delphi.
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

ivand
In reply to this post by Marty Billingsley
Did mine in Perl, around 200 lines of code, very straightforward.
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

Pradeep
In reply to this post by ybakos
Can you please send me the java implementation of the assembler please. My email id is mailpradeev@gmail.com
Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

James
i used C#
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

damanska
I did mine in C in maybe 500-600 lines of code. I wrote a small hash table for it though which made the program bigger.
I am gonna try in python now, should be much shorter :)
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

gauze
In reply to this post by Marty Billingsley
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.
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

wilkist1
In reply to this post by Marty Billingsley
I used Python - the dictionary data type was very useful! Took about 200 lines of code. I found the API descriptions really useful for structuring the program.
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

gauze
In reply to this post by gauze
ok I finished it in shell script, 225 lines including some error reporting, usage message.
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

Rather Iffy
This post was updated on .
In reply to this post by Marty Billingsley
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.
 
--Chrit
 
rst
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

rst
In reply to this post by Marty Billingsley
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.
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

rgravina
This post was updated on .
In reply to this post by Marty Billingsley
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.
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

cadet1620
Administrator
There's a really nice hash table / dynamic array package available for C. See this post.

If you haven't written a hash table before, I highly recommend you do so; it's quite educational.

You might find a good book on Data Structures interesting. You can find cheap copies of the first ed. (1992) of Ellis Horowitz, "Fundamentals of Data Structures in C" using bookfinder:
    http://www.bookfinder.com/
Here's a direct link to the search results.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

rgravina
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).
http://c.learncodethehardway.org/book/

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.

E.g.

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

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.
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

jsaff
In reply to this post by Marty Billingsley
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!
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

cestdiego
In reply to this post by Marty Billingsley
I used emacs lisp :) and I even made a major mode for it, it's called nand2tetris.el (it's on MELPA)
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

fernandocardia
In reply to this post by Marty Billingsley
I've made it using PHP, less than 200 lines. Mainly because it's outstanding on manipulating arrays structures, as python too.
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

Jason Toams
In reply to this post by Marty Billingsley
nodejs 200line code.
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

Chen Li
In reply to this post by cestdiego
Nice to see you here! Thanks to your great work. I have been using your package since the start of learning of nand2tetris. It's really convenient!
Reply | Threaded
Open this post in threaded view
|

Re: What language do most students use to write the assembler?

Chen Li
In reply to this post by Marty Billingsley
I write assembler with standard ml. Here is my project: https://github.com/FirstLoveLife/-Assembler-for-nand2tetris
12