mirror of
https://github.com/usatiuk/nand2tetris.git
synced 2025-10-29 00:27:49 +01:00
162 lines
2.0 KiB
Plaintext
162 lines
2.0 KiB
Plaintext
function Memory.init 0
|
|
push constant 0
|
|
pop static 0
|
|
push constant 2048
|
|
pop static 1
|
|
push constant 2048
|
|
pop static 2
|
|
push constant 0
|
|
push static 1
|
|
add
|
|
push constant 0
|
|
pop temp 0
|
|
pop pointer 1
|
|
push temp 0
|
|
pop that 0
|
|
push constant 1
|
|
push static 1
|
|
add
|
|
push constant 14335
|
|
pop temp 0
|
|
pop pointer 1
|
|
push temp 0
|
|
pop that 0
|
|
push constant 0
|
|
return
|
|
function Memory.peek 0
|
|
push argument 0
|
|
push static 0
|
|
add
|
|
pop pointer 1
|
|
push that 0
|
|
return
|
|
function Memory.poke 0
|
|
push argument 0
|
|
push static 0
|
|
add
|
|
push argument 1
|
|
pop temp 0
|
|
pop pointer 1
|
|
push temp 0
|
|
pop that 0
|
|
push constant 0
|
|
return
|
|
function Memory.alloc 2
|
|
push static 2
|
|
pop local 0
|
|
label WHILE_EXP0
|
|
push local 0
|
|
push constant 0
|
|
gt
|
|
not
|
|
if-goto WHILE_END0
|
|
push constant 1
|
|
push local 0
|
|
add
|
|
pop pointer 1
|
|
push that 0
|
|
push argument 0
|
|
push constant 1
|
|
add
|
|
gt
|
|
if-goto IF_TRUE0
|
|
goto IF_FALSE0
|
|
label IF_TRUE0
|
|
push constant 8010
|
|
push constant 1
|
|
call Memory.poke 2
|
|
pop temp 0
|
|
push local 0
|
|
push constant 1
|
|
push local 0
|
|
add
|
|
pop pointer 1
|
|
push that 0
|
|
add
|
|
push argument 0
|
|
sub
|
|
pop local 1
|
|
push constant 1
|
|
push local 0
|
|
add
|
|
push constant 1
|
|
push local 0
|
|
add
|
|
pop pointer 1
|
|
push that 0
|
|
push argument 0
|
|
sub
|
|
push constant 2
|
|
sub
|
|
pop temp 0
|
|
pop pointer 1
|
|
push temp 0
|
|
pop that 0
|
|
push constant 0
|
|
push local 1
|
|
add
|
|
push constant 0
|
|
pop temp 0
|
|
pop pointer 1
|
|
push temp 0
|
|
pop that 0
|
|
push constant 1
|
|
push local 1
|
|
add
|
|
push argument 0
|
|
pop temp 0
|
|
pop pointer 1
|
|
push temp 0
|
|
pop that 0
|
|
push local 1
|
|
return
|
|
goto IF_END0
|
|
label IF_FALSE0
|
|
push constant 0
|
|
push local 0
|
|
add
|
|
pop pointer 1
|
|
push that 0
|
|
pop local 0
|
|
label IF_END0
|
|
goto WHILE_EXP0
|
|
label WHILE_END0
|
|
push constant 0
|
|
return
|
|
function Memory.deAlloc 1
|
|
push static 2
|
|
pop local 0
|
|
push local 0
|
|
push constant 0
|
|
eq
|
|
if-goto IF_TRUE0
|
|
goto IF_FALSE0
|
|
label IF_TRUE0
|
|
push argument 0
|
|
pop static 2
|
|
push constant 0
|
|
return
|
|
label IF_FALSE0
|
|
label WHILE_EXP0
|
|
push constant 0
|
|
push local 0
|
|
add
|
|
pop pointer 1
|
|
push that 0
|
|
push constant 0
|
|
gt
|
|
not
|
|
if-goto WHILE_END0
|
|
push constant 0
|
|
push local 0
|
|
add
|
|
pop pointer 1
|
|
push that 0
|
|
pop local 0
|
|
goto WHILE_EXP0
|
|
label WHILE_END0
|
|
push argument 0
|
|
pop local 0
|
|
push constant 0
|
|
return
|