Skip to content

nli33/sbf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sbf

A Brainfuck interpreter that lets programs perform OS syscalls via a custom instruction, hopefully portable across architectures

Syscall Instruction

When syscall instruction (!) occurs with the cell pointer at cell n:

Cell [n, n+3] Cell n+4 Cell n+5 Cell [n+6, n+14] ...
syscall number argc arg1 type arg1 ...
  • Syscall number takes 4 cells (32-bit integer)
  • Each argument takes 8 cells (64-bit), the size of a register on 64-bit architecture
  • Arg types:
    • 0 (integer)
    • 1 (pointer)
  • Pointers should be given as an offset relative to the beginning of the tape. The interpreter will translate the relative address to a real pointer
  • All arguments are little-endian

Example

The test program prints "hello\n" twice: first via normal Brainfuck instructions, then via a write syscall. Then, it exits via an exit syscall with exit code 67.

Replace test_prog with the file name corresponding to your platform (e.g. test_prog_macos-arm64).

$ cargo run test_prog
hello
hello
$ echo $?
67

To-Do

  • Create a compiler for a higher-level language that compiles into this Brainfuck dialect (thus creating the Brainfuck Virtual Machine?)

About

A brainfuck interpreter that supports syscalls

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages