mirror of
https://github.com/usatiuk/nand2tetris.git
synced 2025-10-29 00:27:49 +01:00
251 lines
3.4 KiB
Plaintext
251 lines
3.4 KiB
Plaintext
function String.new 0
|
|
push constant 2
|
|
call Memory.alloc 1
|
|
pop pointer 0
|
|
push argument 0
|
|
push constant 0
|
|
gt
|
|
if-goto IF_TRUE0
|
|
goto IF_FALSE0
|
|
label IF_TRUE0
|
|
push argument 0
|
|
call Array.new 1
|
|
pop this 0
|
|
goto IF_END0
|
|
label IF_FALSE0
|
|
push constant 0
|
|
pop this 0
|
|
label IF_END0
|
|
push constant 0
|
|
pop this 1
|
|
push pointer 0
|
|
return
|
|
function String.dispose 0
|
|
push argument 0
|
|
pop pointer 0
|
|
push pointer 0
|
|
call Memory.deAlloc 1
|
|
pop temp 0
|
|
push constant 0
|
|
return
|
|
function String.length 0
|
|
push argument 0
|
|
pop pointer 0
|
|
push this 1
|
|
return
|
|
function String.charAt 0
|
|
push argument 0
|
|
pop pointer 0
|
|
push argument 1
|
|
push this 0
|
|
add
|
|
pop pointer 1
|
|
push that 0
|
|
return
|
|
function String.setCharAt 0
|
|
push argument 0
|
|
pop pointer 0
|
|
push argument 1
|
|
push this 0
|
|
add
|
|
push argument 2
|
|
pop temp 0
|
|
pop pointer 1
|
|
push temp 0
|
|
pop that 0
|
|
push constant 0
|
|
return
|
|
function String.appendChar 0
|
|
push argument 0
|
|
pop pointer 0
|
|
push this 1
|
|
push this 0
|
|
add
|
|
push argument 1
|
|
pop temp 0
|
|
pop pointer 1
|
|
push temp 0
|
|
pop that 0
|
|
push this 1
|
|
push constant 1
|
|
add
|
|
pop this 1
|
|
push pointer 0
|
|
return
|
|
function String.eraseLastChar 0
|
|
push argument 0
|
|
pop pointer 0
|
|
push this 1
|
|
push constant 1
|
|
sub
|
|
push this 0
|
|
add
|
|
push constant 0
|
|
pop temp 0
|
|
pop pointer 1
|
|
push temp 0
|
|
pop that 0
|
|
push this 1
|
|
push constant 1
|
|
sub
|
|
pop this 1
|
|
push constant 0
|
|
return
|
|
function String.intValue 4
|
|
push argument 0
|
|
pop pointer 0
|
|
push constant 0
|
|
pop local 1
|
|
push local 1
|
|
push this 0
|
|
add
|
|
pop pointer 1
|
|
push that 0
|
|
push constant 45
|
|
eq
|
|
if-goto IF_TRUE0
|
|
goto IF_FALSE0
|
|
label IF_TRUE0
|
|
push constant 0
|
|
not
|
|
pop local 3
|
|
push constant 1
|
|
pop local 1
|
|
label IF_FALSE0
|
|
label WHILE_EXP0
|
|
push local 1
|
|
push this 1
|
|
lt
|
|
not
|
|
if-goto WHILE_END0
|
|
push local 1
|
|
push this 0
|
|
add
|
|
pop pointer 1
|
|
push that 0
|
|
push constant 48
|
|
sub
|
|
pop local 2
|
|
push local 0
|
|
push constant 10
|
|
call Math.multiply 2
|
|
push local 2
|
|
add
|
|
pop local 0
|
|
push local 1
|
|
push constant 1
|
|
add
|
|
pop local 1
|
|
goto WHILE_EXP0
|
|
label WHILE_END0
|
|
push local 3
|
|
if-goto IF_TRUE1
|
|
goto IF_FALSE1
|
|
label IF_TRUE1
|
|
push local 0
|
|
neg
|
|
return
|
|
label IF_FALSE1
|
|
push local 0
|
|
return
|
|
function String.int2String 3
|
|
push constant 64
|
|
call String.new 1
|
|
pop local 0
|
|
push argument 0
|
|
push argument 0
|
|
push constant 10
|
|
call Math.divide 2
|
|
push constant 10
|
|
call Math.multiply 2
|
|
sub
|
|
pop local 1
|
|
push local 1
|
|
push constant 48
|
|
add
|
|
pop local 2
|
|
push argument 0
|
|
push constant 10
|
|
lt
|
|
if-goto IF_TRUE0
|
|
goto IF_FALSE0
|
|
label IF_TRUE0
|
|
push local 0
|
|
push local 2
|
|
call String.appendChar 2
|
|
pop temp 0
|
|
push local 0
|
|
return
|
|
goto IF_END0
|
|
label IF_FALSE0
|
|
push local 0
|
|
call String.dispose 1
|
|
pop temp 0
|
|
push argument 0
|
|
push constant 10
|
|
call Math.divide 2
|
|
call String.int2String 1
|
|
pop local 0
|
|
push local 0
|
|
push local 2
|
|
call String.appendChar 2
|
|
pop temp 0
|
|
push local 0
|
|
return
|
|
label IF_END0
|
|
function String.setInt 2
|
|
push argument 0
|
|
pop pointer 0
|
|
push constant 0
|
|
pop this 1
|
|
push argument 1
|
|
push constant 0
|
|
lt
|
|
if-goto IF_TRUE0
|
|
goto IF_FALSE0
|
|
label IF_TRUE0
|
|
push pointer 0
|
|
push constant 45
|
|
call String.appendChar 2
|
|
pop temp 0
|
|
label IF_FALSE0
|
|
push constant 0
|
|
pop local 1
|
|
push argument 1
|
|
call Math.abs 1
|
|
call String.int2String 1
|
|
pop local 0
|
|
label WHILE_EXP0
|
|
push local 1
|
|
push local 0
|
|
call String.length 1
|
|
lt
|
|
not
|
|
if-goto WHILE_END0
|
|
push pointer 0
|
|
push local 0
|
|
push local 1
|
|
call String.charAt 2
|
|
call String.appendChar 2
|
|
pop temp 0
|
|
push local 1
|
|
push constant 1
|
|
add
|
|
pop local 1
|
|
goto WHILE_EXP0
|
|
label WHILE_END0
|
|
push local 0
|
|
call String.dispose 1
|
|
pop temp 0
|
|
push constant 0
|
|
return
|
|
function String.newLine 0
|
|
push constant 128
|
|
return
|
|
function String.backSpace 0
|
|
push constant 129
|
|
return
|
|
function String.doubleQuote 0
|
|
push constant 34
|
|
return
|