diff options
author | Damien George <damien.p.george@gmail.com> | 2014-05-07 18:31:14 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-05-07 18:31:14 +0100 |
commit | c4ccb078a52276fc95e407602676f14d34a3f3c1 (patch) | |
tree | 9946cf21553162a0d2dd9a4d48768397d5f71741 /tests/inlineasm | |
parent | a32c1e41cc28c5f7cd95191918cebd0e447a2fce (diff) | |
download | micropython-c4ccb078a52276fc95e407602676f14d34a3f3c1.tar.gz micropython-c4ccb078a52276fc95e407602676f14d34a3f3c1.zip |
tests: Add inline assembler test for pyboard.
Diffstat (limited to 'tests/inlineasm')
-rw-r--r-- | tests/inlineasm/asmsum.py | 57 | ||||
-rw-r--r-- | tests/inlineasm/asmsum.py.exp | 2 |
2 files changed, 59 insertions, 0 deletions
diff --git a/tests/inlineasm/asmsum.py b/tests/inlineasm/asmsum.py new file mode 100644 index 0000000000..07e71c7384 --- /dev/null +++ b/tests/inlineasm/asmsum.py @@ -0,0 +1,57 @@ +@micropython.asm_thumb +def asm_sum_words(r0, r1): + + # r0 = len + # r1 = ptr + # r2 = sum + # r3 = dummy + mov(r2, 0) + + b(loop_entry) + + label(loop1) + ldr(r3, [r1, 0]) + add(r2, r2, r3) + + add(r1, r1, 4) + sub(r0, r0, 1) + + label(loop_entry) + cmp(r0, 0) + bgt(loop1) + + mov(r0, r2) + +@micropython.asm_thumb +def asm_sum_bytes(r0, r1): + + # r0 = len + # r1 = ptr + # r2 = sum + # r3 = dummy + mov(r2, 0) + + b(loop_entry) + + label(loop1) + ldrb(r3, [r1, 0]) + add(r2, r2, r3) + + add(r1, r1, 1) + sub(r0, r0, 1) + + label(loop_entry) + cmp(r0, 0) + bgt(loop1) + + mov(r0, r2) + +import array + +b = array.array('l', (100, 200, 300, 400)) +n = asm_sum_words(len(b), b) +print(b, n) + +b = array.array('b', (10, 20, 30, 40, 50, 60, 70, 80)) +n = asm_sum_bytes(len(b), b) +print(b, n) diff --git a/tests/inlineasm/asmsum.py.exp b/tests/inlineasm/asmsum.py.exp new file mode 100644 index 0000000000..d50a94c8db --- /dev/null +++ b/tests/inlineasm/asmsum.py.exp @@ -0,0 +1,2 @@ +array('l', [100, 200, 300, 400]) 1000 +array('b', [10, 20, 30, 40, 50, 60, 70, 80]) 360 |