Chap 9 intro (compiling/translating/assembling supplied Pong.jack)

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

Chap 9 intro (compiling/translating/assembling supplied Pong.jack)

The111
I just started reading Chapter 9, and in the intro there are two facts mentioned:
1) .Jack source files for Pong are supplied with the book
2) We can (a) compile them with the supplied JackCompiler, and then run the .vm files straight in the VME, or (b) translate/assemble the .vm code with our own previous projects, and run the machine code on a CPU emu.

However, there is a problem I'm having with #2.  Just for fun, before getting further into the rest of the book, I found the .Jack source files for Pong.  I compiled them using the JackCompiler, and immediately noticed there is no Sys.init function, which was a strict requirement in our translator program.  So it is not even possible for me to try 2(b) as suggested.  I did try manually renaming the Main.vm to Sys.vm, renaming the functions within accordingly, and adding a dummy Sys.init function to start the whole thing off.  So after that my translator would indeed translate it, however, the CPU emulator, when running the .asm file, has an invalid memory access error eventually, and also never displays anything on the screen.

I am sure if I debugged this for long enough I might get to the bottom of it, but I was wondering if I was missing something more obvious?  It is somewhat disappointing that the .vm code output produced by the supplied compiler does not meet the input specs of our translator project (specifically the necessity of a Sys.init function).

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Chap 9 intro (compiling/translating/assembling supplied Pong.jack)

Dano
Hi The111,

function "Sys.init" is part of Operating System/Standard library, which are built later in chapter 12. However, you can use .vm files from OS directory of original software suite. Hope that helps.
Reply | Threaded
Open this post in threaded view
|

Re: Chap 9 intro (compiling/translating/assembling supplied Pong.jack)

The111
Thanks.  When I put all the OS/lib .vm's in with the Pong vm's, then when I run on the VME it works fine, with no warnings about using built-in functions instead (since I've of course put them all there in the same directory).

However, now when I assemble that directory to .asm file, it is 59k lines, which is 2x to large to fit in the Hack instruction ROM.  So I still can't seem to run the native code just for fun. :-(
Reply | Threaded
Open this post in threaded view
|

Re: Chap 9 intro (compiling/translating/assembling supplied Pong.jack)

Dano
My toolchain implementation is able to squeeze Pong including OS to ~22k instructions. I would suggest reading thread about generated code size.
Reply | Threaded
Open this post in threaded view
|

Re: Chap 9 intro (compiling/translating/assembling supplied Pong.jack)

The111
Great, thanks for that link too.  I'll leave that as my project 13... improve my intermediate tools along those lines. :-)