FibonacciElement

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

FibonacciElement

pfonash
I'm having trouble with FibonacciElement, and I'm not sure what's wrong.

I've passed Simple Function and Nested Element, so I'm not sure which piece of my Translator is causing the problem.  I have bootstrap code setting SP to 256 and calling Sys.init.  

When running the CPU emulator, I've noticed that my stack frames match up with the VMs stack frames (except for the return address pushed onto the stack which I don't think needs to match up).  The problem seems to be on the first return. My .asm file never gets to the return code because it never gets past the JGT (if-goto) after the LT comparison.  I'm confused why there's a JGT after the LT because the LT will never return something greater than 0.  But my StackTest, BasicLoop, and FibSeries also pass, so I don't think there's a problem with my LT/if-goto code.  

Any help would be appreciated.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FibonacciElement

cadet1620
Administrator
Are you generating the JGT instead of JNE in your if-goto?  From 8.2.1 "if the value is not zero, execution continues from location marked by the label"  (I wouldn't expect that all the earlier tests would pass if that was so....)

One thing that can really help figuring out where generated code comes from is to include the source VM commands in the generated ASM as comments.  Here's an example from my VM translator:
    // not
@SP
A=M-1
M=!M
    // if-goto IF_TRUE0
@SP
AM=M-1
D=M
@Array.new$IF_TRUE0
D;JNE
    // goto IF_FALSE0
@Array.new$IF_FALSE0
0;JMP
    // label IF_TRUE0
(Array.new$IF_TRUE0)
    // push constant 2
@2
D=A

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

Re: FibonacciElement

pfonash
That did it.  Should've thought about it more carefully.  Onto Static.  Mark, you're a godsend.  Thank you.  

But, my code does pass the previous tests even when I generate JGT for the if-goto.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FibonacciElement

cadet1620
Administrator
pfonash wrote
But, my code does pass the previous tests even when I generate JGT for the if-goto.
I just looked at the ProgramFlow tests. Both of them implement "while (n>0)" loops, hence never test if-goto with a negative value. FibonacciElement is testing against true which is -1.

I'm thinking that ProgramFlow/FibonacciSeries should be changed to use "push 0; gt; if-goto" so that it tests against true.

--Mark
Loading...