-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.aphid
More file actions
60 lines (60 loc) · 860 Bytes
/
test.aphid
File metadata and controls
60 lines (60 loc) · 860 Bytes
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
; Init i as 10
PUSH 10
STORE i
; Loop until i is 0
PUSH i
PUSH 1
SUB
PRINT
STORE i
PUSH i
PUSH 0
GT
JMP_T -8
; IF-ELSE
PUSH 1
PUSH 2
EQ
; If they are equal continue else jump 2 instructions to PUSH "FALSE"
JMP_F 2
PUSH "TRUE"
PUSH "FALSE"
PRINT
POP
; Example of writing and reading from an IO
PUSH "bob.txt"
PUSH "w"
OPEN
; discard the file size
POP
; store the file handler
STORE open_file
; push our string onto the stack
PUSH 105
PUSH 104
; push the file hander back onto the stack
PUSH open_file
; push how many bytes to write onto the stack
PUSH 2
; write the bytes to the file
WRITE
; discard how many bytes where writted
POP
; push the file back onto the stack
PUSH open_file
; close the file
CLOSE
PUSH "bob.txt"
PUSH "r"
OPEN
STORE file_len
STORE open_file
PUSH open_file
PUSH file_len
READ
STORE read_len
FRAME
PUSH open_file
CLOSE
CLR open_file
HALT