Question: Write a function Fib.fib ( n ) in Hack VM code to calculate the n - th Fibonacci number recursively. Complete the code in Fib.vm

Write a function Fib.fib( n ) in Hack VM code to calculate the n-th Fibonacci number recursively. Complete the code in Fib.vm Where: Fib.fib is the name of the function n is which number in the Fibonacci sequence to calculate, Where: Fib.fib(0)==0 Fib.fib(1)==1 The call command for this function is provided in a separate file (See Sys.vm) Test Cases: Write at least 3 test cases. A sample test case is provided in Fib00.tst Each test case should be in a file named FibXX.tst where XX is a number starting at 01. You should also submit any supporting files, such as CMP files. Your mark for this task may be scaled down for poor/missing testing. Fib.vm: // Contains a function Fib.fib that calculates and returns the nth Fibonacci number recursively // n is supplied as an argument // Put your code here. Fib00.tst: // Sample Test file for ArrSort.asm // Follows the Test Scripting Language format described in // Appendix B of the book "The Elements of Computing Systems" load, output-file Fib00.out, compare-to Fib00.cmp, output-list sp%D1.6.1 local%D1.6.1 argument%D1.8.1 this%D1.6.1 that%D1.6.1 RAM[16]%D1.6.1 RAM[17]%D1.6.1 RAM[18]%D1.6.1 local[0]%D1.8.1 local[1]%D1.8.1 local[2]%D1.8.1 argument[0]%D1.11.1 argument[1]%D1.11.1 argument[2]%D1.11.1; set sp 256,// stack pointer set local 300,// base address of the local segment set argument 400,// base address of the argument segment set this 3000,// base address of the this segment set that 3010,// base address of the that segment set RAM[16]0,// static 0 set RAM[17]4,// static 1 set RAM[18]0,// static 2 set local[0]10,// local 0 set local[1]20,// local 1 set local[2]30,// local 2 set argument[0]100,// argument 0 set argument[1]200,// argument 1 set argument[2]300; // argument 2 repeat 200{// Change this number to cover the number of instructions in the VM test file vmstep; } output; Fib00.cmp: | sp | local | argument | this | that |RAM[16]|RAM[17]|RAM[18]| local[0]| local[1]| local[2]| argument[0]| argument[1]| argument[2]||256|300|400|3000|3010|3|4|0|10|20|30|100|200|300| Sys.vm: // Runs x = Fib.fib(y)// x & y are static variables function Sys.init 0 push static 1 call Fib.fib 1 pop static 0 label END goto END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!