bootstrap confusion for FibElement

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

bootstrap confusion for FibElement

The_Larks
I'm a little perplexed here. Bootstrap is supposed to set SP to 256, then *literally* call Sys.int(). Then, we let our regular VM take over in parsing the rest (and **ALL**) of Sys.vm for FibonacciElement?

My code passes all tests, including a "Call only" test, but it fails on bootstrap. I'm probably not understanding exactly what they are asking for, but is it just me, or shouldn't bootstrap be a fairly simple implementation once you get to it?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bootstrap confusion for FibElement

cadet1620
Administrator
The_Larks wrote
I'm a little perplexed here. Bootstrap is supposed to set SP to 256, then *literally* call Sys.int(). Then, we let our regular VM take over in parsing the rest (and **ALL**) of Sys.vm for FibonacciElement?

My code passes all tests, including a "Call only" test, but it fails on bootstrap. I'm probably not understanding exactly what they are asking for, but is it just me, or shouldn't bootstrap be a fairly simple implementation once you get to it?
The bootstrap code is just what you describe.  From my VM translator (in Python):
    def WriteInit(self):
        """
        Write the VM initialization code:
            Set the SP to 256.
            Call Sys.Init()
            Halt loop
        """
        self._WriteCode('@256, D=A, @SP, M=D')
        self.WriteCall('Sys.init', '0')
        self._WriteCode(self._CodeHalt())
Note that the halt loop after the call is not strictly required; it's a safety feature in case some errant Sys.ini returned.

I don't understand what you mean by "fails on bootstrap".

All of the tests in ProgramFlow will fail if you include bootstrap code, as will FunctionCalls/SimpleFunction.
FunctonCalls/NestedCall can run with or without bootstrap code.
FunctonCalls/FibonacciElement and FunctonCalls/StaticsTest require bootstrap code.

I added a command option -n (no-bootstrap) to my translator so that I could still run the earlier tests.

You mention FibbonacciElement. Are you padding NestedCall? It is an intermediate test between SimpleFunction and FibbonacciElement.

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

Re: bootstrap confusion for FibElement

The_Larks
Haha it means I have confirmed that my call command is not the culprit. You wrote me a test script last night, remember? So rather than implement "call" and bootstrap *then* test both, I'm really just testing the latter here. 

On Nov 9, 2016, at 5:04 AM, cadet1620 [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:

The_Larks wrote
I'm a little perplexed here. Bootstrap is supposed to set SP to 256, then *literally* call Sys.int(). Then, we let our regular VM take over in parsing the rest (and **ALL**) of Sys.vm for FibonacciElement?

My code passes all tests, including a "Call only" test, but it fails on bootstrap. I'm probably not understanding exactly what they are asking for, but is it just me, or shouldn't bootstrap be a fairly simple implementation once you get to it?
The bootstrap code is just what you describe.  From my VM translator (in Python):
    def WriteInit(self):
        """
        Write the VM initialization code:
            Set the SP to 256.
            Call Sys.Init()
            Halt loop
        """
        self._WriteCode('@256, D=A, @SP, M=D')
        self.WriteCall('Sys.init', '0')
        self._WriteCode(self._CodeHalt())
Note that the halt loop after the call is not strictly required; it's a safety feature in case some errant Sys.ini returned.

I don't understand what you mean by "fails on bootstrap".

All of the tests in ProgramFlow will fail if you include bootstrap code, as will FunctionCalls/SimpleFunction.
FunctonCalls/NestedCall can run with or without bootstrap code.
FunctonCalls/FibonacciElement and FunctonCalls/StaticsTest require bootstrap code.

I added a command option -n (no-bootstrap) to my translator so that I could still run the earlier tests.

You mention FibbonacciElement. Are you padding NestedCall? It is an intermediate test between SimpleFunction and FibbonacciElement.

--Mark


To unsubscribe from bootstrap confusion for FibElement, click here.
NAML
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bootstrap confusion for FibElement

cadet1620
Administrator
The_Larks wrote
Haha it means I have confirmed that my call command is not the culprit. You wrote me a test script last night, remember? So rather than implement "call" and bootstrap *then* test both, I'm really just testing the latter here.
FibonacciElement is a complex test that includes recursive calls.  It is common for student's call and return code to work perfectly with all tests except FibbonacciElement and NestedCall.

Important: does your code with bootstrap pass NestedCall? If so, and FibonacciElement fails, the problem is most likely due to the recursion.

The FibonaccElement algorithm is:

    int fib(int n) {
        if (n < 2)
            return n;
        return fib(n-2) + fib(n-1);
    }

It is called with n=4.

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

Re: bootstrap confusion for FibElement

The_Larks
This post was updated on .
You know, that's a good question and I had meant to ask that. I think my text is outdated and though NestedCall was included in my .zip file, I don't see it mentioned in the book, so I wasn't sure in which order to test it.

It's just a bit frustrating here that we can't have tests to *isolate*, incrementally, each added implementation. So I'm left not being sure where the error is and just spinning my tires.
Loading...