From 9c0cb1d1c32724fc95ac9548e4f8d873d3adaccc Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Tue, 16 Aug 2022 11:53:39 +0800 Subject: nand2tetris software suite --- tools/OS/Sys.vm | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tools/OS/Sys.vm (limited to 'tools/OS/Sys.vm') diff --git a/tools/OS/Sys.vm b/tools/OS/Sys.vm new file mode 100644 index 0000000..c186dad --- /dev/null +++ b/tools/OS/Sys.vm @@ -0,0 +1,83 @@ +function Sys.init 0 +call Memory.init 0 +pop temp 0 +call Math.init 0 +pop temp 0 +call Screen.init 0 +pop temp 0 +call Output.init 0 +pop temp 0 +call Keyboard.init 0 +pop temp 0 +call Main.main 0 +pop temp 0 +call Sys.halt 0 +pop temp 0 +push constant 0 +return +function Sys.halt 0 +label WHILE_EXP0 +push constant 0 +not +not +if-goto WHILE_END0 +goto WHILE_EXP0 +label WHILE_END0 +push constant 0 +return +function Sys.wait 1 +push argument 0 +push constant 0 +lt +if-goto IF_TRUE0 +goto IF_FALSE0 +label IF_TRUE0 +push constant 1 +call Sys.error 1 +pop temp 0 +label IF_FALSE0 +label WHILE_EXP0 +push argument 0 +push constant 0 +gt +not +if-goto WHILE_END0 +push constant 50 +pop local 0 +label WHILE_EXP1 +push local 0 +push constant 0 +gt +not +if-goto WHILE_END1 +push local 0 +push constant 1 +sub +pop local 0 +goto WHILE_EXP1 +label WHILE_END1 +push argument 0 +push constant 1 +sub +pop argument 0 +goto WHILE_EXP0 +label WHILE_END0 +push constant 0 +return +function Sys.error 0 +push constant 69 +call Output.printChar 1 +pop temp 0 +push constant 82 +call Output.printChar 1 +pop temp 0 +push constant 82 +call Output.printChar 1 +pop temp 0 +push argument 0 +call Output.printInt 1 +pop temp 0 +call Sys.halt 0 +pop temp 0 +push constant 0 +return -- cgit v1.2.3