-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyMath.vm
70 lines (70 loc) · 1020 Bytes
/
MyMath.vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function MyMath.mod 0
push argument 0
push argument 1
push argument 0
push argument 1
call Math.divide 2
call Math.multiply 2
sub
return
function MyMath.ceilDiv 2
push argument 0
push argument 1
call Math.divide 2
pop local 0
push argument 0
push argument 1
call MyMath.mod 2
if-goto IF_TRUE_0
goto IF_FALSE_0
label IF_TRUE_0
push local 0
push constant 1
add
return
label IF_FALSE_0
push local 0
return
function MyMath.roundDiv 3
push argument 0
push argument 1
call Math.divide 2
pop local 0
push argument 0
push argument 1
call MyMath.mod 2
push local 0
push constant 2
call Math.divide 2
gt
if-goto IF_TRUE_1
goto IF_FALSE_1
label IF_TRUE_1
push local 0
push constant 1
add
return
label IF_FALSE_1
push local 0
return
function MyMath.pow 1
push constant 1
pop local 0
label WHILE_TOP_0
push argument 1
push constant 0
gt
not
if-goto WHILE_BREAK_0
push local 0
push argument 0
call Math.multiply 2
pop local 0
push argument 1
push constant 1
sub
pop argument 1
goto WHILE_TOP_0
label WHILE_BREAK_0
push local 0
return