Anpassungen Path-Struktur

This commit is contained in:
2024-04-12 11:01:46 +02:00
parent f6eeaf8c46
commit 7ec9c55e13
448 changed files with 85529 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/8/FunctionCalls/FibonacciElement/Main.vm
// Contains one function: Main.fibonacci.
// Computes the n'th element of the Fibonacci series, recursively.
// n is given in argument[0]. Called by the Sys.init function
// (part of the Sys.vm file), which sets argument[0] to an input
// value and then calls Main.fibonacci.
function Main.fibonacci 0
push argument 0
push constant 2
lt
if-goto N_LT_2
goto N_GE_2
label N_LT_2 // if n < 2 returns n
push argument 0
return
label N_GE_2 // if n >= 2 returns fib(n - 2) + fib(n - 1)
push argument 0
push constant 2
sub
call Main.fibonacci 1 // computes fib(n - 2)
push argument 0
push constant 1
sub
call Main.fibonacci 1 // computes fib(n - 1)
add // returns fib(n - 1) + fib(n - 2)
return