Giter Club home page Giter Club logo

beef's Introduction

================================================================================
BeeF Processor Design Notes
================================================================================
ISA: width: 3 bits (8 instructions)
--> see: https://en.wikipedia.org/wiki/Brainfuck

000[ ^ ]: PSH - push current cell to stack 
001[ + ]: INC - increment data 
010[ - ]: DEC - decrement data
011[ > ]: MVR - move data head right
100[ < ]: MVL - move data head left
101[ [ ]: CBF - if data is 0, skip to matching "]"
110[ ] ]: CBB - if data is not 0, skip to matchin "["
111[ _ ]: POP - pop item from stack, overwriting current cell
================================================================================
Assembling:
- BeeF is a minimal ISA, so the assembler must do extra work to provide
  some basic functionality

*** Basic Building Blocks ***
ADD: current cell and next cell
[->+<]

SUB: current cell and next cell
[->-<]

ZER: zero the current cell
[-]

*** Complex Assembler Constructs ***
- for operations which use the swap register, their functional block must
  restore the register value on completion

INV: invert the current cell
    >^[-]<[->-<]>-^<_>_<

SHR: right-shift cell value by doubling it
    >^[-]<[->++<]>^<_>_<

NOT: logical not of the current cell
    - use the right adjacent cell as scratch space loop condition
    >^[-]^<[ [-]->_+^- ] + >__



IFT BLOCK 1 ELS BLOCK 2 END: if-then-else construct
    - if the current cell is nonzero, then execute BLOCK 1
    - else execute BLOCK 2
    - uses one cell of scratch space, to the left
    1) Store a one on the stack         <^[-]+^>
    2) try loop 1                       [>
      i)  execute BLOCK 1                 BLOCK 1
      ii) pop stored one, store a zero    <<_-^
                                        ]
    3) pop stored value                 _
    4) try loop 2                       [>
      i)  execute BLOCK 2                 BLOCK 2
                                          <<[-]
    5) restore scratch space            ]_>
    
    <^[-]+^>[> 
        BLOCK 1
    <<_-^]_[> 
        BLOCK 2
    <<[-]]_>


SHL: left-shift cell value by halving it
    1) use c-1 as scratch space         <^>
    2) use c+1 as construction site     >^[-]<
    3) loop:                            [
      i)   decrement operand              -
      ii)  copy operand to scratch        ^<_
      iii) check zero in scratch          [>
      iv)  decrement operand                -
      v)   increment result                 >+<
      vi)  break out of conditional         <[-]
                                          ]
      vii) check operand                  >
                                        ]
    4) clean up                         >^<_>_<<_>
    <^>>^[-]<[-^<_[>->+<<[-]]>]>^<_>_<<_>





beef's People

Contributors

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