Is there any required or recommended order in which *.vm files should be read by VM translator and written to final *.asm file?

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

Is there any required or recommended order in which *.vm files should be read by VM translator and written to final *.asm file?

kraftwerk1611
Hi,

I read in the book that bootstrap code that sets SP=256 and calls Sys.Init function should be at the beginning of asm file.


But  after that does it matter in what order we read, process *.vm files and write them to final *.asm file?

If there are two files Sys.vm and Main.vm, should Sys.vm be read, processed and written first?
I see Sys.vm making following call

call Main.fibonacci 1

So I am guessing you can process them in any order.

I am not finding any call to Sys.Init anywhere. Do we have to add and process some more vm files or is it already taken care of by CPU emulator?


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

Re: Is there any required or recommended order in which *.vm files should be read by VM translator and written to final *.asm file?

cadet1620
Administrator
kraftwerk1611 wrote
I read in the book that bootstrap code that sets SP=256 and calls Sys.Init function should be at the beginning of asm file.

But  after that does it matter in what order we read, process *.vm files and write them to final *.asm file?
It does not matter what order you process the .vm files. All function calls result in an ASM jump to (FunctionName) so the will run in the correct order regardless of where in the .asm file the functions end up.

Implementation note: some OSes and language libraries return directory listings in unsorted order. I explicitly sort the names I get back from my readDirectory() call before processing the list. It's a lot easier to debug when the class order in the asm file doesn't change unexpectedly.

I am not finding any call to Sys.Init anywhere. Do we have to add and process some more vm files or is it already taken care of by CPU emulator?
Yes, you must write the call to Sys.init.  All you need to do after setting SP=256 is call your code writer function for "call Sys.init 0".

I like to put a "(HALT) @HALT 0;JMP" loop immediately after the call to Sys.init(). Although Sys.init() is not supposed to return, you will be writing your own Sys.init() in project 12. It's much easier to debug if the code doesn't go wild if you have a bug and your Sys.init() accidentally returns.

--Mark