Files
nand2tetris/projects/12/OutputTest/Keyboard.vm
2021-04-21 17:01:42 +03:00

99 lines
1.4 KiB
Plaintext

function Keyboard.init 0
push constant 24576
pop static 0
push constant 0
return
function Keyboard.keyPressed 0
push constant 0
push static 0
add
pop pointer 1
push that 0
return
function Keyboard.readChar 1
label WHILE_EXP0
push constant 0
push static 0
add
pop pointer 1
push that 0
push constant 0
eq
not
if-goto WHILE_END0
goto WHILE_EXP0
label WHILE_END0
push constant 0
push static 0
add
pop pointer 1
push that 0
pop local 0
push local 0
call Output.printChar 1
pop temp 0
label WHILE_EXP1
push constant 0
push static 0
add
pop pointer 1
push that 0
push local 0
eq
not
if-goto WHILE_END1
goto WHILE_EXP1
label WHILE_END1
push local 0
return
function Keyboard.readLine 2
push constant 32
call String.new 1
pop local 0
push argument 0
call Output.printString 1
pop temp 0
label WHILE_EXP0
push constant 0
not
not
if-goto WHILE_END0
call Keyboard.readChar 0
pop local 1
push local 1
push constant 128
eq
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push local 0
return
label IF_FALSE0
push local 1
push constant 129
eq
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push local 0
call String.eraseLastChar 1
pop temp 0
goto IF_END1
label IF_FALSE1
push local 0
push local 1
call String.appendChar 2
pop local 0
label IF_END1
goto WHILE_EXP0
label WHILE_END0
push local 0
return
function Keyboard.readInt 1
push argument 0
call Keyboard.readLine 1
pop local 0
push local 0
call String.intValue 1
return