summaryrefslogtreecommitdiff
path: root/projects/11/ConvertToBin/Main.vm
diff options
context:
space:
mode:
Diffstat (limited to 'projects/11/ConvertToBin/Main.vm')
-rw-r--r--projects/11/ConvertToBin/Main.vm110
1 files changed, 110 insertions, 0 deletions
diff --git a/projects/11/ConvertToBin/Main.vm b/projects/11/ConvertToBin/Main.vm
new file mode 100644
index 0000000..15d63c0
--- /dev/null
+++ b/projects/11/ConvertToBin/Main.vm
@@ -0,0 +1,110 @@
+function Main.main 1
+push constant 8000
+push constant 3827
+call Memory.poke 2
+pop temp 0
+push constant 8001
+push constant 16
+push constant 1
+neg
+call Main.fillMemory 3
+pop temp 0
+push constant 8000
+call Memory.peek 1
+pop local 0
+push local 0
+call Main.convert 1
+pop temp 0
+push constant 0
+return
+function Main.convert 3
+push constant 1
+neg
+pop local 2
+label convert.While0
+push local 2
+not
+if-goto convert.EndWhile0
+push local 1
+push constant 1
+add
+pop local 1
+push local 0
+call Main.nextMask 1
+pop local 0
+push local 1
+push constant 16
+gt
+not
+not
+if-goto convert.While0.Else0
+push argument 0
+push local 0
+and
+push constant 0
+eq
+not
+not
+if-goto convert.While0.Else0.Else0
+push constant 8000
+push local 1
+add
+push constant 1
+call Memory.poke 2
+pop temp 0
+goto convert.While0.Else0.Endif0
+label convert.While0.Else0.Else0
+push constant 8000
+push local 1
+add
+push constant 0
+call Memory.poke 2
+pop temp 0
+label convert.While0.Else0.Endif0
+goto convert.While0.Endif0
+label convert.While0.Else0
+push constant 0
+pop local 2
+label convert.While0.Endif0
+goto convert.While0
+label convert.EndWhile0
+push constant 0
+return
+function Main.nextMask 0
+push argument 0
+push constant 0
+eq
+not
+if-goto nextMask.Else0
+push constant 1
+return
+goto nextMask.Endif0
+label nextMask.Else0
+push argument 0
+push constant 2
+call Math.multiply 2
+return
+label nextMask.Endif0
+function Main.fillMemory 0
+label fillMemory.While0
+push argument 1
+push constant 0
+gt
+not
+if-goto fillMemory.EndWhile0
+push argument 0
+push argument 2
+call Memory.poke 2
+pop temp 0
+push argument 1
+push constant 1
+sub
+pop argument 1
+push argument 0
+push constant 1
+add
+pop argument 0
+goto fillMemory.While0
+label fillMemory.EndWhile0
+push constant 0
+return