summaryrefslogtreecommitdiff
path: root/tests/micropython/viper_ptr16_store.py
blob: 5a5f25d170f9969c7037b922514f0640482928ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# test ptr16 type

@micropython.viper
def set(dest:ptr16, val:int):
    dest[0] = val

@micropython.viper
def set1(dest:ptr16, val:int):
    dest[1] = val

@micropython.viper
def memset(dest:ptr16, val:int, n:int):
    for i in range(n):
        dest[i] = val

@micropython.viper
def memset2(dest_in, val:int):
    dest = ptr16(dest_in)
    n = int(len(dest_in)) >> 1
    for i in range(n):
        dest[i] = val

b = bytearray(4)
print(b)

set(b, 0x4242)
print(b)

set1(b, 0x4343)
print(b)

memset(b, 0x4444, len(b) // 2)
print(b)

memset2(b, 0x4545)
print(b)