Coder Social home page Coder Social logo

janniknickel / bfkinterpreter Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 8 KB

Code interpreter in x64 assembly for the esoteric language "Brainfuck"

License: MIT License

Shell 10.75% Assembly 89.25%
assembly brainfuck-interpreter interpreter esoteric-language

bfkinterpreter's Introduction

Bfk Interpreter

A brainfuck interpreter written in x64 NASM assembly for Linux.

Build

Either run the build script:

./build.sh to build and link a linux command line application in the 'bin/' directory.

Optionally, pass the --dbg flag to the build script to include debug information.

Or assemble and link the code yourself:

nasm -f elf64 -o bin/bfkint.o interpreter.asm
ld -m elf_x86_64 -o bin/bfkint bin/bfkint.o

Usage

Run ./bin/bfkint file to interpret the brainfuck code in a file.

Alternatively, the ./build_run file script can be used to build the interpreter and then interpret the file.

Input/output works through the interactively through the terminal.

Technical

This interpreter uses 32768 memory cells by default, which can be modified by changing the value of %define CELLS line at the top of the interpreter.asm file. At the beginning, the memory ptr points to cell 0. Negative cells and cells >= 32768 are not allowed and will most likely result in a crash of the interpreter or undefined behaviour.

Each cell has a size of 1 unsigned byte. Values wrap around when decrementing 0 or incrementing 255.

The program ends when the interpreter reaches the end of the code file. There is no output when this happens and the program ends with exit code 0.

The interpreter detects and outputs the following errors:

  • Invalid cmd argument(s)
  • Code file doesnt exist or could not be opened
  • '[' or ']' mismatch

Only the 8 brainfuck instruction characters '>', '<', '+', '-', '.', ',', '[', ']' are interpreted, everything else counts as comment.

Examples

The examples/ directory contains some basic example scripts to test the interpreter. Attributions to the original authors are inside each file if required.

License

The code is released under the MIT license. See LICENSE. See the section above for license information for the examples.

Brainfuck

A brainfuck program consists of 8 instructions and can access an array of at least 30000 memory cells which usually hold 8 bit and move a pointer to a cell in memory.

Instruction Description
> Move the ptr right
< Move the ptr left
+ Increment the memory cell at the ptr
- Decrement the memory cell at the ptr
. Output the memory cell at the ptr as character
, Input a character and save it in the memory cell at the ptr
[ If the cell at the ptr is 0, jump past the matching ]
] If the cell at the ptr is not 0, jump to the matching [

bfkinterpreter's People

Contributors

janniknickel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.