Brainf*ck interpreter

  • HuntaBadday
    12th May 2020 Member 1 Permalink

    mov r10, 0
    mov r11, code
    mov r12, data
    mov r2, data
    mov r0, r2
    mov r3, 0
    add r0, 255
    bump r10
    send r10, 0x1000
    send r10, 0x200a
    jmp checkCode

    code:
    ; This does not support loop nesting
    dw "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."
    dw 0

    checkCode:
    mov r1, [r11]
    cmp r1, '>'
    je right
    cmp r1, '<'
    je left
    cmp r1, '+'
    je plus
    cmp r1, '-'
    je subt
    cmp r1, '.'
    je out
    cmp r1, ','
    je input
    cmp r1, '['
    je while
    cmp r1, ']'
    je check
    cmp r1, 0
    jz hltt
    add r11, 1
    jmp checkCode


    right:
    cmp r0, r12
    jne .skip
    sub r12, 256
    .skip:
    add r12, 1
    add r11, 1
    mov r1, [r11]
    cmp r1, '>'
    je right
    jmp checkCode

    left:
    cmp r12, r2
    jne .skip
    add r12, 256
    .skip:
    sub r12, 1
    add r11, 1
    mov r1, [r11]
    cmp r1, '<'
    je left
    jmp checkCode

    plus:
    mov r1, [r12]
    add r1, 1
    mov [r12], r1
    add r11, 1
    mov r1, [r11]
    cmp r1, '+'
    je plus
    jmp checkCode

    subt:
    mov r1, [r12]
    sub r1, 1
    mov [r12], r1
    add r11, 1
    mov r1, [r11]
    cmp r1, '-'
    je subt
    jmp checkCode

    out:
    mov r1, [r12]
    add r1, r3
    send r10, r1
    add r11, 1
    mov r1, [r11]
    cmp r1, '.'
    je out
    jmp checkCode

    input:
    wait r10
    js input
    bump r10
    .loop:
    recv r1, r10
    jnc .loop
    sub r1, r3
    mov [r12], r1
    add r11, 1
    mov r1, [r11]
    cmp r1, ','
    je input
    jmp checkCode

    while:
    mov r1, [r12]
    cmp r1, 0
    je .loop
    add r11, 1
    push r11
    jmp checkCode
    .loop:
    add r11, 1
    mov r1, [r11]
    .back:
    cmp r1, ']'
    jne .loop
    add r11, 1
    jmp checkCode

    check:
    mov r1, [r12]
    cmp r1, 0
    je .check
    mov r11, [sp]
    jmp checkCode
    .check:
    pop r1
    add r11, 1
    jmp checkCode

    hltt:
    hlt
    jmp hltt

    data:
    dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
    ; 256 address space

     

    Here is the assembly file to download:

    https://github.com/HuntaBadday/r216-Brainfuck-interpreter

  • LBPHacker
    12th May 2020 Developer 0 Permalink
    But can it beat mine? Also, please just link to the repo instead, your post is an eyesore >_> EDIT: your repo link is broken, I think your repo is private.
    Edited 2 times by LBPHacker. Last: 12th May 2020
  • coolstuf
    12th May 2020 Member 0 Permalink

    wow, keep it clean lol(link)