Last active
January 26, 2018 00:48
-
-
Save axic/442a6ec7d16cd0cf1228fd1328b584df to your computer and use it in GitHub Desktop.
"Hello World" in Brainf* compiled to eWASM using https://github.com/axic/bf-compiler-webassembly/tree/ewasm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; "Hello World" in Brainf* compiled to eWASM using https://github.com/axic/bf-compiler-webassembly/tree/ewasm | |
(module | |
(func $callDataCopy (import "ethereum" "callDataCopy") (param i32 i32 i32)) | |
(func $return (import "ethereum" "return") (param i32 i32)) | |
(global $writeptr (mut i32) (i32.const 1)) | |
(global $readptr (mut i32) (i32.const 0)) | |
(func $getchar | |
(result i32) | |
(call $callDataCopy (get_global $readptr) (i32.const 0) (i32.const 1)) | |
(set_global $readptr (i32.add (get_global $readptr) (i32.const 1))) | |
(i32.load8_u (i32.const 0)) | |
) | |
(func $putchar | |
(param $value i32) | |
(i32.store8 (get_global $writeptr) (get_local $value)) | |
(set_global $writeptr (i32.add (get_global $writeptr) (i32.const 1))) | |
;; verify we do not overwrite 256 bytes here.. | |
) | |
(memory $0 (export "memory") 1 1) | |
(func (export "main") (local $ptr i32) (set_local $ptr (i32.const 257)) | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(block ;; [ | |
(loop | |
(br_if 1 (i32.eqz (i32.load8_s (get_local $ptr)))) | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(br 0) | |
) | |
) ;; ] | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(block ;; [ | |
(loop | |
(br_if 1 (i32.eqz (i32.load8_s (get_local $ptr)))) | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(br 0) | |
) | |
) ;; ] | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(block ;; [ | |
(loop | |
(br_if 1 (i32.eqz (i32.load8_s (get_local $ptr)))) | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(br 0) | |
) | |
) ;; ] | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(block ;; [ | |
(loop | |
(br_if 1 (i32.eqz (i32.load8_s (get_local $ptr)))) | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(br 0) | |
) | |
) ;; ] | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(block ;; [ | |
(loop | |
(br_if 1 (i32.eqz (i32.load8_s (get_local $ptr)))) | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(br 0) | |
) | |
) ;; ] | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(block ;; [ | |
(loop | |
(br_if 1 (i32.eqz (i32.load8_s (get_local $ptr)))) | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(br 0) | |
) | |
) ;; ] | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(block ;; [ | |
(loop | |
(br_if 1 (i32.eqz (i32.load8_s (get_local $ptr)))) | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(br 0) | |
) | |
) ;; ] | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(block ;; [ | |
(loop | |
(br_if 1 (i32.eqz (i32.load8_s (get_local $ptr)))) | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(set_local $ptr (i32.add (get_local $ptr) (i32.const 1))) ;; > | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(br 0) | |
) | |
) ;; ] | |
(set_local $ptr (i32.sub (get_local $ptr) (i32.const 1))) ;; < | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(block ;; [ | |
(loop | |
(br_if 1 (i32.eqz (i32.load8_s (get_local $ptr)))) | |
(i32.store8 (get_local $ptr) (i32.sub (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; - | |
(br 0) | |
) | |
) ;; ] | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.store8 (get_local $ptr) (i32.add (i32.load8_s (get_local $ptr)) (i32.const 1))) ;; + | |
(i32.load8_s (get_local $ptr)) (call $putchar) ;; . | |
(call $return (i32.const 1) (i32.sub (get_global $writeptr) (i32.const 1))) | |
) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment