Skip to content

alhimik45/asm_bf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Languages