Skip to content

Commit c4ccb07

Browse files
committed
tests: Add inline assembler test for pyboard.
1 parent a32c1e4 commit c4ccb07

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

tests/inlineasm/asmsum.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
@micropython.asm_thumb
2+
def asm_sum_words(r0, r1):
3+
4+
# r0 = len
5+
# r1 = ptr
6+
# r2 = sum
7+
# r3 = dummy
8+
mov(r2, 0)
9+
10+
b(loop_entry)
11+
12+
label(loop1)
13+
ldr(r3, [r1, 0])
14+
add(r2, r2, r3)
15+
16+
add(r1, r1, 4)
17+
sub(r0, r0, 1)
18+
19+
label(loop_entry)
20+
cmp(r0, 0)
21+
bgt(loop1)
22+
23+
mov(r0, r2)
24+
25+
@micropython.asm_thumb
26+
def asm_sum_bytes(r0, r1):
27+
28+
# r0 = len
29+
# r1 = ptr
30+
# r2 = sum
31+
# r3 = dummy
32+
mov(r2, 0)
33+
34+
b(loop_entry)
35+
36+
label(loop1)
37+
ldrb(r3, [r1, 0])
38+
add(r2, r2, r3)
39+
40+
add(r1, r1, 1)
41+
sub(r0, r0, 1)
42+
43+
label(loop_entry)
44+
cmp(r0, 0)
45+
bgt(loop1)
46+
47+
mov(r0, r2)
48+
49+
import array
50+
51+
b = array.array('l', (100, 200, 300, 400))
52+
n = asm_sum_words(len(b), b)
53+
print(b, n)
54+
55+
b = array.array('b', (10, 20, 30, 40, 50, 60, 70, 80))
56+
n = asm_sum_bytes(len(b), b)
57+
print(b, n)

tests/inlineasm/asmsum.py.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
array('l', [100, 200, 300, 400]) 1000
2+
array('b', [10, 20, 30, 40, 50, 60, 70, 80]) 360

tests/run-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def main():
115115
test_dirs = ('basics', 'float', 'import', 'io', 'misc')
116116
else:
117117
# run pyboard tests
118-
test_dirs = ('basics', 'float', 'pyb')
118+
test_dirs = ('basics', 'float', 'pyb', 'inlineasm')
119119
tests = sorted(test_file for test_files in (glob('{}/*.py'.format(dir)) for dir in test_dirs) for test_file in test_files)
120120
else:
121121
# tests explicitly given

0 commit comments

Comments
 (0)