Bf core

From Esolang
Jump to: navigation, search
bf core
Paradigm(s) imperative
Designed by Total Vacuum
Appeared in 2016
Memory system cell-based
Computational class Turing complete
Major implementations bf core[1]
File extension(s) .b


wtf?

brainfuck!

intro

bf core is extremely optimized by size (69 bytes) brainfuck core implementation written in x86 asm. Coded by Total Vacuum in 2016.

goal

The goal is to create as compact as possible brainfuck core implementation for simple brainfuck to dos/winxp executable .com file compiler. Output file format:

  • core (69 bytes for current version)
  • code (passed through comment and whitespace remover)
  • space (ascii 0x20, 1 byte)

You can freely use this core in your brainfuck compiler to produce dos/winxp executable .com files, or you can generate .com file even without compiler using

copy bfcore.com+src.b dest.com 

where bfcore.com is previously compiled bf core, src.b is brainfuck source (strip comments and whitespaces first!), dest.com is destination .com file.

The next goal is to trim core size to 64 bytes. Is it possible? All ideas on core size trimming are welcome! :)

specification

  • 8-bit cells
  • 510 memory cells (+2 bytes for 30000 cells)
  • max code size is 32K
  • the only available characters are [ ] < > + - , .
  • one extra terminating space character (ascii 0x20) required (for correct program termination)
  • no newline character conversions on i/o
  • incorrect i/o when redirecting from/to file (+3 bytes to fix)
  • up to 255 nested [ ] blocks

src

         |         .model tiny       ;
         |         .code             ;
         |         .startup          ;
BE 45 01 |         lea si,@src       ;
D1 EF    |         shr di,1          ;
F3 AB    |         rep stosw         ;
4F       |         dec di            ;
2B F8    | @move:  sub di,ax         ; </>
3D       |         db 3Dh            ;
28 05    | @add:   sub [di],al       ; +/-
AC       | @next:  lodsb             ;
98       |         cbw               ;
2C 5B    |         sub al,'['        ;
E3 07    |         jcxz @true        ;
7C F8    |         jl @next          ;
48       | @inccx: dec ax            ; [/]
2A C8    |         sub cl,al         ;
EB F3    |         jmp @next         ;
7C 0C    | @true:  jl @ptr           ;
7F 06    |         jg @end           ;
3A 05    |         cmp al,[di]       ; [
74 F3    |         je @inccx         ;
56       |         push si           ;
3D       |         db 3Dh            ;
5E       | @end:   pop si            ; ]
4E       |         dec si            ;
EB E5    |         jmp @next         ;
2C E1    | @ptr:   sub al,'<'-'['    ;
48       |         dec ax            ;
73 DB    |         jnc @move         ;
2C EE    | @last:  sub al,'+'-'<'-1  ; +/,/-/.
3C 03    |         cmp al,3          ;
74 08    |         je @putc          ;
73 0A    |         jnc @exit         ;
48       |         dec ax            ;
75 D3    |         jnz @add          ;
B4 08    | @getc:  mov ah,8          ; ,
3D       |         db 3Dh            ;
B4 02    | @putc:  mov ah,2          ; .
8A 15    |         mov dl,[di]       ;
CD 21    | @exit:  int 21h           ;
88 05    |         mov [di],al       ;
EB C8    |         jmp @next         ;
         | @src:  ;db "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++. ";Hello World!
         |         end               ;

compilation

Compile with:

tasm.exe /m9
tlink.exe /t /x

sorry

Sorry for my English :)