Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

A 300N F 30% d 2 m Answered: 1 week ago

Answered: 1 week ago

Question

=+What do you want them to know?

Answered: 1 week ago

Question

=+1. How can you animate it?

Answered: 1 week ago