project08 template files

This commit is contained in:
2025-10-26 17:51:57 -04:00
parent be00f40a6b
commit 38721f77c0
24 changed files with 1180 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
// 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/ProgramFlow/FibonacciSeries/FibonacciSeries.vm
// Puts the first n elements of the Fibonacci series in the memory,
// starting at address addr. n and addr are given in argument[0] and
// argument[1], which must be initialized by the caller of this code.
push argument 1 // sets THAT, the base address of the
pop pointer 1 // that segment, to argument[1]
push constant 0 // sets the series' first and second
pop that 0 // elements to 0 and 1, respectively
push constant 1
pop that 1
push argument 0 // sets n, the number of remaining elements
push constant 2 // to be computed, to argument[0] minus 2,
sub // since 2 elements were already computed.
pop argument 0
label LOOP
push argument 0
if-goto COMPUTE_ELEMENT // if n > 0, goto COMPUTE_ELEMENT
goto END // otherwise, goto END
label COMPUTE_ELEMENT
// that[2] = that[0] + that[1]
push that 0
push that 1
add
pop that 2
// THAT += 1 (updates the base address of that)
push pointer 1
push constant 1
add
pop pointer 1
// updates n-- and loops
push argument 0
push constant 1
sub
pop argument 0
goto LOOP
label END