JackCompiler -> Vm2Asm -> Assembler

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

JackCompiler -> Vm2Asm -> Assembler

Diogo
Hello there,

I am a computer science student, going through this amazing book on my own. I am in need of some assistance. Thanks in advance for any one willing to help =)

I've got my Assembler and Vm-2-Asm translator working (wrote those in plain C, both passed all the tests). Following the suggestion given in page 174, I am interested in compiling the supplied Square project from Chapter 9 using the JackCompiler, then further translate the compiled VM code into binary code using my own translator and assembler.

So, this is what I've tried:

0. I put all files from tools/OS into the Square folder (as suggested in page 197);

1. Compiled the Square folder with the JackCompiler;

2. Tested the compiled project at the VmEmulator and all went well;

3. Translated all .vm files into one single Square.asm file using my translator;

4. Tested the Square.asm file with the CPUEmulator and the error "In line 0, ')' expected" came up. Cheking the code there was no reason for ')' at the first line... got confused there!;

5. Just for the sake of it, I went ahead and ran Square.asm through my Assembler to Square.hack;

6.  Tested the Square.hack file with the CPUEmulator and the error "Program too large" came up. Well, I then realized that my Vm2Asm translator did translate all the functions from the OS files as well as the Square projects files so the generated .asm file has near 56K lines (lots of those are comments). The generated .hack file has near 47K lines.

So... that raised some questions in my mind.

q0. Did I do something wrong? In general, I mean...

q1. Is the error "In line 0, ')' expected" related to the fact that the file is way too large?

q2. Can it be that something is wrong with my assembler and/or Vm2Asm translator (please, recall that both passed all supplied tests)?

q3. Or is it something wrong with the whole process described above?

Once again, thanks in advance! By the way, this book is really, really amazing!!!

Best regards,
Diogo
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JackCompiler -> Vm2Asm -> Assembler

cadet1620
Administrator
It sounds like you are doing everything right.  You will feel amazing when you finally get your whole tool chain working.

I haven't hear about the "error in line 0". I would not be surprised if it's caused by the .asm file being too long. As an experiment you could try shortening it with a text editor and see what happens.

Sounds like your compiler and VM translator are OK.  One of the things that you've seen is that the code your VM translator generates is much larger than that generated by the supplied VM translator. This happens to most people. When I encountered it, I thought about what VM commands generated huge amounts of code -- it's no secret, it's call and return -- and how I might be able to write an assembly language helper routine that would shorten them. The idea is to load arguments in R13-15 and jump to a routine that your VM translator wrote as part of the bootstrap. You can do the same thing for 'gt', 'eq' and 'lt' which are also a bi big, but there are not so many of them that it makes such a big improvement.

This post shows the number of various VM commands in the OS .vm files.

One thing that I just remembered was a student who was writing in C and ended up with the \0 on the end of some of his strings written to the output file. The Java based tools were not too happy about that!

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JackCompiler -> Vm2Asm -> Assembler

Diogo
Mark, thanks for your time and attention.

The "In line 0, ')' expected" message went away when I re-translated the project. I went back to the previous version looking for the reasons. Well, I found out that I had somehow accidentally typed a '@' on a label, probably when browsing around with my text editor.

So, I wanted to share this: if you load your translated ASM files in the CPUEmulator and get the error "In line 0, ')' expected", look for your labels, you might have something like:

@symbol
...
(@symbol) <- wrong


Also, your tips on how to start thinking about optimization were great. When I finally realized the whole idea I was like "how come I didn't think about this before?" =)

I followed your benchmark numbers on the post. Well... from 42K HACK instructions now I can translate the whole OS folder to 22544 instructions. Needless to say, my codewriter module became quite big, dealing with lots of specific sequences of VM instructions and all. Optimizing is fun, but I'll leave that for now...

Finally, I was able to tool chain the whole thing... and yes, it felt amazing!

Thanks once again Mark,
Diogo

ps.: although posted on the chapter 9 folder, this was really about chapter 8, sorry about that.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JackCompiler -> Vm2Asm -> Assembler

Andrew
In case anyone else searches for "In line 0, ')' expected"

I found that it had to do with an illegal character being used for labels. I had allowed '\' to be used as a character in my labels, and it was giving me this error when trying to load the .asm file. Note that this was nowhere near line 0 at all, so I spent a lot of time staring at a very simple line that was perfectly correct.

Message: the message doesn't necessarily indicate an error at line 0, so consider other possibilities. I spent a long time learning that, so I wanted to share in case anyone else has that problem.
Loading...