From 63a2cced4238af7d171e0b8807d887c435b4656b Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Tue, 6 Oct 2020 18:49:05 +0200 Subject: add translation of relational operations and loops --- tests/wasm_compile_loop/instructions.wat | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/wasm_compile_loop/instructions.wat (limited to 'tests/wasm_compile_loop/instructions.wat') diff --git a/tests/wasm_compile_loop/instructions.wat b/tests/wasm_compile_loop/instructions.wat new file mode 100644 index 0000000..02a75e0 --- /dev/null +++ b/tests/wasm_compile_loop/instructions.wat @@ -0,0 +1,25 @@ +(module + (memory 0 2) + (func $main + (local $counter i32) + + ;; prepare offset for store operation later + (i32.const 0x0) + + ;; initialize counter + (set_local $counter (i32.const 0)) + + ;; add numbers from 1 to 10 + (i32.const 0) + (loop $again (param i32) (result i32) + (set_local $counter (i32.add + (get_local $counter) + (i32.const 1))) + (i32.add (get_local $counter)) + (br_if $again (i32.lt_u + (get_local $counter) + (i32.const 10)))) + + ;; write computed sum (55 in dec, 37 in hex) at MEMORY_BOTTOM_ADDR + (i32.store offset=0x0 align=2)) + (export "main" (func $main))) -- cgit v1.2.3