jmp no call

opt
Szymon Karpiński 6 years ago
parent d2a35c5b0e
commit 447ec62300
  1. 33
      brainfuck.asm

@ -43,11 +43,11 @@ bf_instructions:
xor rdi, rdi
call exit
align 8
times 8*('+'-1) ret
times 8*('+'-1) hlt
bf_increment: ; '+' ascii 43
inc byte [rdi]
inc rsi
ret
jmp rbx
align 8
bf_in_stub: ; ',' ascii 44
jmp bf_in
@ -55,29 +55,28 @@ bf_instructions:
bf_decr: ; '-' ascii 45
dec byte [rdi]
inc rsi
ret
jmp rbx
align 8
bf_out_stub: ; '.' ascii 46
jmp bf_out
ret
align 8
times 8*('<'-'.'-1) ret
times 8*('<'-'.'-1) hlt
bf_left: ; '<' ascii 60
dec rdi
inc rsi
ret
jmp rbx
align 8
times 8*('>'-'<'-1) ret
times 8*('>'-'<'-1) hlt
bf_right: ; '>' ascii 62
inc rdi
inc rsi
ret
jmp rbx
align 8
times 8*('['-'>'-1) ret
times 8*('['-'>'-1) hlt
bf_forward_stub: ; '[' ascii 91
jmp bf_forward
align 8
times 8*(']'-'['-1) ret
times 8*(']'-'['-1) hlt
bf_backward_stub: ; ']' ascii 93
jmp bf_backward
align 8
@ -88,7 +87,7 @@ bf_instructions:
jmp bf_jump
bf_forward_end:
inc rsi
ret
jmp rbx
bf_backward:
cmp byte [rdi], 0
@ -96,13 +95,13 @@ bf_instructions:
jmp bf_jump
bf_backward_end:
inc rsi
ret
jmp rbx
bf_jump:
sub rsi, bf_program
mov rsi, [8*rsi + bf_jumps]
inc rsi
ret
jmp rbx
bf_out:
push rdi
@ -114,7 +113,7 @@ bf_instructions:
pop rsi
pop rdi
inc rsi
ret
jmp rbx
bf_in:
push rdi
@ -124,7 +123,7 @@ bf_instructions:
pop rdi
mov byte [rdi], al
inc rsi
ret
jmp rbx
main:
@ -159,11 +158,11 @@ _jump_loop:
lea rsi, [bf_program]
lea rdi, [bf_tape]
lea rbx, [_program_loop]
_program_loop:
movzx rax, byte [rsi]
lea rax, [bf_instructions + 8*rax]
call rax
jmp _program_loop
jmp rax
xor rdi, rdi
call exit

Loading…
Cancel
Save