Call and Return as global functions (and LT,GT,and EQ too)
After going through the project 8 I noticed that the call and return codes added a LOT to the total generated code. So My biggest wonder was whether or not "call" and "return" could be used as functions.
I had a feeling that there would be and after much thought I was able to implement such a routine.
Below are some hints as to how I was able to accomplish this feat.
The call_function needs to know three things. The return address, the number of arguments, and the line number of the function that will be called. every time the vm command requests a call, I store the above 3 things in a temporary variable, then jump to the call_function. The call_function will do stuff depending on what is stored in the three temporary variables.
The return function is much easier then the Call_function. Since everything you need to know is saved in the stack, you can simply make an unconditional jump to the return_function.
Also, as a side comment...it may be well worth the effort to make GT,LT, and EQ into functions as well.
I'm quite sure many people had to go through something like this therefore I didn't go into much detail. But in the event that this method is ground breaking....I'd be more than happy to elaborate.
Analyzing frequency of all VM commands in the Hack OS
If you are trying to minimize your code, your best choices are the high usage ones that your implementation will translate using lots of hack assembly instructions.
Re: Call and Return as global functions (and LT,GT,and EQ too)
I plan to optimize my translations once I get past the compiler chapters.
Im currently almost done chapter 9.
I tested translating the supplied OS files and then assembling.
To my shock I have around 54k lines of hack assembly, and about 50k of hack instructions.
As it seems many people found out, the 32k instructions limit for the ROM requires you to do some optimization if you want to be able to test your work in the simulator....and in my case I will have to since as it stands I con't even fit the OS into ROM.