Compare commits
3 Commits
d59a5c8b39
...
main
Author | SHA1 | Date | |
---|---|---|---|
1ba6765c85 | |||
ceb84c9e3d | |||
15311ca7d1 |
9
helper.s
9
helper.s
@@ -18,14 +18,13 @@ clear_heap_block_loop:
|
|||||||
mov byte ptr [rdi+rcx], 0
|
mov byte ptr [rdi+rcx], 0
|
||||||
inc rcx
|
inc rcx
|
||||||
cmp rcx, rsi
|
cmp rcx, rsi
|
||||||
jle clear_heap_block_loop
|
jl clear_heap_block_loop
|
||||||
ret
|
ret
|
||||||
|
|
||||||
# rdi = size in octets
|
# rdi = size in octets
|
||||||
brk_alloc:
|
brk_alloc:
|
||||||
push rbx
|
push rbx
|
||||||
push r12
|
push r12
|
||||||
inc rdi # so you get all of the requested space
|
|
||||||
mov rbx, rdi
|
mov rbx, rdi
|
||||||
|
|
||||||
mov rax, 12
|
mov rax, 12
|
||||||
@@ -65,6 +64,7 @@ read:
|
|||||||
# rsi = char*
|
# rsi = char*
|
||||||
write:
|
write:
|
||||||
push r15
|
push r15
|
||||||
|
push r11
|
||||||
mov r15, rdi
|
mov r15, rdi
|
||||||
mov rdi, rsi # no need to touch rsi
|
mov rdi, rsi # no need to touch rsi
|
||||||
call count
|
call count
|
||||||
@@ -74,6 +74,7 @@ write:
|
|||||||
mov rdi, r15
|
mov rdi, r15
|
||||||
|
|
||||||
syscall
|
syscall
|
||||||
|
pop r11
|
||||||
pop r15
|
pop r15
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@@ -81,9 +82,9 @@ write:
|
|||||||
count:
|
count:
|
||||||
mov rax, rdi
|
mov rax, rdi
|
||||||
count_loop:
|
count_loop:
|
||||||
mov r8b, [rax]
|
mov r9b, [rax]
|
||||||
inc rax
|
inc rax
|
||||||
cmp r8b, 0
|
cmp r9b, 0
|
||||||
jnz count_loop
|
jnz count_loop
|
||||||
dec rax
|
dec rax
|
||||||
sub rax, rdi
|
sub rax, rdi
|
||||||
|
27
main.s
27
main.s
@@ -165,9 +165,22 @@ process_prnt:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
process_inpt:
|
process_inpt:
|
||||||
|
# Gotta flush the buffer first
|
||||||
|
mov rdi, 1
|
||||||
|
mov rsi, r13
|
||||||
|
call write
|
||||||
|
|
||||||
|
# Clear Text buffer
|
||||||
|
mov rdi, r10
|
||||||
|
sub rdi, r13
|
||||||
|
mov rsi, rdi
|
||||||
|
mov rdi, r13
|
||||||
|
call clear_heap_block
|
||||||
|
mov r10, r13
|
||||||
|
|
||||||
|
# Ask character
|
||||||
mov rdi, r14
|
mov rdi, r14
|
||||||
add rdi, r15
|
add rdi, r15
|
||||||
|
|
||||||
mov rsi, rdi # char*
|
mov rsi, rdi # char*
|
||||||
xor rdi, rdi # fd
|
xor rdi, rdi # fd
|
||||||
mov rdx, 1 # size
|
mov rdx, 1 # size
|
||||||
@@ -176,32 +189,24 @@ process_inpt:
|
|||||||
|
|
||||||
# In stack it is
|
# In stack it is
|
||||||
# A = Address to loop back
|
# A = Address to loop back
|
||||||
# C = Cell to check
|
|
||||||
# AC AC AC AC AC AC AC <- pop here
|
|
||||||
process_loop_start:
|
process_loop_start:
|
||||||
pop rdi
|
pop rdi
|
||||||
push r11 # Address to loopback
|
push r11 # Address to loopback
|
||||||
push r15 # Cell to check
|
|
||||||
push rdi
|
push rdi
|
||||||
ret
|
ret
|
||||||
|
|
||||||
process_loop_end:
|
process_loop_end:
|
||||||
# Gotta get ret value
|
# Gotta get ret value
|
||||||
pop rsi
|
pop rsi
|
||||||
pop rdi # Cell
|
|
||||||
pop rax # Address
|
pop rax # Address
|
||||||
|
|
||||||
# if cell is 0 we are done with loop
|
# if cell is 0 we are done with loop
|
||||||
cmp byte ptr [r14+rdi], 0
|
cmp byte ptr [r14+r15], 0
|
||||||
je 1f
|
je 1f
|
||||||
mov r11, rax
|
mov r11, rax
|
||||||
|
|
||||||
# Make sure stack isn't caught on fire
|
# Make sure stack isn't caught on fire
|
||||||
push rax
|
push rax
|
||||||
push rdi
|
|
||||||
push rsi
|
|
||||||
ret
|
|
||||||
1:
|
1:
|
||||||
push rsi
|
jmp rsi
|
||||||
ret # Discard
|
|
||||||
|
|
||||||
|
2
tests/test1.bf
Normal file
2
tests/test1.bf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>
|
||||||
|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
|
1
tests/test3.bf
Normal file
1
tests/test3.bf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
++++[>++++[>++++<-]<-]>>++.[<<+>>-]<<.
|
1
tests/test4.bf
Normal file
1
tests/test4.bf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
|
1
tests/test5.bf
Normal file
1
tests/test5.bf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
++++++++[>++++++++<-]>+.,+.,,
|
1
welcome.bf
Normal file
1
welcome.bf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
+++++++++[>++++++++>+++++++++++>++++>++++++++++>+++++++++++>++++>+++++++++++<<<<<<<-]>.>++.+++++++..+++.>---.-.>---.>++.<<<---.>>>--.<<<+++.--.>>>++.<<.<+++++++.-----.>.>>--.--.<<<+++++.>>>>+++.<<<<-.>.>>+.<<<-.>>>-.++++++++.+++++.>>+++.<<<<<+++.>>>>>---.<<---.<<.>>--.+++++.<<<-.>>>>>++.<<++++.--.++.>>.<<++.>>.<<--.>+++++.<<<.<+++.>>>.>>++++.<<++..>>----.<<------.<<.>>-----.+++++.<<.<<-------.>>>----.------.<+.>>>>>++++++++++.
|
Reference in New Issue
Block a user