Where is Sys.init defined?

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

Where is Sys.init defined?

Henoktes722
In the bootstrap code,

SP=256
call Sys.init

I know that Sys.init calls the main function of the program to start executing of our program. But I can't say it is already defined, because we are actually build the computer from down, so we know what things had so far. If it is not a primitive, how can I create this function, the logic of finding and executing the main method?
Reply | Threaded
Open this post in threaded view
|

Re: Where is Sys.init defined?

WBahn
Administrator
Sys.init() is simply a function that is compiled just like any other Jack code.

The trick isn't how Sys.init() finds the Main.main() function, it simply calls it just like any other piece of Jack code calls any other function.

The trick is how Sys.init() gets called. That is the role of the bootstrap code that is put at the beginning of the .asm file by the VM translator.
Reply | Threaded
Open this post in threaded view
|

Re: Where is Sys.init defined?

Henoktes722
So do I need to define the function or it's a primitive?
Reply | Threaded
Open this post in threaded view
|

Re: Where is Sys.init defined?

WBahn
Administrator
Henoktes722 wrote
So do I need to define the function or it's a primitive?
Eventually you will write that function as part of the operating system. But for now it is supplied. Read the description of the test programs for the function calling commands (p171 of the text).
Reply | Threaded
Open this post in threaded view
|

Re: Where is Sys.init defined?

Henoktes722
Sure, I'll definitely check it.