-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.s
More file actions
executable file
·129 lines (99 loc) · 1.57 KB
/
main.s
File metadata and controls
executable file
·129 lines (99 loc) · 1.57 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
.data
memory: .skip 10000
.global _start
_start:
movq 16(%rsp), %rsi
#opens file for reading
movq $2, %rax
movq %rsi, %rdi
movq $0, %rsi
movq $0666, %rdx
syscall
#reads 5000 chars max, puts them in buffer
movq %rax, %rdi
movq $0, %rax
movq $file_buffer, %rsi
movq $5000, %rdx
syscall
#closes file
movq $3, %rax
syscall
#r8 is stack pointer for brainfuck
#r9 has the value for our little cutie pi memory of char
movq $memory, %r8
movq $file_buffer, %r9
begin_interpret:
movb (%r9), %bl
incq %r9
cmpb $43, %bl #+
je plus
cmpb $45, %bl #-
je minus
cmpb $62, %bl #>
je right
cmpb $60, %bl #<
je left
cmpb $46, %bl #.
je out
cmpb $91, %bl #[
je start_loop
cmpb $93, %bl #]
je end_loop
cmpb $44, %bl
je input
cmpb $0, %bl
je exit
jmp begin_interpret
exit:
movq $0, %rdi
movq $60, %rax
syscall
plus:
incb (%r8)
jmp begin_interpret
minus:
decb (%r8)
jmp begin_interpret
right:
incq %r8
jmp begin_interpret
left:
decq %r8
jmp begin_interpret
out:
#output char in r8
movq $1, %rax
movq $1, %rdx
movq $1, %rdi
movq %r8, %rsi
syscall
jmp begin_interpret
start_loop:
cmpb $0, (%r8)
jne begin_interpret
loop_start_loop:
movb (%r9), %bl
incq %r9
cmpb $93, %bl
je begin_interpret
jmp loop_start_loop
end_loop:
cmpb $0, (%r8)
je begin_interpret
loop_end_loop:
decq %r9
movb (%r9), %bl
cmpb $91,%bl
jne loop_end_loop
incq %r9
jmp begin_interpret
input:
#reads 1 char max, puts them in (%r8)
movq $0, %rdi
movq $0, %rax
movq %r8, %rsi
movq $1, %rdx
syscall
jmp begin_interpret
.bss
.lcomm file_buffer, 10000