One failed comparison with FibonacciElement and StaticsTest

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

One failed comparison with FibonacciElement and StaticsTest

pstrawn
I have almost finished Ch. 8: my code passes for BasicLoop, Fibonacci, NestedCall, and SimpleFunction. However, below are the failed comparisons for the last two programs.

FibonacciElement
Test Output
| RAM[0] |RAM[261]|
|    262 |      3 |

My Output
FibonacciElement
| RAM[0] |RAM[261]|
|    262 |      4 |

StaticsTest
Test Output
| RAM[0] |RAM[261]|RAM[262]|
|    263   |     -2       |      8 |

My Output
FibonacciElement
| RAM[0] |RAM[261]|RAM[262]|
|    263   |     8       |      8 |

I've tried everything I can to debug: comparing assembly commands and tracing code, running the VME.tst file, double-checking how I handle labels and returns.

I have a feeling it has to do with how I handle the return-address in my assembly code for `call f n`, but if that were the case, wouldn't NestedLoop and SimpleFunction fail as well?

Maybe the more likely culprit is how my bootstrap code works? That's the only new code that's not tested in the other four (from what I can tell).

My logic with that is as follows (in pseudocode):
// Set SP to 256
// Call the writeCall() method from within writeInit() passing as arguments Sys.init and 0

On reflection, maybe that second step is the wrong way to set everything up. It seems almost too easy, which means it's probably not right. Any pointing-in-the-right-direction would be greatly appreciated. Thank you! I see the end in sight once I get over this hump of Ch. 8!
Reply | Threaded
Open this post in threaded view
|

Re: One failed comparison with FibonacciElement and StaticsTest

cadet1620
Administrator
Your bootstrap looks OK.

The new things in the failing tests are:
    recursion (FibonacciElement) -- beware of any temp RAM data the you might require to be maintained across a function call.
    static variables in multiple classes (StaticsTest) -- double check that static variables get names that are unique between VM files.

If you are not already doing so, write the VM source code in the ASM output as comments. This will help you find your way around in your ASM.
// push $Cordic 4
    @RIP$421
    D=A
    @$PUSH_MEM__Cordic.4$
    0;JMP
(RIP$421)

// add
    @RIP$422
    D=A
    @$STACK_add$
    0;JMP
(RIP$422)

// pop pointer 1
    @RIP$423
    D=A
    @$POP_MEM_4$
    0;JMP
(RIP$423)
[Don't try to understand the ASM in the above example; it is the output from a highly optimized  translator.]

If you want to, email me the ASM you generate (with source comments) for the failing tests and I'll take a look at it when I get the chance.  I'm on vacation this week but should have time available in the mornings and evenings.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: One failed comparison with FibonacciElement and StaticsTest

omar
In reply to this post by pstrawn
I had the same output, I initialized the stack in the bootstrapper to 261 and it worked.
Reply | Threaded
Open this post in threaded view
|

Re: One failed comparison with FibonacciElement and StaticsTest

pstrawn
In reply to this post by cadet1620
Update: I cleaned up (or so I thought) how I handled R13-R15. It didn't help with FibonacciElement, but now I get the right output for StaticsTest. It must be something with how I (mis)handle recursion. I do print the VM code as comments, so I'm trying to trace my output by hand using the CPUEmulator and my commented code. Thanks for the pointers - I will keep at it for a little while longer before sending an email. I do appreciate the guidance immensely!
Reply | Threaded
Open this post in threaded view
|

Re: One failed comparison with FibonacciElement and StaticsTest

cadet1620
Administrator
Glad to see you still working on it; I like tenacious students.

One thought about the recursive failure, be sure that you are saving the return address on the stack, not in one of R13-15.  I remember seeing one student's translator that generated code that had return using a value chat call stored in one or the R registers...

--Mark