1@micropython.asm_thumb
2def 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
26@micropython.asm_thumb
27def asm_sum_bytes(r0, r1):
28
29    # r0 = len
30    # r1 = ptr
31    # r2 = sum
32    # r3 = dummy
33    mov(r2, 0)
34
35    b(loop_entry)
36
37    label(loop1)
38    ldrb(r3, [r1, 0])
39    add(r2, r2, r3)
40
41    add(r1, r1, 1)
42    sub(r0, r0, 1)
43
44    label(loop_entry)
45    cmp(r0, 0)
46    bgt(loop1)
47
48    mov(r0, r2)
49
50
51import uarray as array
52
53b = array.array("l", (100, 200, 300, 400))
54n = asm_sum_words(len(b), b)
55print(b, n)
56
57b = array.array("b", (10, 20, 30, 40, 50, 60, 70, 80))
58n = asm_sum_bytes(len(b), b)
59print(b, n)
60
61b = b"\x01\x02\x03\x04"
62n = asm_sum_bytes(len(b), b)
63print(b, n)
64