Giter Club home page Giter Club logo

brainfuck-assembly's Introduction

Brainfuck Assembler

A simple assembly language compiling to brainfuck. Just for fun.

Instructions

Every instruction takes the form

MNEMONIC{C} Operand1, Operand2

Where

  • MNEMONIC: the name of the instruction
  • {C}: An optional 'conditional' flag, which indicates that the instruction must only be executed if the last condition operation evaluated to true
  • Operand1: First operand of the instruction, must always be a register name
  • Operand2: Second operand of the instruction. Not all instructions have two operands.

The second operand can be:

  • A register name. Eg R1
  • A constant value (prefixed by the # symbol, eg #3)
  • The memory address stored in a register (register name surrounded by [], eg [R3])

Instruction reference

Generic operations

Instruction Description
MOV Reg, Operand Copies Operand to Reg
ADD Reg, Operand Adds Operand to the value contained in Reg, storing the result in Reg
OUT Reg Prints the content of Reg

Conditions

Instruction Description
GT Reg, Operand Checks if Reg is greater than Operand, storing 1 in CRR if the condition is verified.

Branching

Instruction Description
B Operand Jumps to the instruction referenced by Operand. This can either be a constant or a register

User Registers

User registers are available for use by the users.

Register Description
CRR Condition result register. 1 If the latest contional operation evaluated to true, 0 otherwise.
PC Program Counter, contains the address of the current istruction being executed
R1 General purpose register 1
R2 General purpose register 2
R3 General purpose register 3
R4 General purpose register 4
R5 General purpose register 5

Example

Assembly

    MOV R1, #5   ; Set R1 to 5
loop:
    ADD R2, #1   ; Add 1 to R2
    GT R1, R2    ; R1 > R2?
    BC loop      ; If yes, branch to loop
    OUT R1       ; Print R1
    OUT R2       ; Print R2

Output

++++++
[-[-[-[-[-[-
>
>>>>>>>>[-]<<<<<<<<
>+<[>-]>[>]<
[-
    >>>>>>>>[-]+++++<<<<<<<<
]
+<[>-]>[>]<<->[-<+>]<
<]>
>>>>>>>>[-]+<<<<<<<<
>+<[>-]>[>]<
[-
    >>>>>>>>>+<<<<<<<<<
]
+<[>-]>[>]<<->[-<+>]<
<]>
>>>>>>>>[-]++<<<<<<<<
>+<[>-]>[>]<
[-
    >>>>>>[-]<<<<<<>>>>>>>>
[-<<<+<+>>>>]<<<<[->>>>+<<<<]>>>>>[-<<<<<<+>+>>>>>]<<<<<[->>>>>+<<<<<]>>>>><<<<[-<<<<+>+>>>]<<<[->>>+<<<]>>>
[-<<[<<->]>[>]<->>]<<[+]<<
[->>>>>+<<<<<]
<
]
+<[>-]>[>]<<->[-<+>]<
<]>
>>>>>>>>[-]+++<<<<<<<<
>+<[>-]>[>]<
[-
    >>>>>>[-<<<<<<+>+>>>>>]<<<<<[->>>>>+<<<<<]>>>>><<<<<<[-<<+++>>]
]
+<[>-]>[>]<<->[-<+>]<
<]>
>>>>>>>>[-]++++<<<<<<<<
>+<[>-]>[>]<
[-
    >>>>>>>>.<<<<<<<<
]
+<[>-]>[>]<<->[-<+>]<
<]>
>>>>>>>>[-]+++++<<<<<<<<
>+<[>-]>[>]<
[-
    >>>>>>>>>.<<<<<<<<<
]
+<[>-]>[>]<<->[-<+>]<
<]>

brainfuck-assembly's People

Contributors

hixos 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.