Error in FibonacciElement.cmp?

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

Error in FibonacciElement.cmp?

ashleyjsands
To my fellow students,

I think that there may be an error in FibonacciElement.cmp. Here is the contents of the file for convenience:
| RAM[0] |RAM[261]|
|    262 |      3 |

The book states that your boot loading code should set the stack pointer (RAM[0]) to 256. So after the Fibonacci function has finished, the stack pointer should be 257, not 262.

I believe the reason for this error in the cmp file is that the VM test script sets the stack pointer to 261 and uses the same compare file. This is why the compare file expects the return value in 261 and expects the stack pointer to be 262.

In conclusion the compare file for the CPU emulator should be:
| RAM[0] |RAM[256]|
|    257 |      3 |

Please correct me if I'm wrong.

Regards,
Ashley


Reply | Threaded
Open this post in threaded view
|

Re: Error in FibonacciElement.cmp?

cadet1620
Administrator
FibonacciElement.cmp is OK. Quoting from the book (end of 8.3.1)
... the computer's bootstrap code should effect the following operations (in machine language):
    SP=256          // Initialiaze the stack pointer to 0x0100
    call Sys.init   // Start executing (the translated code of) Sys.init
That's a VM call, not just a jump.

When Sys.init() starts runing, there is a full stack frame on the stack. This stack frame is why the final SP is 5 greater than you are expecting.

--Mark


Reply | Threaded
Open this post in threaded view
|

Re: Error in FibonacciElement.cmp?

ashleyjsands
Thank you Mark. Now that makes sense.