Inline assembler data statement: suggested enhancement
The data statement enables data to be included with code. Unfortunately it doesn't seem possible to access it without explicitly manipulating the program counter. Attempts to assign labels to registers produce an error. For example it would be good to be able to write something like this (to access an element from a data array):
d1 = const(12)
d2 = const(13)
@micropython.asm_thumb
def bar(r0):
b(START)
label(MYDATA)
data(4, d1, d2)
label(START)
movwt(r1, MYDATA)
add(r0, r0, r0) # Convert index to byte offset
add(r0, r0, r0)
add(r1, r1, r0) # add offset to data address
ldr(r0, [r1, 0])
But this fails with "unsupported Thumb instruction 'movwt' with 2 arguments". The code can be made to work as follows, but it seems inelegant compared to using a label.
d0 = const(1234567)
d1 = const(987654)
d2 = const(3*d1)
@micropython.asm_thumb
def getdata(r0):
push({pc})
b(START)
data(4, d0, d1, d2)
label(START)
pop({r2})
add(r2, 2) # skip the b() instruction
add(r0, r0, r0)
add(r0, r0, r0) # Convert array offset to bytes
add(r2, r2, r0) # Add to adjusted address
ldr(r0, [r2, 0]) # get the requested data
Enhancement: please add support for the ADR assembler opcode
Please add support for the ADR opcode in micropython for microbit. We need to utilize a temporary data table inside an assembler def.
Using 'adr' gives an error something like: "unsupported Thumb command 'adr' "
Desired usage:
def example():
b(LABEL1)
label(LABEL2)
data(4, 1, 2, 3, 4, 5, 6, 7, 8)
label(LABEL1)
adr(r1, LABEL2) # r1 = address of where data starts
# or, this is how it appears in some ARM/Thumb documentation:
# adr(r0,=LABEL2) # r1 = address of LABEL2
ldr(r0, [r1, 0]) # return value pointed to by LABEL2
If adr opcode cannot be supported, then please suggest a workaround using available opcodes. Thank you!