Code Monkey home page Code Monkey logo

asm_bf's Introduction

Assembler to Brainfuck translator

Running:

cat input.asm | ruby asm_bf.rb > out.bf

Supported:

  • Registers
  • Stack(like C-string, can't store 0)
  • Strings and arrays

Basic types:

  • Registers:
mov ax 5 // ax = 5
mov bx 6 // bx = 6
sub ax bx // ax = 5 - 6 (mod 256) = 255

mov cx 12
mov dx 2 
mul cx dx // cx = 12 * 2 = 24

mov dx 10
div cx dx // division with remainder:  cx = 24 \ 10 = 2, dx = 24 % 10 = 4
  • Stack:
mov ax 1
push ax
push 5
pop bx
pop cx // bx = 5, cx = 1 now

push 0 // wrong! undefined behaviour
  • Arrays:
array test 10 // like C's : unsigned char test[10];
set test 0 42 // test[0] = 42
get test 0 ax // ax = test[0]

Also, register can be index of array, but then you can access only first 256 elements.

  • Strings:
string hello "Hello, World!" // like C's: unsigned char hello[] = "Hello, World!";
puts hello // print string

Strings are arrays too:

get hello 0 ax // ax = 'H'
put ax // prints 'H'

Basic operations:

  • IO:
take ax // like C's: ax = getchar();
put ax // prints char in 'ax'
puts str // prints string in str variable
  • Loop:
while ax // in while used one of registers
	// do smth.
endwhile
  • Comparing:
mov ax 2
mov bx 1
cmp ax bx // compare, and now:

ne // not equal
    // actions in case registers are not equal
end

nl // not less
    // actions
end

ng // not greater
    // actions
end

eq // equal
    // actions
end

lt // less
    // actions
end

gt // greater
    // actions
end

asm_bf's People

Contributors

alhimik45 avatar

Watchers

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